0

[headless] Move screen info implementation to //components

This is in anticipation of --screen-info support by Chrome Headless
mode (aka new Headless).

Bug: 396072563
Change-Id: I2f69d9bd008e46ee6c5d987611092be300aef4ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6265844
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1420474}
This commit is contained in:
Peter Kvitek
2025-02-14 06:52:00 -08:00
committed by Chromium LUCI CQ
parent ed3e27e52e
commit 472ce1bc48
10 changed files with 56 additions and 26 deletions

@ -708,6 +708,7 @@ test("components_unittests") {
if (!is_android && !is_ios) {
deps += [
"//components/access_code_cast/common:unit_tests",
"//components/headless/screen_info:unit_tests",
"//components/live_caption:unit_tests",
"//components/soda:unit_tests",
"//components/storage_monitor:unit_tests",

@ -0,0 +1,29 @@
# Copyright 2025 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("screen_info") {
sources = [
"headless_screen_info.cc",
"headless_screen_info.h",
]
deps = [
"//base",
"//third_party/re2",
"//ui/display",
"//ui/gfx/geometry/",
]
}
source_set("unit_tests") {
testonly = true
sources = [ "headless_screen_info_unittest.cc" ]
deps = [
":screen_info",
"//base/test:test_support",
"//testing/gmock",
"//testing/gtest",
]
}

@ -0,0 +1,6 @@
include_rules = [
"+base",
"+third_party/re2/src/re2/re2.h",
"+ui/display",
"+ui/gfx/geometry",
]

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "headless/lib/browser/headless_screen_info.h"
#include "components/headless/screen_info/headless_screen_info.h"
#include <optional>

@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef HEADLESS_LIB_BROWSER_HEADLESS_SCREEN_INFO_H_
#define HEADLESS_LIB_BROWSER_HEADLESS_SCREEN_INFO_H_
#ifndef COMPONENTS_HEADLESS_SCREEN_INFO_HEADLESS_SCREEN_INFO_H_
#define COMPONENTS_HEADLESS_SCREEN_INFO_HEADLESS_SCREEN_INFO_H_
#include <string>
#include <string_view>
#include <vector>
#include "base/types/expected.h"
#include "headless/public/headless_export.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
namespace headless {
struct HEADLESS_EXPORT HeadlessScreenInfo {
struct HeadlessScreenInfo {
gfx::Rect bounds = gfx::Rect(800, 600);
gfx::Insets work_area_insets;
int color_depth = 24;
@ -62,4 +61,4 @@ struct HEADLESS_EXPORT HeadlessScreenInfo {
} // namespace headless
#endif // HEADLESS_LIB_BROWSER_HEADLESS_SCREEN_INFO_H_
#endif // COMPONENTS_HEADLESS_SCREEN_INFO_HEADLESS_SCREEN_INFO_H_

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "headless/lib/browser/headless_screen_info.h"
#include "components/headless/screen_info/headless_screen_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -10,7 +10,7 @@
namespace headless {
namespace {
TEST(ScreenInfoTest, Basic) {
TEST(HeadlessScreenInfoTest, Basic) {
EXPECT_EQ(HeadlessScreenInfo::FromString(" \t ").error(),
"Invalid screen info: \t ");
@ -30,7 +30,7 @@ TEST(ScreenInfoTest, Basic) {
HeadlessScreenInfo({.bounds = gfx::Rect(0, 0, 800, 600)}));
}
TEST(ScreenInfoTest, ScreenOrigin) {
TEST(HeadlessScreenInfoTest, ScreenOrigin) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{100,200}").value()[0],
HeadlessScreenInfo({.bounds = gfx::Rect(100, 200, 800, 600)}));
@ -65,7 +65,7 @@ TEST(ScreenInfoTest, ScreenOrigin) {
"Invalid screen info: 100+200");
}
TEST(ScreenInfoTest, ScreenSize) {
TEST(HeadlessScreenInfoTest, ScreenSize) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{100x200}").value()[0],
HeadlessScreenInfo({.bounds = gfx::Rect(100, 200)}));
@ -91,7 +91,7 @@ TEST(ScreenInfoTest, ScreenSize) {
"Invalid screen info: 100 200");
}
TEST(ScreenInfoTest, ScreenParameters) {
TEST(HeadlessScreenInfoTest, ScreenParameters) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{xyz =}").error(),
"Invalid screen info: xyz =");
@ -123,7 +123,7 @@ TEST(ScreenInfoTest, ScreenParameters) {
"Unknown screen info parameter: xyz");
}
TEST(ScreenInfoTest, ScreenColorDepth) {
TEST(HeadlessScreenInfoTest, ScreenColorDepth) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{ colorDepth=16 }").value()[0],
HeadlessScreenInfo({.color_depth = 16}));
@ -140,7 +140,7 @@ TEST(ScreenInfoTest, ScreenColorDepth) {
"Invalid screen color depth: 24x");
}
TEST(ScreenInfoTest, ScreenDevicePixelRatio) {
TEST(HeadlessScreenInfoTest, ScreenDevicePixelRatio) {
EXPECT_EQ(
HeadlessScreenInfo::FromString("{ devicePixelRatio=0.5}").value()[0],
HeadlessScreenInfo({.device_pixel_ratio = 0.5f}));
@ -161,7 +161,7 @@ TEST(ScreenInfoTest, ScreenDevicePixelRatio) {
"Invalid screen device pixel ratio: 1.0x");
}
TEST(ScreenInfoTest, ScreenIsInternal) {
TEST(HeadlessScreenInfoTest, ScreenIsInternal) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{ isInternal=1 }").value()[0],
HeadlessScreenInfo({.is_internal = true}));
@ -181,7 +181,7 @@ TEST(ScreenInfoTest, ScreenIsInternal) {
"Invalid screen is internal: xyz");
}
TEST(ScreenInfoTest, ScreenLabel) {
TEST(HeadlessScreenInfoTest, ScreenLabel) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{ label=xyz}").value()[0],
HeadlessScreenInfo({.label = "xyz"}));
@ -211,7 +211,7 @@ TEST(ScreenInfoTest, ScreenLabel) {
"Invalid screen info: '\\'quoted\\'");
}
TEST(ScreenInfoTest, MultipleScreens) {
TEST(HeadlessScreenInfoTest, MultipleScreens) {
// Explicit screen origin results in overlapped screens.
EXPECT_THAT(HeadlessScreenInfo::FromString("{}{0,0 600x800}").value(),
testing::ElementsAre(
@ -263,7 +263,7 @@ TEST(ScreenInfoTest, MultipleScreens) {
"Invalid screen info: }");
}
TEST(ScreenInfoTest, WorkArea) {
TEST(HeadlessScreenInfoTest, WorkArea) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{ workAreaLeft=100 }").value()[0],
HeadlessScreenInfo(
{.work_area_insets = gfx::Insets::TLBR(0, 100, 0, 0)}));
@ -314,7 +314,7 @@ TEST(ScreenInfoTest, WorkArea) {
"Invalid work area inset: -42");
}
TEST(ScreenInfoTest, Rotation) {
TEST(HeadlessScreenInfoTest, Rotation) {
EXPECT_EQ(HeadlessScreenInfo::FromString("{ rotation=0 }").value()[0],
HeadlessScreenInfo({.rotation = 0}));

@ -265,8 +265,6 @@ component("headless_non_renderer") {
"lib/browser/headless_request_context_manager.h",
"lib/browser/headless_screen.cc",
"lib/browser/headless_screen.h",
"lib/browser/headless_screen_info.cc",
"lib/browser/headless_screen_info.h",
"lib/browser/headless_screen_orientation_delegate.cc",
"lib/browser/headless_screen_orientation_delegate.h",
"lib/browser/headless_web_contents_impl.cc",
@ -365,6 +363,7 @@ component("headless_non_renderer") {
"//components/embedder_support/origin_trials",
"//components/headless/clipboard",
"//components/headless/command_handler:switches",
"//components/headless/screen_info",
"//components/headless/select_file_dialog",
"//components/keyed_service/content",
"//components/origin_trials:browser",
@ -560,7 +559,6 @@ test("headless_unittests") {
sources = [
"lib/browser/headless_browser_impl_unittest.cc",
"lib/browser/headless_client_hints_controller_delegate_unittest.cc",
"lib/browser/headless_screen_info_unittest.cc",
"lib/renderer/allowlist_unittest.cc",
]

@ -71,8 +71,5 @@ specific_include_rules = {
"+components/prefs",
"+components/metrics",
"+components/variations",
],
"headless_screen_info.cc": [
"+third_party/re2/src/re2/re2.h",
]
}

@ -17,9 +17,9 @@
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "components/headless/screen_info/headless_screen_info.h"
#include "components/viz/common/switches.h"
#include "content/public/common/content_switches.h"
#include "headless/lib/browser/headless_screen_info.h"
#include "headless/public/switches.h"
#include "net/http/http_util.h"
#include "net/proxy_resolution/proxy_config.h"

@ -6,7 +6,7 @@
#include "base/check_deref.h"
#include "base/containers/flat_set.h"
#include "headless/lib/browser/headless_screen_info.h"
#include "components/headless/screen_info/headless_screen_info.h"
#include "ui/display/display_finder.h"
#include "ui/display/display_list.h"
#include "ui/display/util/display_util.h"