Chromium Code Reviews| 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 543cf3d2c8f7a9756a0274cb25182f960d2a0336..6bc8d08fa77f846f8255875db60c051e9c6ade20 100644 |
| --- a/ui/base/material_design/material_design_controller_unittest.cc |
| +++ b/ui/base/material_design/material_design_controller_unittest.cc |
| @@ -20,8 +20,11 @@ class MaterialDesignControllerTest : public testing::Test { |
| 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); |
| @@ -35,15 +38,54 @@ MaterialDesignControllerTest::~MaterialDesignControllerTest() { |
| 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. |
| +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"); |
| + } |
| +}; |
|
sky
2016/04/11 15:32:41
private: DISALLOW... for these.
varkha
2016/04/11 19:30:58
Done.
|
| + |
| +class MaterialDesignControllerTestHybrid : public MaterialDesignControllerTest { |
| + public: |
| + MaterialDesignControllerTestHybrid() { |
| + SetCommandLineSwitch("material-hybrid"); |
| + } |
| +}; |
| + |
| +class MaterialDesignControllerTestDefault : |
| + public MaterialDesignControllerTest { |
| + public: |
| + MaterialDesignControllerTestDefault() { |
| + SetCommandLineSwitch(""); |
|
sky
2016/04/11 15:32:41
"" -> std::string()
varkha
2016/04/11 19:30:58
Done.
|
| + } |
| +}; |
| + |
| +class MaterialDesignControllerTestInvalid : |
| + public MaterialDesignControllerTest { |
| + public: |
| + MaterialDesignControllerTestInvalid() { |
| + const std::string kInvalidValue = "1nvalid-valu3"; |
| + SetCommandLineSwitch(kInvalidValue); |
| + } |
| +}; |
| + |
| #if !defined(ENABLE_TOPCHROME_MD) |
| // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not |
| @@ -58,10 +100,8 @@ TEST_F(MaterialDesignControllerTest, |
| // Verify command line value "material" maps to Mode::MATERIAL when the compile |
| // time flag is defined. |
| -TEST_F(MaterialDesignControllerTest, |
| +TEST_F(MaterialDesignControllerTestMaterial, |
| EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) { |
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| - switches::kTopChromeMD, "material"); |
| EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL, |
| MaterialDesignController::GetMode()); |
| } |
| @@ -69,10 +109,8 @@ TEST_F(MaterialDesignControllerTest, |
| // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID |
| // when the compile time flag is defined. |
| TEST_F( |
| - MaterialDesignControllerTest, |
| + MaterialDesignControllerTestHybrid, |
| EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnabled) { |
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| - switches::kTopChromeMD, "material-hybrid"); |
| EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, |
| MaterialDesignController::GetMode()); |
| } |
| @@ -80,10 +118,8 @@ TEST_F( |
| // Verify command line value "" maps to the default mode when the compile time |
| // flag is defined. |
| TEST_F( |
| - MaterialDesignControllerTest, |
| + MaterialDesignControllerTestDefault, |
| DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { |
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| - switches::kTopChromeMD, ""); |
| EXPECT_EQ(MaterialDesignController::DefaultMode(), |
| MaterialDesignController::GetMode()); |
| } |
| @@ -99,19 +135,14 @@ TEST_F(MaterialDesignControllerTest, |
| } |
| // Verify an invalid command line value uses the default mode. |
| -TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) { |
| - const std::string kInvalidValue = "1nvalid-valu3"; |
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| - switches::kTopChromeMD, kInvalidValue); |
| +TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) { |
| EXPECT_EQ(MaterialDesignController::DefaultMode(), |
| MaterialDesignController::GetMode()); |
| } |
| -// 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"); |
| +// Verify that MaterialDesignController::IsModeMaterial() will be true when |
| +// initialized with command line flag "material". |
| +TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) { |
| EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); |
| } |