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

Side by Side Diff: ash/common/system/chromeos/palette/palette_tool_manager_unittest.cc

Issue 2140343002: Add palette tool/manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stylus-add-icons
Patch Set: Remove base::Optional, use VECTOR_ICON_NONE instead Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « ash/common/system/chromeos/palette/palette_tool_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "ash/common/system/chromeos/palette/palette_tool.h"
6 #include "ash/common/system/chromeos/palette/palette_tool_manager.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using namespace ash;
14
15 namespace {
16
17 // A simple tool instance that exposes some additional data for testing.
18 class TestTool : public PaletteTool {
19 public:
20 TestTool(Delegate* delegate, PaletteGroup group, PaletteToolId tool_id)
21 : PaletteTool(delegate), group_(group), tool_id_(tool_id) {}
22
23 // PaletteTool:
24 PaletteGroup GetGroup() const override { return group_; }
25 PaletteToolId GetToolId() const override { return tool_id_; }
26
27 // Shadows the parent declaration since PaletteTool::enabled is not virtual.
28 bool enabled() const { return PaletteTool::enabled(); }
29
30 private:
31 // PaletteTool:
32 views::View* CreateView() override {
33 NOTREACHED();
34 return nullptr;
35 }
36 void OnViewDestroyed() override { FAIL(); }
37
38 PaletteGroup group_;
39 PaletteToolId tool_id_;
40
41 DISALLOW_COPY_AND_ASSIGN(TestTool);
42 };
43
44 // Base class for tool manager unittests.
45 class PaletteToolManagerTest : public ::testing::Test,
46 public PaletteToolManager::Delegate,
47 public PaletteTool::Delegate {
48 public:
49 PaletteToolManagerTest()
50 : palette_tool_manager_(new PaletteToolManager(this)) {}
51 ~PaletteToolManagerTest() override {}
52
53 protected:
54 // PaletteToolManager::Delegate:
55 void HidePalette() override {}
56 void OnActiveToolChanged() override { ++tool_changed_count_; }
57 WmWindow* GetWindow() override {
58 NOTREACHED();
59 return nullptr;
60 }
61
62 // PaletteTool::Delegate:
63 void EnableTool(PaletteToolId tool_id) override {}
64 void DisableTool(PaletteToolId tool_id) override {}
65
66 // Helper method for returning an unowned pointer to the constructed tool
67 // while also adding it to the PaletteToolManager.
68 TestTool* BuildTool(PaletteGroup group, PaletteToolId tool_id) {
69 auto* tool = new TestTool(this, group, tool_id);
70 palette_tool_manager_->AddTool(base::WrapUnique(tool));
71 return tool;
72 }
73
74 int tool_changed_count_ = 0;
75 std::unique_ptr<PaletteToolManager> palette_tool_manager_;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(PaletteToolManagerTest);
79 };
80
81 } // namespace
82
83 // Verifies that tools can be enabled/disabled and that enabling a tool disables
84 // only active tools in the same group.
85 TEST_F(PaletteToolManagerTest, MultipleToolsActivateDeactivate) {
86 // Register actions/modes.
87 TestTool* action_1 =
88 BuildTool(PaletteGroup::ACTION, PaletteToolId::CREATE_NOTE);
89 TestTool* action_2 =
90 BuildTool(PaletteGroup::ACTION, PaletteToolId::CAPTURE_REGION);
91 TestTool* mode_1 = BuildTool(PaletteGroup::MODE, PaletteToolId::MAGNIFY);
92 TestTool* mode_2 =
93 BuildTool(PaletteGroup::MODE, PaletteToolId::LASER_POINTER);
94
95 // Enable mode 1.
96 EXPECT_EQ(0, tool_changed_count_);
97 palette_tool_manager_->ActivateTool(mode_1->GetToolId());
98 EXPECT_FALSE(action_1->enabled());
99 EXPECT_FALSE(action_2->enabled());
100 EXPECT_TRUE(mode_1->enabled());
101 EXPECT_FALSE(mode_2->enabled());
102
103 // Turn a single action on/off. Enabling/disabling the tool does not change
104 // any other group's state.
105 palette_tool_manager_->ActivateTool(action_1->GetToolId());
106 EXPECT_TRUE(action_1->enabled());
107 EXPECT_FALSE(action_2->enabled());
108 EXPECT_TRUE(mode_1->enabled());
109 EXPECT_FALSE(mode_2->enabled());
110 palette_tool_manager_->DeactivateTool(action_1->GetToolId());
111 EXPECT_FALSE(action_1->enabled());
112 EXPECT_FALSE(action_2->enabled());
113 EXPECT_TRUE(mode_1->enabled());
114 EXPECT_FALSE(mode_2->enabled());
115
116 // Activating a tool on will deactivate any other active tools in the same
117 // group.
118 palette_tool_manager_->ActivateTool(action_1->GetToolId());
119 EXPECT_TRUE(action_1->enabled());
120 EXPECT_FALSE(action_2->enabled());
121 palette_tool_manager_->ActivateTool(action_2->GetToolId());
122 EXPECT_FALSE(action_1->enabled());
123 EXPECT_TRUE(action_2->enabled());
124 palette_tool_manager_->DeactivateTool(action_2->GetToolId());
125
126 // Activating an already active tool will not do anything.
127 palette_tool_manager_->ActivateTool(action_1->GetToolId());
128 EXPECT_TRUE(action_1->enabled());
129 EXPECT_FALSE(action_2->enabled());
130 palette_tool_manager_->ActivateTool(action_1->GetToolId());
131 EXPECT_TRUE(action_1->enabled());
132 EXPECT_FALSE(action_2->enabled());
133 palette_tool_manager_->DeactivateTool(action_1->GetToolId());
134 }
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/palette/palette_tool_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698