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
3 // found in the LICENSE file.
7 #include "base/command_line.h"
8 #include "base/macros.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/resource/material_design/material_design_controller.h"
11 #include "ui/base/test/material_design_controller_test_api.h"
12 #include "ui/base/ui_base_switches.h"
17 // Test fixture for the MaterialDesignController class.
18 class MaterialDesignControllerTest
: public testing::Test
{
20 MaterialDesignControllerTest();
21 ~MaterialDesignControllerTest() override
;
24 void TearDown() override
;
27 DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest
);
30 MaterialDesignControllerTest::MaterialDesignControllerTest() {
33 MaterialDesignControllerTest::~MaterialDesignControllerTest() {
36 void MaterialDesignControllerTest::TearDown() {
37 testing::Test::TearDown();
39 // Ensure other tests aren't polluted by a Mode set in these tests.
40 test::MaterialDesignControllerTestAPI::UninitializeMode();
43 #if !defined(ENABLE_TOPCHROME_MD)
45 // Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not
47 TEST_F(MaterialDesignControllerTest
,
48 NonMaterialModeWhenCompileTimeFlagDisabled
) {
49 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL
,
50 MaterialDesignController::GetMode());
55 // Verify command line value "material" maps to Mode::MATERIAL when the compile
56 // time flag is defined.
57 TEST_F(MaterialDesignControllerTest
,
58 EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled
) {
59 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
60 switches::kTopChromeMD
, "material");
61 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL
,
62 MaterialDesignController::GetMode());
65 // Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID
66 // when the compile time flag is defined.
68 MaterialDesignControllerTest
,
69 EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnabled
) {
70 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
71 switches::kTopChromeMD
, "material-hybrid");
72 EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID
,
73 MaterialDesignController::GetMode());
76 // Verify command line value "" maps to Mode::NON_MATERIAL when the compile time
79 MaterialDesignControllerTest
,
80 DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled
) {
81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
82 switches::kTopChromeMD
, "");
83 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL
,
84 MaterialDesignController::GetMode());
87 // Verify no command line value maps to Mode::NON_MATERIAL when the compile time
89 TEST_F(MaterialDesignControllerTest
,
90 NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled
) {
91 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kTopChromeMD
));
93 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL
,
94 MaterialDesignController::GetMode());
97 // Verify an invalid command line value uses the default NON_MATERIAL mode.
98 TEST_F(MaterialDesignControllerTest
, InvalidCommandLineValue
) {
99 const std::string kInvalidValue
= "1nvalid-valu3";
100 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
101 switches::kTopChromeMD
, kInvalidValue
);
102 EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL
,
103 MaterialDesignController::GetMode());
106 // Verify that MaterialDesignController::IsModeMaterial() will initialize the
107 // mode if it hasn't been initialized yet.
108 TEST_F(MaterialDesignControllerTest
, IsModeMaterialInitializesMode
) {
109 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
110 switches::kTopChromeMD
, "material");
111 EXPECT_TRUE(MaterialDesignController::IsModeMaterial());
114 #endif // !defined(ENABLE_TOPCHROME_MD)