Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Unified Diff: ui/base/material_design/material_design_controller_unittest.cc

Issue 1878943002: Revert of Makes MaterialDesignController initialization explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/material_design/material_design_controller_unittest.cc
diff --git a/ui/base/material_design/material_design_controller_unittest.cc b/ui/base/material_design/material_design_controller_unittest.cc
index 1342fbb0dbb4a87bbea8dca23ea7c7349cb9b6b5..543cf3d2c8f7a9756a0274cb25182f960d2a0336 100644
--- a/ui/base/material_design/material_design_controller_unittest.cc
+++ b/ui/base/material_design/material_design_controller_unittest.cc
@@ -20,11 +20,8 @@
MaterialDesignControllerTest();
~MaterialDesignControllerTest() override;
- protected:
// testing::Test:
void SetUp() override;
- void TearDown() override;
- void SetCommandLineSwitch(const std::string& value_string);
private:
DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
@@ -38,65 +35,14 @@
void MaterialDesignControllerTest::SetUp() {
testing::Test::SetUp();
- MaterialDesignController::Initialize();
+
+ // Ensure other tests aren't polluted by a Mode set in these tests. The Mode
+ // has to be cleared in SetUp and not in TearDown because when the test suite
+ // starts up it triggers a call to ResourceBundle::LoadCommonResources()
+ // which calls MaterialDesignController::IsModeMaterial(), thereby
+ // initializing the mode and potentially causing the first test to fail.
+ test::MaterialDesignControllerTestAPI::UninitializeMode();
}
-
-void MaterialDesignControllerTest::TearDown() {
- test::MaterialDesignControllerTestAPI::UninitializeMode();
- testing::Test::TearDown();
-}
-
-void MaterialDesignControllerTest::SetCommandLineSwitch(
- const std::string& value_string) {
-#if defined(ENABLE_TOPCHROME_MD)
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, value_string);
-#endif // defined(ENABLE_TOPCHROME_MD)
-}
-
-class MaterialDesignControllerTestMaterial :
- public MaterialDesignControllerTest {
- public:
- MaterialDesignControllerTestMaterial() {
- SetCommandLineSwitch("material");
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial);
-};
-
-class MaterialDesignControllerTestHybrid : public MaterialDesignControllerTest {
- public:
- MaterialDesignControllerTestHybrid() {
- SetCommandLineSwitch("material-hybrid");
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestHybrid);
-};
-
-class MaterialDesignControllerTestDefault :
- public MaterialDesignControllerTest {
- public:
- MaterialDesignControllerTestDefault() {
- SetCommandLineSwitch(std::string());
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestDefault);
-};
-
-class MaterialDesignControllerTestInvalid :
- public MaterialDesignControllerTest {
- public:
- MaterialDesignControllerTestInvalid() {
- const std::string kInvalidValue = "1nvalid-valu3";
- SetCommandLineSwitch(kInvalidValue);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestInvalid);
-};
#if !defined(ENABLE_TOPCHROME_MD)
@@ -112,8 +58,10 @@
// Verify command line value "material" maps to Mode::MATERIAL when the compile
// time flag is defined.
-TEST_F(MaterialDesignControllerTestMaterial,
+TEST_F(MaterialDesignControllerTest,
EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTopChromeMD, "material");
EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL,
MaterialDesignController::GetMode());
}
@@ -121,8 +69,10 @@
// Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID
// when the compile time flag is defined.
TEST_F(
- MaterialDesignControllerTestHybrid,
+ MaterialDesignControllerTest,
EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnabled) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTopChromeMD, "material-hybrid");
EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID,
MaterialDesignController::GetMode());
}
@@ -130,8 +80,10 @@
// Verify command line value "" maps to the default mode when the compile time
// flag is defined.
TEST_F(
- MaterialDesignControllerTestDefault,
+ MaterialDesignControllerTest,
DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTopChromeMD, "");
EXPECT_EQ(MaterialDesignController::DefaultMode(),
MaterialDesignController::GetMode());
}
@@ -147,14 +99,19 @@
}
// Verify an invalid command line value uses the default mode.
-TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) {
+TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) {
+ const std::string kInvalidValue = "1nvalid-valu3";
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTopChromeMD, kInvalidValue);
EXPECT_EQ(MaterialDesignController::DefaultMode(),
MaterialDesignController::GetMode());
}
-// Verify that MaterialDesignController::IsModeMaterial() will be true when
-// initialized with command line flag "material".
-TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) {
+// Verify that MaterialDesignController::IsModeMaterial() will initialize the
+// mode if it hasn't been initialized yet.
+TEST_F(MaterialDesignControllerTest, IsModeMaterialInitializesMode) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTopChromeMD, "material");
EXPECT_TRUE(MaterialDesignController::IsModeMaterial());
}
« no previous file with comments | « ui/base/material_design/material_design_controller.cc ('k') | ui/message_center/views/bounded_label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698