-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
chrome/browser/ui/webui/search_engine_choice/search_engine_choice_ui_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters