Skip to content

Commit

Permalink
[waffle]Add screenshot tests
Browse files Browse the repository at this point in the history
Bug: b/280753754
Change-Id: I64dcd5b7269f7c1540e6204004df1610c9fc98bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4759006
Commit-Queue: Jack Yammine <jyammine@google.com>
Reviewed-by: Jens Mueller <muellerj@google.com>
Reviewed-by: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1185075}
  • Loading branch information
Jack Yammine authored and Chromium LUCI CQ committed Aug 18, 2023
1 parent 35ccfc9 commit b42b780
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
35 changes: 35 additions & 0 deletions chrome/browser/ui/test/pixel_test_configuration_mixin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>

#include "chrome/browser/ui/test/pixel_test_configuration_mixin.h"
#include "ui/base/ui_base_switches.h"

PixelTestConfigurationMixin::PixelTestConfigurationMixin(
InProcessBrowserTestMixinHost* host,
bool use_dark_theme,
bool use_right_to_left_language)
: InProcessBrowserTestMixin(host),
use_dark_theme_(use_dark_theme),
use_right_to_left_language_(use_right_to_left_language) {}

PixelTestConfigurationMixin::~PixelTestConfigurationMixin() = default;

void PixelTestConfigurationMixin::SetUpCommandLine(
base::CommandLine* command_line) {
if (use_dark_theme_) {
command_line->AppendSwitch(switches::kForceDarkMode);
}
if (use_right_to_left_language_) {
const std::string language = "ar-XB";
command_line->AppendSwitchASCII(switches::kLang, language);

// On Linux & Lacros the command line switch has no effect, we need to use
// environment variables to change the language.
scoped_env_override_ =
std::make_unique<base::ScopedEnvironmentVariableOverride>("LANGUAGE",
language);
}
}
33 changes: 33 additions & 0 deletions chrome/browser/ui/test/pixel_test_configuration_mixin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TEST_PIXEL_TEST_CONFIGURATION_MIXIN_H_
#define CHROME_BROWSER_UI_TEST_PIXEL_TEST_CONFIGURATION_MIXIN_H_

#include <memory>

#include "base/scoped_environment_variable_override.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"

// Mixin to automatically set up generic pixel test configurations.
class PixelTestConfigurationMixin : public InProcessBrowserTestMixin {
public:
explicit PixelTestConfigurationMixin(InProcessBrowserTestMixinHost* host,
bool use_dark_theme,
bool use_right_to_left_language);
PixelTestConfigurationMixin(const PixelTestConfigurationMixin&) = delete;
PixelTestConfigurationMixin& operator=(const PixelTestConfigurationMixin&) =
delete;

// InProcessBrowserTestMixin
~PixelTestConfigurationMixin() override;
void SetUpCommandLine(base::CommandLine* command_line) override;

private:
const bool use_dark_theme_;
const bool use_right_to_left_language_;
std::unique_ptr<base::ScopedEnvironmentVariableOverride> scoped_env_override_;
};

