Commit 78eb032e authored by Joey Arhar's avatar Joey Arhar Committed by Chromium LUCI CQ

Add dark mode focus ring browsertests

Focus rings are rendered differently in dark mode, so we need additional
pixel tests for dark mode.

Fixed: 1067517
Change-Id: I94ba8b86a03943b7d30cddd44a30ac2cc380e0ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596019Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarYu Han <yuzhehan@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839189}
parent cfbec794
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "cc/test/pixel_comparator.h" #include "cc/test/pixel_comparator.h"
#include "chrome/browser/focus_ring_browsertest_mac.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
// TODO(crbug.com/958242): Move the baselines to skia gold for easier // TODO(crbug.com/958242): Move the baselines to skia gold for easier
// rebaselining when all platforms are supported // rebaselining when all platforms are supported
...@@ -53,7 +55,9 @@ const cc::FuzzyPixelComparator mac_loose_comparator( ...@@ -53,7 +55,9 @@ const cc::FuzzyPixelComparator mac_loose_comparator(
class FocusRingBrowserTest : public InProcessBrowserTest { class FocusRingBrowserTest : public InProcessBrowserTest {
public: public:
FocusRingBrowserTest() { FocusRingBrowserTest() {
feature_list_.InitWithFeatures({features::kFormControlsRefresh}, {}); feature_list_.InitWithFeatures(
{features::kFormControlsRefresh, features::kCSSColorSchemeUARendering},
{});
} }
void SetUp() override { void SetUp() override {
...@@ -67,6 +71,9 @@ class FocusRingBrowserTest : public InProcessBrowserTest { ...@@ -67,6 +71,9 @@ class FocusRingBrowserTest : public InProcessBrowserTest {
// The --disable-lcd-text flag helps text render more similarly on // The --disable-lcd-text flag helps text render more similarly on
// different bots and platform. // different bots and platform.
command_line->AppendSwitch(switches::kDisableLCDText); command_line->AppendSwitch(switches::kDisableLCDText);
// This is required to allow dark mode to be used on some platforms.
command_line->AppendSwitch(switches::kForceDarkMode);
} }
void RunTest(const std::string& screenshot_filename, void RunTest(const std::string& screenshot_filename,
...@@ -77,6 +84,7 @@ class FocusRingBrowserTest : public InProcessBrowserTest { ...@@ -77,6 +84,7 @@ class FocusRingBrowserTest : public InProcessBrowserTest {
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(features::IsFormControlsRefreshEnabled()); ASSERT_TRUE(features::IsFormControlsRefreshEnabled());
ASSERT_TRUE(features::IsCSSColorSchemeUARenderingEnabled());
base::FilePath dir_test_data; base::FilePath dir_test_data;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data));
...@@ -103,8 +111,7 @@ class FocusRingBrowserTest : public InProcessBrowserTest { ...@@ -103,8 +111,7 @@ class FocusRingBrowserTest : public InProcessBrowserTest {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::NavigateToURL( ASSERT_TRUE(content::NavigateToURL(
web_contents, web_contents, GURL("data:text/html,<!DOCTYPE html>" + body_html)));
GURL("data:text/html,<!DOCTYPE html><body>" + body_html + "</body>")));
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
EXPECT_TRUE(CompareWebContentsOutputToReference( EXPECT_TRUE(CompareWebContentsOutputToReference(
...@@ -174,3 +181,21 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, Anchor) { ...@@ -174,3 +181,21 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, Anchor) {
/* screenshot_width */ 90, /* screenshot_width */ 90,
/* screenshot_height */ 130, comparator); /* screenshot_height */ 130, comparator);
} }
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, DarkModeButton) {
#if defined(OS_MAC)
if (!MacOSVersionSupportsDarkMode())
return;
cc::FuzzyPixelComparator comparator = mac_strict_comparator;
#else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true);
#endif
RunTest("focus_ring_browsertest_dark_mode_button",
"<meta name=\"color-scheme\" content=\"light dark\">"
"<button autofocus style=\"width:40px;height:20px;\"></button>"
"<br>"
"<br>"
"<button style=\"width:40px;height:20px;\"></button>",
/* screenshot_width */ 80,
/* screenshot_height */ 80, comparator);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_FOCUS_RING_BROWSERTEST_MAC_H_
#define CHROME_BROWSER_FOCUS_RING_BROWSERTEST_MAC_H_
bool MacOSVersionSupportsDarkMode();
#endif // CHROME_BROWSER_FOCUS_RING_BROWSERTEST_MAC_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/focus_ring_browsertest_mac.h"
bool MacOSVersionSupportsDarkMode() {
if (@available(macOS 10.14, *))
return true;
return false;
}
...@@ -6793,6 +6793,8 @@ if (!is_android) { ...@@ -6793,6 +6793,8 @@ if (!is_android) {
sources += [ sources += [
"../browser/apps/platform_apps/app_shim_interactive_uitest_mac.mm", "../browser/apps/platform_apps/app_shim_interactive_uitest_mac.mm",
"../browser/apps/platform_apps/app_shim_quit_interactive_uitest_mac.mm", "../browser/apps/platform_apps/app_shim_quit_interactive_uitest_mac.mm",
"../browser/focus_ring_browsertest_mac.h",
"../browser/focus_ring_browsertest_mac.mm",
"../browser/global_keyboard_shortcuts_mac_browsertest.mm", "../browser/global_keyboard_shortcuts_mac_browsertest.mm",
"../browser/notifications/notification_interactive_uitest_mac.mm", "../browser/notifications/notification_interactive_uitest_mac.mm",
"../browser/spellchecker/spellcheck_mac_view_interactive_uitest.mm", "../browser/spellchecker/spellcheck_mac_view_interactive_uitest.mm",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment