| 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 protected: |
| 24 // testing::Test: | 24 // testing::Test: |
| 25 void SetUp() override; | 25 void SetUp() override; |
| 26 void TearDown() override; | 26 void TearDown() override; |
| 27 |
| 27 void SetCommandLineSwitch(const std::string& value_string); | 28 void SetCommandLineSwitch(const std::string& value_string); |
| 29 bool CurrentModeIsDefaultMode(); |
| 28 | 30 |
| 29 private: | 31 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); | 32 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 MaterialDesignControllerTest::MaterialDesignControllerTest() { | 35 MaterialDesignControllerTest::MaterialDesignControllerTest() { |
| 34 } | 36 } |
| 35 | 37 |
| 36 MaterialDesignControllerTest::~MaterialDesignControllerTest() { | 38 MaterialDesignControllerTest::~MaterialDesignControllerTest() { |
| 37 } | 39 } |
| 38 | 40 |
| 39 void MaterialDesignControllerTest::SetUp() { | 41 void MaterialDesignControllerTest::SetUp() { |
| 40 testing::Test::SetUp(); | 42 testing::Test::SetUp(); |
| 41 MaterialDesignController::Initialize(); | 43 MaterialDesignController::Initialize(); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void MaterialDesignControllerTest::TearDown() { | 46 void MaterialDesignControllerTest::TearDown() { |
| 45 test::MaterialDesignControllerTestAPI::Uninitialize(); | 47 test::MaterialDesignControllerTestAPI::Uninitialize(); |
| 46 testing::Test::TearDown(); | 48 testing::Test::TearDown(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void MaterialDesignControllerTest::SetCommandLineSwitch( | 51 void MaterialDesignControllerTest::SetCommandLineSwitch( |
| 50 const std::string& value_string) { | 52 const std::string& value_string) { |
| 51 #if defined(ENABLE_TOPCHROME_MD) | 53 #if defined(ENABLE_TOPCHROME_MD) |
| 52 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 54 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 53 switches::kTopChromeMD, value_string); | 55 switches::kTopChromeMD, value_string); |
| 54 #endif // defined(ENABLE_TOPCHROME_MD) | 56 #endif // defined(ENABLE_TOPCHROME_MD) |
| 55 } | 57 } |
| 56 | 58 |
| 59 bool MaterialDesignControllerTest::CurrentModeIsDefaultMode() { |
| 60 return MaterialDesignController::GetMode() == |
| 61 test::MaterialDesignControllerTestAPI::DefaultMode(); |
| 62 } |
| 63 |
| 57 class MaterialDesignControllerTestMaterial : | 64 class MaterialDesignControllerTestMaterial : |
| 58 public MaterialDesignControllerTest { | 65 public MaterialDesignControllerTest { |
| 59 public: | 66 public: |
| 60 MaterialDesignControllerTestMaterial() { | 67 MaterialDesignControllerTestMaterial() { |
| 61 SetCommandLineSwitch("material"); | 68 SetCommandLineSwitch("material"); |
| 62 } | 69 } |
| 63 | 70 |
| 64 private: | 71 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial); | 72 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial); |
| 66 }; | 73 }; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab
led) { | 132 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab
led) { |
| 126 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, | 133 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, |
| 127 MaterialDesignController::GetMode()); | 134 MaterialDesignController::GetMode()); |
| 128 } | 135 } |
| 129 | 136 |
| 130 // Verify command line value "" maps to the default mode when the compile time | 137 // Verify command line value "" maps to the default mode when the compile time |
| 131 // flag is defined. | 138 // flag is defined. |
| 132 TEST_F( | 139 TEST_F( |
| 133 MaterialDesignControllerTestDefault, | 140 MaterialDesignControllerTestDefault, |
| 134 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { | 141 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { |
| 135 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 142 EXPECT_TRUE(CurrentModeIsDefaultMode()); |
| 136 MaterialDesignController::GetMode()); | |
| 137 } | 143 } |
| 138 | 144 |
| 139 // Verify the current mode is reported as the default mode when no command line | 145 // Verify the current mode is reported as the default mode when no command line |
| 140 // flag is defined. | 146 // flag is defined. |
| 141 TEST_F(MaterialDesignControllerTest, | 147 TEST_F(MaterialDesignControllerTest, |
| 142 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { | 148 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { |
| 143 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 149 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 144 switches::kTopChromeMD)); | 150 switches::kTopChromeMD)); |
| 145 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 151 EXPECT_TRUE(CurrentModeIsDefaultMode()); |
| 146 MaterialDesignController::GetMode()); | |
| 147 } | 152 } |
| 148 | 153 |
| 149 // Verify an invalid command line value uses the default mode. | 154 // Verify an invalid command line value uses the default mode. |
| 150 TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) { | 155 TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) { |
| 151 EXPECT_EQ(MaterialDesignController::DefaultMode(), | 156 EXPECT_TRUE(CurrentModeIsDefaultMode()); |
| 152 MaterialDesignController::GetMode()); | |
| 153 } | 157 } |
| 154 | 158 |
| 155 // Verify that MaterialDesignController::IsModeMaterial() will be true when | 159 // Verify that MaterialDesignController::IsModeMaterial() will be true when |
| 156 // initialized with command line flag "material". | 160 // initialized with command line flag "material". |
| 157 TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) { | 161 TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) { |
| 158 EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); | 162 EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); |
| 159 } | 163 } |
| 160 | 164 |
| 161 #endif // !defined(ENABLE_TOPCHROME_MD) | 165 #endif // !defined(ENABLE_TOPCHROME_MD) |
| 162 | 166 |
| 163 } // namespace | 167 } // namespace |
| 164 } // namespace ui | 168 } // namespace ui |
| OLD | NEW |