| 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..1342fbb0dbb4a87bbea8dca23ea7c7349cb9b6b5 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,66 @@ 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");
|
| + }
|
| +
|
| + 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)
|
|
|
| // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not
|
| @@ -58,10 +112,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 +121,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 +130,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 +147,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());
|
| }
|
|
|
|
|