Chromium Code Reviews| 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/ash_switches.h" | |
| 9 #include "ash/material_design/material_design_controller.h" | |
| 10 #include "ash/test/ash_test_base.h" | |
| 11 #include "ash/test/material_design_controller_test_api.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 // Saves and restores command line. | |
| 20 // TODO(varkha): replace with base/test/scoped_command_line.h when it becomes | |
|
oshima
2016/04/27 21:51:04
According to the comment in that CL, my understand
varkha
2016/04/27 22:14:00
Right, thanks!
| |
| 21 // available. | |
| 22 class ScopedCommandLineSwitch { | |
| 23 public: | |
| 24 ScopedCommandLineSwitch(const std::string& flag, const std::string& value) | |
| 25 : original_command_line_(*base::CommandLine::ForCurrentProcess()) { | |
| 26 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(flag, value); | |
| 27 } | |
| 28 | |
| 29 ~ScopedCommandLineSwitch() { | |
| 30 *base::CommandLine::ForCurrentProcess() = original_command_line_; | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 base::CommandLine original_command_line_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(ScopedCommandLineSwitch); | |
| 37 }; | |
| 38 | |
| 39 // Test fixture for the MaterialDesignController class. | |
| 40 class MaterialDesignControllerTest : public ash::test::AshTestBase { | |
| 41 public: | |
| 42 MaterialDesignControllerTest(); | |
| 43 ~MaterialDesignControllerTest() override; | |
|
oshima
2016/04/27 21:51:04
nit: or just
= default
for ctor/dtor.
varkha
2016/04/27 22:14:00
Done.
| |
| 44 | |
| 45 protected: | |
| 46 // testing::Test: | |
| 47 void SetUp() override; | |
| 48 void TearDown() override; | |
| 49 void SetCommandLineValue(const std::string& value_string); | |
| 50 | |
| 51 private: | |
| 52 std::unique_ptr<ScopedCommandLineSwitch> scoped_switch_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); | |
| 55 }; | |
| 56 | |
| 57 MaterialDesignControllerTest::MaterialDesignControllerTest() {} | |
| 58 | |
| 59 MaterialDesignControllerTest::~MaterialDesignControllerTest() {} | |
| 60 | |
| 61 void MaterialDesignControllerTest::SetUp() { | |
| 62 ash::test::AshTestBase::SetUp(); | |
| 63 } | |
|
oshima
2016/04/27 21:51:04
not necessary?
varkha
2016/04/27 22:14:00
Done. Right, old scaffolding.
| |
| 64 | |
| 65 void MaterialDesignControllerTest::TearDown() { | |
| 66 ash::test::AshTestBase::TearDown(); | |
| 67 scoped_switch_.reset(); | |
| 68 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 69 ash::switches::kAshMaterialDesign)); | |
| 70 } | |
| 71 | |
| 72 void MaterialDesignControllerTest::SetCommandLineValue( | |
| 73 const std::string& value_string) { | |
| 74 scoped_switch_.reset(new ScopedCommandLineSwitch( | |
| 75 ash::switches::kAshMaterialDesign, value_string)); | |
| 76 } | |
| 77 | |
| 78 class MaterialDesignControllerTestNonMaterial | |
| 79 : public MaterialDesignControllerTest { | |
| 80 public: | |
| 81 MaterialDesignControllerTestNonMaterial() : MaterialDesignControllerTest() {} | |
| 82 void SetUp() override { | |
| 83 SetCommandLineValue("disabled"); | |
| 84 MaterialDesignControllerTest::SetUp(); | |
| 85 } | |
| 86 | |
| 87 private: | |
| 88 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestNonMaterial); | |
| 89 }; | |
| 90 | |
| 91 class MaterialDesignControllerTestMaterial | |
| 92 : public MaterialDesignControllerTest { | |
| 93 public: | |
| 94 MaterialDesignControllerTestMaterial() : MaterialDesignControllerTest() {} | |
| 95 void SetUp() override { | |
| 96 SetCommandLineValue("enabled"); | |
| 97 MaterialDesignControllerTest::SetUp(); | |
| 98 } | |
| 99 | |
| 100 private: | |
| 101 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial); | |
| 102 }; | |
| 103 | |
| 104 class MaterialDesignControllerTestExperimental | |
| 105 : public MaterialDesignControllerTest { | |
| 106 public: | |
| 107 MaterialDesignControllerTestExperimental() : MaterialDesignControllerTest() {} | |
| 108 void SetUp() override { | |
| 109 SetCommandLineValue("experimental"); | |
| 110 MaterialDesignControllerTest::SetUp(); | |
| 111 } | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestExperimental); | |
| 115 }; | |
| 116 | |
| 117 class MaterialDesignControllerTestInvalid | |
| 118 : public MaterialDesignControllerTest { | |
| 119 public: | |
| 120 MaterialDesignControllerTestInvalid() : MaterialDesignControllerTest() {} | |
| 121 void SetUp() override { | |
| 122 SetCommandLineValue("1nvalid-valu3"); | |
| 123 MaterialDesignControllerTest::SetUp(); | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestInvalid); | |
| 128 }; | |
| 129 | |
| 130 } // namespace | |
| 131 | |
| 132 // Verify the current mode is reported as the default mode when no command line | |
| 133 // flag is added. | |
| 134 TEST_F(MaterialDesignControllerTest, NoCommandLineValueMapsToDefaultMode) { | |
| 135 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 136 ash::switches::kAshMaterialDesign)); | |
| 137 EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() == | |
| 138 MaterialDesignController::Mode::MATERIAL_NORMAL || | |
| 139 test::MaterialDesignControllerTestAPI::DefaultMode() == | |
| 140 MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL, | |
| 141 MaterialDesignController::IsMaterial()); | |
| 142 } | |
| 143 | |
| 144 // Verify that MaterialDesignController::IsMaterial() will be false when | |
| 145 // initialized with command line flag "disabled". | |
| 146 TEST_F(MaterialDesignControllerTestNonMaterial, CommandLineValue) { | |
| 147 EXPECT_FALSE(MaterialDesignController::IsMaterial()); | |
| 148 EXPECT_FALSE(MaterialDesignController::IsMaterialExperimental()); | |
| 149 } | |
| 150 | |
| 151 // Verify that MaterialDesignController::IsMaterial() will be true when | |
| 152 // initialized with command line flag "enabled". | |
| 153 TEST_F(MaterialDesignControllerTestMaterial, CommandLineValue) { | |
| 154 EXPECT_TRUE(MaterialDesignController::IsMaterial()); | |
| 155 EXPECT_FALSE(MaterialDesignController::IsMaterialExperimental()); | |
| 156 } | |
| 157 | |
| 158 // Verify that MaterialDesignController::IsMaterialexperimental() will be true | |
| 159 // when initialized with command line flag "experimental". | |
| 160 TEST_F(MaterialDesignControllerTestExperimental, CommandLineValue) { | |
| 161 EXPECT_TRUE(MaterialDesignController::IsMaterial()); | |
| 162 EXPECT_TRUE(MaterialDesignController::IsMaterialExperimental()); | |
| 163 } | |
| 164 | |
| 165 // Verify an invalid command line value uses the default mode. | |
| 166 TEST_F(MaterialDesignControllerTestInvalid, CommandLineValue) { | |
| 167 EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() == | |
| 168 MaterialDesignController::Mode::MATERIAL_NORMAL || | |
| 169 test::MaterialDesignControllerTestAPI::DefaultMode() == | |
| 170 MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL, | |
| 171 MaterialDesignController::IsMaterial()); | |
| 172 } | |
| 173 | |
| 174 } // namespace ash | |
| OLD | NEW |