Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| 11 #include "ui/base/test/material_design_controller_test_api.h" | 11 #include "ui/base/test/material_design_controller_test_api.h" |
| 12 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Test fixture for the MaterialDesignController class. | 17 // Test fixture for the MaterialDesignController class. |
| 18 class MaterialDesignControllerTest : public testing::Test { | 18 class MaterialDesignControllerTest : public testing::Test { |
| 19 public: | 19 public: |
| 20 MaterialDesignControllerTest(); | 20 MaterialDesignControllerTest(); |
| 21 ~MaterialDesignControllerTest() override; | 21 ~MaterialDesignControllerTest() override; |
| 22 | 22 |
| 23 protected: | |
| 23 // testing::Test: | 24 // testing::Test: |
| 24 void SetUp() override; | 25 void SetUp() override; |
| 26 void TearDown() override; | |
| 27 void SetCommandLineSwitch(const std::string& value_string); | |
| 25 | 28 |
| 26 private: | 29 private: |
| 27 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); | 30 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); |
| 28 }; | 31 }; |
| 29 | 32 |
| 30 MaterialDesignControllerTest::MaterialDesignControllerTest() { | 33 MaterialDesignControllerTest::MaterialDesignControllerTest() { |
| 31 } | 34 } |
| 32 | 35 |
| 33 MaterialDesignControllerTest::~MaterialDesignControllerTest() { | 36 MaterialDesignControllerTest::~MaterialDesignControllerTest() { |
| 34 } | 37 } |
| 35 | 38 |
| 36 void MaterialDesignControllerTest::SetUp() { | 39 void MaterialDesignControllerTest::SetUp() { |
| 37 testing::Test::SetUp(); | 40 testing::Test::SetUp(); |
| 41 MaterialDesignController::Initialize(); | |
| 42 } | |
| 38 | 43 |
| 39 // Ensure other tests aren't polluted by a Mode set in these tests. The Mode | 44 void MaterialDesignControllerTest::TearDown() { |
| 40 // has to be cleared in SetUp and not in TearDown because when the test suite | |
| 41 // starts up it triggers a call to ResourceBundle::LoadCommonResources() | |
| 42 // which calls MaterialDesignController::IsModeMaterial(), thereby | |
| 43 // initializing the mode and potentially causing the first test to fail. | |
| 44 test::MaterialDesignControllerTestAPI::UninitializeMode(); | 45 test::MaterialDesignControllerTestAPI::UninitializeMode(); |
| 46 testing::Test::TearDown(); | |
| 45 } | 47 } |
| 46 | 48 |
| 49 void MaterialDesignControllerTest::SetCommandLineSwitch( | |
| 50 const std::string& value_string) { | |
| 51 #if defined(ENABLE_TOPCHROME_MD) | |
| 52 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 53 switches::kTopChromeMD, value_string); | |
| 54 #endif // defined(ENABLE_TOPCHROME_MD) | |
| 55 } | |
| 56 | |
| 57 class MaterialDesignControllerTestMaterial : | |
| 58 public MaterialDesignControllerTest { | |
| 59 public: | |
| 60 MaterialDesignControllerTestMaterial() { | |
| 61 SetCommandLineSwitch("material"); | |
| 62 } | |
| 63 }; | |
|
sky
2016/04/11 15:32:41
private: DISALLOW... for these.
varkha
2016/04/11 19:30:58
Done.
| |
| 64 | |
| 65 class MaterialDesignControllerTestHybrid : public MaterialDesignControllerTest { | |
| 66 public: | |
| 67 MaterialDesignControllerTestHybrid() { | |
| 68 SetCommandLineSwitch("material-hybrid"); | |
| 69 } | |
| 70 }; | |
| 71 | |
| 72 class MaterialDesignControllerTestDefault : | |
| 73 public MaterialDesignControllerTest { | |
| 74 public: | |
| 75 MaterialDesignControllerTestDefault() { | |
| 76 SetCommandLineSwitch(""); | |
|
sky
2016/04/11 15:32:41
"" -> std::string()
varkha
2016/04/11 19:30:58
Done.
| |
| 77 } | |
| 78 }; | |
| 79 | |
| 80 class MaterialDesignControllerTestInvalid : | |
| 81 public MaterialDesignControllerTest { | |
| 82 public: | |
| 83 MaterialDesignControllerTestInvalid() { | |
| 84 const std::string kInvalidValue = "1nvalid-valu3"; | |
| 85 SetCommandLineSwitch(kInvalidValue); | |
| 86 } | |
| 87 }; | |
| 88 | |
| 47 #if !defined(ENABLE_TOPCHROME_MD) | 89 #if !defined(ENABLE_TOPCHROME_MD) |
| 48 | 90 |
| 49 // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not | 91 // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not |
| 50 // defined. | 92 // defined. |
| 51 TEST_F(MaterialDesignControllerTest, | 93 TEST_F(MaterialDesignControllerTest, |
| 52 NonMaterialModeWhenCompileTimeFlagDisabled) { | 94 NonMaterialModeWhenCompileTimeFlagDisabled) { |
| 53 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL, | 95 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL, |
| 54 MaterialDesignController::GetMode()); | 96 MaterialDesignController::GetMode()); |
| 55 } | 97 } |
| 56 | 98 |
| 57 #else | 99 #else |
| 58 | 100 |
| 59 // Verify command line value "material" maps to Mode::MATERIAL when the compile | 101 // Verify command line value "material" maps to Mode::MATERIAL when the compile |
| 60 // time flag is defined. | 102 // time flag is defined. |
| 61 TEST_F(MaterialDesignControllerTest, | 103 TEST_F(MaterialDesignControllerTestMaterial, |
| 62 EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) { | 104 EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) { |
| 63 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 64 switches::kTopChromeMD, "material"); | |
| 65 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL, | 105 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL, |
| 66 MaterialDesignController::GetMode()); | 106 MaterialDesignController::GetMode()); |
| 67 } | 107 } |
| 68 | 108 |
| 69 // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID | 109 // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID |
| 70 // when the compile time flag is defined. | 110 // when the compile time flag is defined. |
| 71 TEST_F( | 111 TEST_F( |
| 72 MaterialDesignControllerTest, | 112 MaterialDesignControllerTestHybrid, |
| 73 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab led) { | 113 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab led) { |
| 74 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 75 switches::kTopChromeMD, "material-hybrid"); | |
| 76 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, | 114 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, |
| 77 MaterialDesignController::GetMode()); | 115 MaterialDesignController::GetMode()); |
| 78 } | 116 } |
| 79 | 117 |
| 80 // Verify command line value "" maps to the default mode when the compile time | 118 // Verify command line value "" maps to the default mode when the compile time |
| 81 // flag is defined. | 119 // flag is defined. |
| 82 TEST_F( | 120 TEST_F( |
| 83 MaterialDesignControllerTest, | 121 MaterialDesignControllerTestDefault, |
| 84 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { | 122 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { |
| 85 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 86 switches::kTopChromeMD, ""); | |
| 87 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 123 EXPECT_EQ(MaterialDesignController::DefaultMode(), |
| 88 MaterialDesignController::GetMode()); | 124 MaterialDesignController::GetMode()); |
| 89 } | 125 } |
| 90 | 126 |
| 91 // Verify the current mode is reported as the default mode when no command line | 127 // Verify the current mode is reported as the default mode when no command line |
| 92 // flag is defined. | 128 // flag is defined. |
| 93 TEST_F(MaterialDesignControllerTest, | 129 TEST_F(MaterialDesignControllerTest, |
| 94 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { | 130 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { |
| 95 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 131 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 96 switches::kTopChromeMD)); | 132 switches::kTopChromeMD)); |
| 97 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 133 EXPECT_EQ(MaterialDesignController::DefaultMode(), |
| 98 MaterialDesignController::GetMode()); | 134 MaterialDesignController::GetMode()); |
| 99 } | 135 } |
| 100 | 136 |
| 101 // Verify an invalid command line value uses the default mode. | 137 // Verify an invalid command line value uses the default mode. |
| 102 TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) { | 138 TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) { |
| 103 const std::string kInvalidValue = "1nvalid-valu3"; | |
| 104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 105 switches::kTopChromeMD, kInvalidValue); | |
| 106 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 139 EXPECT_EQ(MaterialDesignController::DefaultMode(), |
| 107 MaterialDesignController::GetMode()); | 140 MaterialDesignController::GetMode()); |
| 108 } | 141 } |
| 109 | 142 |
| 110 // Verify that MaterialDesignController::IsModeMaterial() will initialize the | 143 // Verify that MaterialDesignController::IsModeMaterial() will be true when |
| 111 // mode if it hasn't been initialized yet. | 144 // initialized with command line flag "material". |
| 112 TEST_F(MaterialDesignControllerTest, IsModeMaterialInitializesMode) { | 145 TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) { |
| 113 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 114 switches::kTopChromeMD, "material"); | |
| 115 EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); | 146 EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); |
| 116 } | 147 } |
| 117 | 148 |
| 118 #endif // !defined(ENABLE_TOPCHROME_MD) | 149 #endif // !defined(ENABLE_TOPCHROME_MD) |
| 119 | 150 |
| 120 } // namespace | 151 } // namespace |
| 121 } // namespace ui | 152 } // namespace ui |
| OLD | NEW |