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

Unified Diff: ash/common/system/chromeos/palette/tools/create_note_unittest.cc

Issue 2235063002: Add create note palette action. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app-runtime-changes
Patch Set: Comments and tests Created 4 years, 4 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/common/system/chromeos/palette/tools/create_note_unittest.cc
diff --git a/ash/common/system/chromeos/palette/tools/create_note_unittest.cc b/ash/common/system/chromeos/palette/tools/create_note_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3050c0fc510b12afbfe319d1f1f534c91dc6dd04
--- /dev/null
+++ b/ash/common/system/chromeos/palette/tools/create_note_unittest.cc
@@ -0,0 +1,85 @@
+// 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_ids.h"
+#include "ash/common/system/chromeos/palette/palette_tool.h"
+#include "ash/common/system/chromeos/palette/tools/create_note_action.h"
+#include "ash/common/test/test_palette_delegate.h"
+#include "ash/common/wm_shell.h"
+#include "ash/test/ash_test_base.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using namespace ash;
James Cook 2016/08/16 22:08:44 nit: just wrap the file in namespace ash { } unl
jdufault 2016/08/16 22:45:52 Done.
+
+namespace {
+
+// Mock PaletteTool::Delegate class.
+class MockPaletteToolDelegate : public PaletteTool::Delegate {
+ public:
+ MockPaletteToolDelegate() {}
+ ~MockPaletteToolDelegate() {}
James Cook 2016/08/16 22:08:45 override
jdufault 2016/08/16 22:45:52 Done.
+
+ MOCK_METHOD1(EnableTool, void(PaletteToolId tool_id));
+ MOCK_METHOD1(DisableTool, void(PaletteToolId tool_id));
+ MOCK_METHOD0(HidePalette, void());
+ MOCK_METHOD0(GetWindow, WmWindow*());
+};
+
+// Base class for all create note ash tests.
+class CreateNoteTest : public test::AshTestBase {
+ public:
+ CreateNoteTest() {}
+ ~CreateNoteTest() override {}
+
+ void SetUp() override {
+ test::AshTestBase::SetUp();
+
+ WmShell::Get()->SetPaletteDelegateForTesting(
+ base::MakeUnique<TestPaletteDelegate>());
+
+ palette_tool_delegate = base::MakeUnique<MockPaletteToolDelegate>();
+ tool = base::MakeUnique<CreateNoteAction>(palette_tool_delegate.get());
+ }
+
+ TestPaletteDelegate* test_palette_delegate() {
+ return static_cast<TestPaletteDelegate*>(
+ WmShell::Get()->palette_delegate());
+ }
+
+ std::unique_ptr<MockPaletteToolDelegate> palette_tool_delegate;
James Cook 2016/08/16 22:08:44 palette_tool_delegate_
jdufault 2016/08/16 22:45:51 Done; moved to protected as well.
+ std::unique_ptr<PaletteTool> tool;
James Cook 2016/08/16 22:08:44 tool_
jdufault 2016/08/16 22:45:52 Done; moved to protected as well.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CreateNoteTest);
+};
+
+} // namespace
+
+// The note tool is only visible when there is a note-taking app available.
+TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) {
+ test_palette_delegate()->set_has_note_app(false);
+ EXPECT_FALSE(tool->CreateView());
+ tool->OnViewDestroyed();
+
+ test_palette_delegate()->set_has_note_app(true);
+ std::unique_ptr<views::View> view = base::WrapUnique(tool->CreateView());
+ EXPECT_TRUE(view);
+ tool->OnViewDestroyed();
+}
+
+// Activating the note tool both creates a note via the delegate and also
+// disables the tool and hides the palette.
+TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) {
+ test_palette_delegate()->set_has_note_app(true);
+ std::unique_ptr<views::View> view = base::WrapUnique(tool->CreateView());
+
+ EXPECT_CALL(*palette_tool_delegate.get(),
+ DisableTool(PaletteToolId::CREATE_NOTE));
+ EXPECT_CALL(*palette_tool_delegate.get(), HidePalette());
+
+ tool->OnEnable();
+ EXPECT_EQ(1, test_palette_delegate()->create_note_count());
+}

Powered by Google App Engine
This is Rietveld 408576698