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

Unified Diff: ash/material_design/material_design_controller_unittest.cc

Issue 1921133002: Adds ash::MaterialDesignController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds ash::MaterialDesignController (unit_tests) 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 side-by-side diff with in-line comments
Download patch
Index: ash/material_design/material_design_controller_unittest.cc
diff --git a/ash/material_design/material_design_controller_unittest.cc b/ash/material_design/material_design_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16732cbd00ef288bc119defdb44d3d542be3ce1e
--- /dev/null
+++ b/ash/material_design/material_design_controller_unittest.cc
@@ -0,0 +1,174 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <memory>
+#include <string>
+
+#include "ash/ash_switches.h"
+#include "ash/material_design/material_design_controller.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/test/material_design_controller_test_api.h"
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ash {
+namespace {
+
+// Saves and restores command line.
+// 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!
+// available.
+class ScopedCommandLineSwitch {
+ public:
+ ScopedCommandLineSwitch(const std::string& flag, const std::string& value)
+ : original_command_line_(*base::CommandLine::ForCurrentProcess()) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(flag, value);
+ }
+
+ ~ScopedCommandLineSwitch() {
+ *base::CommandLine::ForCurrentProcess() = original_command_line_;
+ }
+
+ private:
+ base::CommandLine original_command_line_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCommandLineSwitch);
+};
+
+// Test fixture for the MaterialDesignController class.
+class MaterialDesignControllerTest : public ash::test::AshTestBase {
+ public:
+ MaterialDesignControllerTest();
+ ~MaterialDesignControllerTest() override;
oshima 2016/04/27 21:51:04 nit: or just = default for ctor/dtor.
varkha 2016/04/27 22:14:00 Done.
+
+ protected:
+ // testing::Test:
+ void SetUp() override;
+ void TearDown() override;
+ void SetCommandLineValue(const std::string& value_string);
+
+ private:
+ std::unique_ptr<ScopedCommandLineSwitch> scoped_switch_;
+
+ DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
+};
+
+MaterialDesignControllerTest::MaterialDesignControllerTest() {}
+
+MaterialDesignControllerTest::~MaterialDesignControllerTest() {}
+
+void MaterialDesignControllerTest::SetUp() {
+ ash::test::AshTestBase::SetUp();
+}
oshima 2016/04/27 21:51:04 not necessary?
varkha 2016/04/27 22:14:00 Done. Right, old scaffolding.
+
+void MaterialDesignControllerTest::TearDown() {
+ ash::test::AshTestBase::TearDown();
+ scoped_switch_.reset();
+ ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshMaterialDesign));
+}
+
+void MaterialDesignControllerTest::SetCommandLineValue(
+ const std::string& value_string) {
+ scoped_switch_.reset(new ScopedCommandLineSwitch(
+ ash::switches::kAshMaterialDesign, value_string));
+}
+
+class MaterialDesignControllerTestNonMaterial
+ : public MaterialDesignControllerTest {
+ public:
+ MaterialDesignControllerTestNonMaterial() : MaterialDesignControllerTest() {}
+ void SetUp() override {
+ SetCommandLineValue("disabled");
+ MaterialDesignControllerTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestNonMaterial);
+};
+
+class MaterialDesignControllerTestMaterial
+ : public MaterialDesignControllerTest {
+ public:
+ MaterialDesignControllerTestMaterial() : MaterialDesignControllerTest() {}
+ void SetUp() override {
+ SetCommandLineValue("enabled");
+ MaterialDesignControllerTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestMaterial);
+};
+
+class MaterialDesignControllerTestExperimental
+ : public MaterialDesignControllerTest {
+ public:
+ MaterialDesignControllerTestExperimental() : MaterialDesignControllerTest() {}
+ void SetUp() override {
+ SetCommandLineValue("experimental");
+ MaterialDesignControllerTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestExperimental);
+};
+
+class MaterialDesignControllerTestInvalid
+ : public MaterialDesignControllerTest {
+ public:
+ MaterialDesignControllerTestInvalid() : MaterialDesignControllerTest() {}
+ void SetUp() override {
+ SetCommandLineValue("1nvalid-valu3");
+ MaterialDesignControllerTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestInvalid);
+};
+
+} // namespace
+
+// Verify the current mode is reported as the default mode when no command line
+// flag is added.
+TEST_F(MaterialDesignControllerTest, NoCommandLineValueMapsToDefaultMode) {
+ ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshMaterialDesign));
+ EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() ==
+ MaterialDesignController::Mode::MATERIAL_NORMAL ||
+ test::MaterialDesignControllerTestAPI::DefaultMode() ==
+ MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL,
+ MaterialDesignController::IsMaterial());
+}
+
+// Verify that MaterialDesignController::IsMaterial() will be false when
+// initialized with command line flag "disabled".
+TEST_F(MaterialDesignControllerTestNonMaterial, CommandLineValue) {
+ EXPECT_FALSE(MaterialDesignController::IsMaterial());
+ EXPECT_FALSE(MaterialDesignController::IsMaterialExperimental());
+}
+
+// Verify that MaterialDesignController::IsMaterial() will be true when
+// initialized with command line flag "enabled".
+TEST_F(MaterialDesignControllerTestMaterial, CommandLineValue) {
+ EXPECT_TRUE(MaterialDesignController::IsMaterial());
+ EXPECT_FALSE(MaterialDesignController::IsMaterialExperimental());
+}
+
+// Verify that MaterialDesignController::IsMaterialexperimental() will be true
+// when initialized with command line flag "experimental".
+TEST_F(MaterialDesignControllerTestExperimental, CommandLineValue) {
+ EXPECT_TRUE(MaterialDesignController::IsMaterial());
+ EXPECT_TRUE(MaterialDesignController::IsMaterialExperimental());
+}
+
+// Verify an invalid command line value uses the default mode.
+TEST_F(MaterialDesignControllerTestInvalid, CommandLineValue) {
+ EXPECT_EQ(test::MaterialDesignControllerTestAPI::DefaultMode() ==
+ MaterialDesignController::Mode::MATERIAL_NORMAL ||
+ test::MaterialDesignControllerTestAPI::DefaultMode() ==
+ MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL,
+ MaterialDesignController::IsMaterial());
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698