chromium/chrome/browser/focus_ring_browsertest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/file_util.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/test/pixel_comparator.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/base/ui_base_switches.h"

// TODO(crbug.com/40625383): Move the baselines to skia gold for easier
//   rebaselining when all platforms are supported

// To rebaseline this test on all platforms:
// 1. Run a CQ+1 dry run.
// 2. Click the failing bots for android, windows, mac, and linux.
// 3. Find the failing interactive_ui_tests step.
// 4. Click the "Deterministic failure" link for the failing test case.
// 5. Copy the "Actual pixels" data url and paste into browser.
// 6. Save the image into your chromium checkout in
//    chrome/test/data/focus_rings.

#if BUILDFLAG(IS_MAC)
// Mac has subtle rendering differences between different versions of MacOS, so
// we account for them with these fuzzy pixel comparators. These two comparators
// are used in different tests in order to keep the matching somewhat strict.
const auto mac_strict_comparator = cc::FuzzyPixelComparator()
                                       .DiscardAlpha()
                                       .SetErrorPixelsPercentageLimit(3.f)
                                       .SetAvgAbsErrorLimit(20.f)
                                       .SetAbsErrorLimit(49);
const auto mac_loose_comparator = cc::FuzzyPixelComparator()
                                      .DiscardAlpha()
                                      .SetErrorPixelsPercentageLimit(8.7f)
                                      .SetAvgAbsErrorLimit(20.f)
                                      .SetAbsErrorLimit(43);
#endif

// The ChromeRefresh2023 trybot has very slightly different rendering output
// than normal linux bots. It is currently unclear if this is due to the flag or
// some configuration on the bot. In addition, this bot does not get run on CQ+1
// so having a separate golden file to rebaseline is not good enough. This fuzzy
// comparator accounts for this and still make sure that the output is sane.
// TODO(http://crbug.com/1443584): Remove this fuzzy matcher when
// ChromeRefresh2023 is enabled by default, and replace it with a standard
// cc::AlphaDiscardingExactPixelComparator.
const auto fuzzy_comparator =;

class FocusRingBrowserTest : public InProcessBrowserTest {};

// TODO(crbug.com/40774264): Flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Checkbox
#else
#define MAYBE_Checkbox
#endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Checkbox) {}

// TODO(crbug.com/40774264): Flaky on Mac.
// TODO(b/334008286): Failing on Windows.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_Radio
#else
#define MAYBE_Radio
#endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Radio) {}

// TODO(crbug.com/40774264): Flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Button
#else
#define MAYBE_Button
#endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Button) {}

// TODO(crbug.com/40774264): Flaky on Mac.
// TODO(b/334008286): Failing on Windows.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_Anchor
#else
#define MAYBE_Anchor
#endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Anchor) {}

// TODO(crbug.com/40774264): Flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_DarkModeButton
#else
#define MAYBE_DarkModeButton
#endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_DarkModeButton) {}