Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: ui/base/material_design/material_design_controller_unittest.cc

Issue 1878943002: Revert of Makes MaterialDesignController initialization explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:
24 // testing::Test: 23 // testing::Test:
25 void SetUp() override; 24 void SetUp() override;
26 void TearDown() override;
27 void SetCommandLineSwitch(const std::string& value_string);
28 25
29 private: 26 private:
30 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); 27 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
31 }; 28 };
32 29
33 MaterialDesignControllerTest::MaterialDesignControllerTest() { 30 MaterialDesignControllerTest::MaterialDesignControllerTest() {
34 } 31 }
35 32
36 MaterialDesignControllerTest::~MaterialDesignControllerTest() { 33 MaterialDesignControllerTest::~MaterialDesignControllerTest() {
37 } 34 }
38 35
39 void MaterialDesignControllerTest::SetUp() { 36 void MaterialDesignControllerTest::SetUp() {
40 testing::Test::SetUp(); 37 testing::Test::SetUp();
41 MaterialDesignController::Initialize(); 38
39 // Ensure other tests aren't polluted by a Mode set in these tests. The Mode
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();
42 } 45 }
43 46
44 void MaterialDesignControllerTest::TearDown() {
45 test::MaterialDesignControllerTestAPI::UninitializeMode();
46 testing::Test::TearDown();
47 }
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
64 private:
65 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial);
66 };
67
68 class MaterialDesignControllerTestHybrid : public MaterialDesignControllerTest {
69 public:
70 MaterialDesignControllerTestHybrid() {
71 SetCommandLineSwitch("material-hybrid");
72 }
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestHybrid);
76 };
77
78 class MaterialDesignControllerTestDefault :
79 public MaterialDesignControllerTest {
80 public:
81 MaterialDesignControllerTestDefault() {
82 SetCommandLineSwitch(std::string());
83 }
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestDefault);
87 };
88
89 class MaterialDesignControllerTestInvalid :
90 public MaterialDesignControllerTest {
91 public:
92 MaterialDesignControllerTestInvalid() {
93 const std::string kInvalidValue = "1nvalid-valu3";
94 SetCommandLineSwitch(kInvalidValue);
95 }
96
97 private:
98 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestInvalid);
99 };
100
101 #if !defined(ENABLE_TOPCHROME_MD) 47 #if !defined(ENABLE_TOPCHROME_MD)
102 48
103 // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not 49 // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not
104 // defined. 50 // defined.
105 TEST_F(MaterialDesignControllerTest, 51 TEST_F(MaterialDesignControllerTest,
106 NonMaterialModeWhenCompileTimeFlagDisabled) { 52 NonMaterialModeWhenCompileTimeFlagDisabled) {
107 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL, 53 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
108 MaterialDesignController::GetMode()); 54 MaterialDesignController::GetMode());
109 } 55 }
110 56
111 #else 57 #else
112 58
113 // Verify command line value "material" maps to Mode::MATERIAL when the compile 59 // Verify command line value "material" maps to Mode::MATERIAL when the compile
114 // time flag is defined. 60 // time flag is defined.
115 TEST_F(MaterialDesignControllerTestMaterial, 61 TEST_F(MaterialDesignControllerTest,
116 EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) { 62 EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) {
63 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
64 switches::kTopChromeMD, "material");
117 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL, 65 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL,
118 MaterialDesignController::GetMode()); 66 MaterialDesignController::GetMode());
119 } 67 }
120 68
121 // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID 69 // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID
122 // when the compile time flag is defined. 70 // when the compile time flag is defined.
123 TEST_F( 71 TEST_F(
124 MaterialDesignControllerTestHybrid, 72 MaterialDesignControllerTest,
125 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab led) { 73 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnab led) {
74 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
75 switches::kTopChromeMD, "material-hybrid");
126 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID, 76 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID,
127 MaterialDesignController::GetMode()); 77 MaterialDesignController::GetMode());
128 } 78 }
129 79
130 // Verify command line value "" maps to the default mode when the compile time 80 // Verify command line value "" maps to the default mode when the compile time
131 // flag is defined. 81 // flag is defined.
132 TEST_F( 82 TEST_F(
133 MaterialDesignControllerTestDefault, 83 MaterialDesignControllerTest,
134 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { 84 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
85 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
86 switches::kTopChromeMD, "");
135 EXPECT_EQ(MaterialDesignController::DefaultMode(), 87 EXPECT_EQ(MaterialDesignController::DefaultMode(),
136 MaterialDesignController::GetMode()); 88 MaterialDesignController::GetMode());
137 } 89 }
138 90
139 // Verify the current mode is reported as the default mode when no command line 91 // Verify the current mode is reported as the default mode when no command line
140 // flag is defined. 92 // flag is defined.
141 TEST_F(MaterialDesignControllerTest, 93 TEST_F(MaterialDesignControllerTest,
142 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) { 94 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
143 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( 95 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
144 switches::kTopChromeMD)); 96 switches::kTopChromeMD));
145 EXPECT_EQ(MaterialDesignController::DefaultMode(), 97 EXPECT_EQ(MaterialDesignController::DefaultMode(),
146 MaterialDesignController::GetMode()); 98 MaterialDesignController::GetMode());
147 } 99 }
148 100
149 // Verify an invalid command line value uses the default mode. 101 // Verify an invalid command line value uses the default mode.
150 TEST_F(MaterialDesignControllerTestInvalid, InvalidCommandLineValue) { 102 TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) {
103 const std::string kInvalidValue = "1nvalid-valu3";
104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
105 switches::kTopChromeMD, kInvalidValue);
151 EXPECT_EQ(MaterialDesignController::DefaultMode(), 106 EXPECT_EQ(MaterialDesignController::DefaultMode(),
152 MaterialDesignController::GetMode()); 107 MaterialDesignController::GetMode());
153 } 108 }
154 109
155 // Verify that MaterialDesignController::IsModeMaterial() will be true when 110 // Verify that MaterialDesignController::IsModeMaterial() will initialize the
156 // initialized with command line flag "material". 111 // mode if it hasn't been initialized yet.
157 TEST_F(MaterialDesignControllerTestMaterial, IsModeMaterialInitializesMode) { 112 TEST_F(MaterialDesignControllerTest, IsModeMaterialInitializesMode) {
113 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
114 switches::kTopChromeMD, "material");
158 EXPECT_TRUE(MaterialDesignController::IsModeMaterial()); 115 EXPECT_TRUE(MaterialDesignController::IsModeMaterial());
159 } 116 }
160 117
161 #endif // !defined(ENABLE_TOPCHROME_MD) 118 #endif // !defined(ENABLE_TOPCHROME_MD)
162 119
163 } // namespace 120 } // namespace
164 } // namespace ui 121 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/material_design/material_design_controller.cc ('k') | ui/message_center/views/bounded_label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698