#endif // CHROME_BROWSER_UI_TEST_PIXEL_TEST_CONFIGURATION_MIXIN_H_
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void ShowSearchEngineChoiceDialog(Browser& browser) {

SearchEngineChoiceDialogView::SearchEngineChoiceDialogView(Browser* browser)
: browser_(browser) {
CHECK(browser_);
CHECK(base::FeatureList::IsEnabled(switches::kSearchEngineChoice));
// Create the web view in the native dialog.
web_view_ =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include <string>
#include <vector>

#include "base/test/scoped_feature_list.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_service.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/search_engine_choice/search_engine_choice_tab_helper.h"
#include "chrome/browser/ui/test/pixel_test_configuration_mixin.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/signin/public/base/signin_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h"

#if !BUILDFLAG(ENABLE_SEARCH_ENGINE_CHOICE)
#error Platform not supported
#endif

// Tests for the chrome://search-engine-choice WebUI page.
namespace {
struct TestParam {
std::string test_suffix;
bool use_dark_theme = false;
bool use_right_to_left_language = false;
};

// To be passed as 4th argument to `INSTANTIATE_TEST_SUITE_P()`, allows the test
// to be named like `<TestClassName>.InvokeUi_default/<TestSuffix>` instead
// of using the index of the param in `TestParam` as suffix.
std::string ParamToTestSuffix(const ::testing::TestParamInfo<TestParam>& info) {
return info.param.test_suffix;
}

// Permutations of supported parameters.
const TestParam kTestParams[] = {
{.test_suffix = "Default"},
{.test_suffix = "DarkTheme", .use_dark_theme = true},
{.test_suffix = "RightToLeft", .use_right_to_left_language = true},
};
} // namespace

class SearchEngineChoiceUIPixelTest
: public TestBrowserDialog,
public MixinBasedInProcessBrowserTest,
public testing::WithParamInterface<TestParam> {
public:
SearchEngineChoiceUIPixelTest()
: scoped_chrome_build_override_(SearchEngineChoiceServiceFactory::
ScopedChromeBuildOverrideForTesting(
/*force_chrome_build=*/true)),
pixel_test_mixin_(&mixin_host_,
GetParam().use_dark_theme,
GetParam().use_right_to_left_language) {}

~SearchEngineChoiceUIPixelTest() override = default;

// TestBrowserDialog
void ShowUi(const std::string& name) override {
SearchEngineChoiceService::SetDialogDisabledForTests(
/*dialog_disabled=*/false);

GURL url = GURL(chrome::kChromeUISearchEngineChoiceURL);
content::TestNavigationObserver observer(url);
observer.StartWatchingNewWebContents();

ShowSearchEngineChoiceDialog(*browser());
observer.Wait();
}

private:
base::AutoReset<bool> scoped_chrome_build_override_;
base::test::ScopedFeatureList feature_list_{switches::kSearchEngineChoice};
PixelTestConfigurationMixin pixel_test_mixin_;
};

IN_PROC_BROWSER_TEST_P(SearchEngineChoiceUIPixelTest, InvokeUi_default) {
ShowAndVerifyUi();
}

INSTANTIATE_TEST_SUITE_P(,
SearchEngineChoiceUIPixelTest,
testing::ValuesIn(kTestParams),
&ParamToTestSuffix);
3 changes: 3 additions & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ static_library("test_support") {
"../browser/ui/profile_ui_test_utils.h",
"../browser/ui/tabs/pinned_tab_test_utils.cc",
"../browser/ui/tabs/pinned_tab_test_utils.h",
"../browser/ui/test/pixel_test_configuration_mixin.cc",
"../browser/ui/test/pixel_test_configuration_mixin.h",
"../browser/ui/test/test_browser_dialog.cc",
"../browser/ui/test/test_browser_dialog.h",
"../browser/ui/test/test_browser_ui.cc",
Expand Down Expand Up @@ -3162,6 +3164,7 @@ if (!is_android) {
"../browser/ui/views/profiles/profile_picker_ui_browsertest.cc",
"../browser/ui/views/profiles/profile_type_choice_ui_browsertest.cc",
"../browser/ui/views/profiles/sync_confirmation_ui_browsertest.cc",
"../browser/ui/webui/search_engine_choice/search_engine_choice_ui_browsertest.cc",
]
}

Expand Down
1 change: 1 addition & 0 deletions testing/buildbot/filters/pixel_tests.filter
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ReopenTabPromoControllerDialogBrowserTest.*
SAAEnabledPermissionPromptBubbleViewBrowserTest.*
SafetyTipPageInfoBubbleViewDialogTest.*
ScreenCaptureNotificationUiBrowserTest.*
SearchEngineChoiceUIPixelTest.*
SecurePaymentConfirmationDialogViewTest.InvokeUi_*
*SendTabToSelfBubbleTest.*
SessionCrashedBubbleViewTest.*
Expand Down

0 comments on commit b42b780

Please sign in to comment.