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