1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// Copyright 2015 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 <string>
#include "base/command_line.h"
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_switches.h"
namespace ui {
namespace {
// Test fixture for the MaterialDesignController class.
class MaterialDesignControllerTest : public testing::Test {
public:
MaterialDesignControllerTest();
~MaterialDesignControllerTest() override;
// testing::Test:
void SetUp() override;
private:
DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
};
MaterialDesignControllerTest::MaterialDesignControllerTest() {
}
MaterialDesignControllerTest::~MaterialDesignControllerTest() {
}
void MaterialDesignControllerTest::SetUp() {
testing::Test::SetUp();
// Ensure other tests aren't polluted by a Mode set in these tests. The Mode
// has to be cleared in SetUp and not in TearDown because when the test suite
// starts up it triggers a call to ResourceBundle::LoadCommonResources()
// which calls MaterialDesignController::IsModeMaterial(), thereby
// initializing the mode and potentially causing the first test to fail.
test::MaterialDesignControllerTestAPI::UninitializeMode();
}
#if !defined(ENABLE_TOPCHROME_MD)
// Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not
// defined.
TEST_F(MaterialDesignControllerTest,
NonMaterialModeWhenCompileTimeFlagDisabled) {
EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
MaterialDesignController::GetMode());
}
#else
// Verify command line value "material" maps to Mode::MATERIAL when the compile
// time flag is defined.
TEST_F(MaterialDesignControllerTest,
EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, "material");
EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL,
MaterialDesignController::GetMode());
}
// Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID
// when the compile time flag is defined.
TEST_F(
MaterialDesignControllerTest,
EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnabled) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, "material-hybrid");
EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID,
MaterialDesignController::GetMode());
}
// Verify command line value "" maps to the default mode when the compile time
// flag is defined.
TEST_F(
MaterialDesignControllerTest,
DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, "");
EXPECT_EQ(MaterialDesignController::DefaultMode(),
MaterialDesignController::GetMode());
}
// Verify the current mode is reported as the default mode when no command line
// flag is defined.
TEST_F(MaterialDesignControllerTest,
NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTopChromeMD));
EXPECT_EQ(MaterialDesignController::DefaultMode(),
MaterialDesignController::GetMode());
}
// Verify an invalid command line value uses the default mode.
TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) {
const std::string kInvalidValue = "1nvalid-valu3";
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, kInvalidValue);
EXPECT_EQ(MaterialDesignController::DefaultMode(),
MaterialDesignController::GetMode());
}
// Verify that MaterialDesignController::IsModeMaterial() will initialize the
// mode if it hasn't been initialized yet.
TEST_F(MaterialDesignControllerTest, IsModeMaterialInitializesMode) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, "material");
EXPECT_TRUE(MaterialDesignController::IsModeMaterial());
}
#endif // !defined(ENABLE_TOPCHROME_MD)
} // namespace
} // namespace ui
|