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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/system/chromeos/palette/palette_tool_manager_unittest.cc
diff --git a/ash/common/system/chromeos/palette/palette_tool_manager_unittest.cc b/ash/common/system/chromeos/palette/palette_tool_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45b4c416aa20965a48ae37200b5e470419116b37
--- /dev/null
+++ b/ash/common/system/chromeos/palette/palette_tool_manager_unittest.cc
@@ -0,0 +1,134 @@
+// 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 "ash/common/system/chromeos/palette/palette_tool.h"
+#include "ash/common/system/chromeos/palette/palette_tool_manager.h"
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using namespace ash;
+
+namespace {
+
+// A simple tool instance that exposes some additional data for testing.
+class TestTool : public PaletteTool {
+ public:
+ TestTool(Delegate* delegate, PaletteGroup group, PaletteToolId tool_id)
+ : PaletteTool(delegate), group_(group), tool_id_(tool_id) {}
+
+ // PaletteTool:
+ PaletteGroup GetGroup() const override { return group_; }
+ PaletteToolId GetToolId() const override { return tool_id_; }
+
+ // Shadows the parent declaration since PaletteTool::enabled is not virtual.
+ bool enabled() const { return PaletteTool::enabled(); }
+
+ private:
+ // PaletteTool:
+ views::View* CreateView() override {
+ NOTREACHED();
+ return nullptr;
+ }
+ void OnViewDestroyed() override { FAIL(); }
+
+ PaletteGroup group_;
+ PaletteToolId tool_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTool);
+};
+
+// Base class for tool manager unittests.
+class PaletteToolManagerTest : public ::testing::Test,
+ public PaletteToolManager::Delegate,
+ public PaletteTool::Delegate {
+ public:
+ PaletteToolManagerTest()
+ : palette_tool_manager_(new PaletteToolManager(this)) {}
+ ~PaletteToolManagerTest() override {}
+
+ protected:
+ // PaletteToolManager::Delegate:
+ void HidePalette() override {}
+ void OnActiveToolChanged() override { ++tool_changed_count_; }
+ WmWindow* GetWindow() override {
+ NOTREACHED();
+ return nullptr;
+ }
+
+ // PaletteTool::Delegate:
+ void EnableTool(PaletteToolId tool_id) override {}
+ void DisableTool(PaletteToolId tool_id) override {}
+
+ // Helper method for returning an unowned pointer to the constructed tool
+ // while also adding it to the PaletteToolManager.
+ TestTool* BuildTool(PaletteGroup group, PaletteToolId tool_id) {
+ auto* tool = new TestTool(this, group, tool_id);
+ palette_tool_manager_->AddTool(base::WrapUnique(tool));
+ return tool;
+ }
+
+ int tool_changed_count_ = 0;
+ std::unique_ptr<PaletteToolManager> palette_tool_manager_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PaletteToolManagerTest);
+};
+
+} // namespace
+
+// Verifies that tools can be enabled/disabled and that enabling a tool disables
+// only active tools in the same group.
+TEST_F(PaletteToolManagerTest, MultipleToolsActivateDeactivate) {
+ // Register actions/modes.
+ TestTool* action_1 =
+ BuildTool(PaletteGroup::ACTION, PaletteToolId::CREATE_NOTE);
+ TestTool* action_2 =
+ BuildTool(PaletteGroup::ACTION, PaletteToolId::CAPTURE_REGION);
+ TestTool* mode_1 = BuildTool(PaletteGroup::MODE, PaletteToolId::MAGNIFY);
+ TestTool* mode_2 =
+ BuildTool(PaletteGroup::MODE, PaletteToolId::LASER_POINTER);
+
+ // Enable mode 1.
+ EXPECT_EQ(0, tool_changed_count_);
+ palette_tool_manager_->ActivateTool(mode_1->GetToolId());
+ EXPECT_FALSE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ EXPECT_TRUE(mode_1->enabled());
+ EXPECT_FALSE(mode_2->enabled());
+
+ // Turn a single action on/off. Enabling/disabling the tool does not change
+ // any other group's state.
+ palette_tool_manager_->ActivateTool(action_1->GetToolId());
+ EXPECT_TRUE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ EXPECT_TRUE(mode_1->enabled());
+ EXPECT_FALSE(mode_2->enabled());
+ palette_tool_manager_->DeactivateTool(action_1->GetToolId());
+ EXPECT_FALSE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ EXPECT_TRUE(mode_1->enabled());
+ EXPECT_FALSE(mode_2->enabled());
+
+ // Activating a tool on will deactivate any other active tools in the same
+ // group.
+ palette_tool_manager_->ActivateTool(action_1->GetToolId());
+ EXPECT_TRUE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ palette_tool_manager_->ActivateTool(action_2->GetToolId());
+ EXPECT_FALSE(action_1->enabled());
+ EXPECT_TRUE(action_2->enabled());
+ palette_tool_manager_->DeactivateTool(action_2->GetToolId());
+
+ // Activating an already active tool will not do anything.
+ palette_tool_manager_->ActivateTool(action_1->GetToolId());
+ EXPECT_TRUE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ palette_tool_manager_->ActivateTool(action_1->GetToolId());
+ EXPECT_TRUE(action_1->enabled());
+ EXPECT_FALSE(action_2->enabled());
+ palette_tool_manager_->DeactivateTool(action_1->GetToolId());
+}
« 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