OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <memory> | |
6 #include <string> | |
7 | |
8 #include "ash/common/ash_switches.h" | |
9 #include "ash/common/material_design/material_design_controller.h" | |
10 #include "ash/common/test/material_design_controller_test_api.h" | |
11 #include "ash/test/ash_test_base.h" | |
12 #include "base/command_line.h" | |
13 #include "base/macros.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace ash { | |
17 namespace { | |
18 | |
19 // Test fixture for the MaterialDesignController class. | |
20 class MaterialDesignControllerTest : public ash::test::AshTestBase { | |
21 public: | |
22 MaterialDesignControllerTest() = default; | |
23 ~MaterialDesignControllerTest() override = default; | |
24 | |
25 protected: | |
26 // ash::test::AshTestBase: | |
27 void SetCommandLineValue(const std::string& value_string); | |
28 | |
29 private: | |
30 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); | |
31 }; | |
32 | |
33 void MaterialDesignControllerTest::SetCommandLineValue( | |
34 const std::string& value_string) { | |
35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
36 ash::switches::kAshMaterialDesign, value_string); | |
37 } | |
38 | |
39 class MaterialDesignControllerTestNonMaterial | |
40 : public MaterialDesignControllerTest { | |
41 public: | |
42 MaterialDesignControllerTestNonMaterial() : MaterialDesignControllerTest() {} | |
43 void SetUp() override { | |
44 SetCommandLineValue("disabled"); | |
45 MaterialDesignControllerTest::SetUp(); | |
46 } | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestNonMaterial); | |
50 }; | |
51 | |
52 class MaterialDesignControllerTestMaterial | |
53 : public MaterialDesignControllerTest { | |
54 public: | |
55 MaterialDesignControllerTestMaterial() : MaterialDesignControllerTest() {} | |
56 void SetUp() override { | |
57 SetCommandLineValue("enabled"); | |
58 MaterialDesignControllerTest::SetUp(); | |
59 } | |
60 | |
61 private: | |
62 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial); | |
63 }; | |
64 | |
65 class MaterialDesignControllerTestExperimental | |
66 : public MaterialDesignControllerTest { | |
67 public: | |
68 MaterialDesignControllerTestExperimental() : MaterialDesignControllerTest() {} | |
69 void SetUp() override { | |
70 SetCommandLineValue("experimental"); | |
71 MaterialDesignControllerTest::SetUp(); | |
72 } | |
73 | |
74 private: | |
75 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestExperimental); | |
76 }; | |
77 | |
78 class MaterialDesignControllerTestInvalid | |
79 : public MaterialDesignControllerTest { | |
80 public: | |
81 MaterialDesignControllerTestInvalid() : MaterialDesignControllerTest() {} | |
82 void SetUp() override { | |
83 SetCommandLineValue("1nvalid-valu3"); | |
84 MaterialDesignControllerTest::SetUp(); | |
85 } | |
86 | |
87 private: | |
88 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestInvalid); | |
89 }; | |
90 | |
91 } // namespace | |
92 | |
93 // Verify the current mode is reported as the default mode when no command line | |
94 // flag is added. | |
95 TEST_F(MaterialDesignControllerTest, NoCommandLineValueMapsToDefaultMode) { | |
96 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
97 ash::switches::kAshMaterialDesign)); | |
98 EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() == | |
99 MaterialDesignController::Mode::MATERIAL_NORMAL || | |
100 test::MaterialDesignControllerTestAPI::DefaultMode() == | |
101 MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL, | |
102 test::MaterialDesignControllerTestAPI::IsMaterial()); | |
103 } | |
104 | |
105 // Verify that MaterialDesignController::IsMaterial() will be false when | |
106 // initialized with command line flag "disabled". | |
107 TEST_F(MaterialDesignControllerTestNonMaterial, CommandLineValue) { | |
108 EXPECT_FALSE(test::MaterialDesignControllerTestAPI::IsMaterial()); | |
109 EXPECT_FALSE(test::MaterialDesignControllerTestAPI::IsMaterialExperimental()); | |
110 } | |
111 | |
112 // Verify that MaterialDesignController::IsMaterial() will be true when | |
113 // initialized with command line flag "enabled". | |
114 TEST_F(MaterialDesignControllerTestMaterial, CommandLineValue) { | |
115 EXPECT_TRUE(test::MaterialDesignControllerTestAPI::IsMaterial()); | |
116 EXPECT_FALSE(test::MaterialDesignControllerTestAPI::IsMaterialExperimental()); | |
117 } | |
118 | |
119 // Verify that MaterialDesignController::IsMaterialexperimental() will be true | |
120 // when initialized with command line flag "experimental". | |
121 TEST_F(MaterialDesignControllerTestExperimental, CommandLineValue) { | |
122 EXPECT_TRUE(test::MaterialDesignControllerTestAPI::IsMaterial()); | |
123 EXPECT_TRUE(test::MaterialDesignControllerTestAPI::IsMaterialExperimental()); | |
124 } | |
125 | |
126 // Verify an invalid command line value uses the default mode. | |
127 TEST_F(MaterialDesignControllerTestInvalid, CommandLineValue) { | |
128 EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() == | |
129 MaterialDesignController::Mode::MATERIAL_NORMAL || | |
130 test::MaterialDesignControllerTestAPI::DefaultMode() == | |
131 MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL, | |
132 test::MaterialDesignControllerTestAPI::IsMaterial()); | |
133 } | |
134 | |
135 } // namespace ash | |
OLD | NEW |