Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_ids.h" | |
| 6 #include "ash/common/system/chromeos/palette/palette_tool.h" | |
| 7 #include "ash/common/system/chromeos/palette/tools/create_note_action.h" | |
| 8 #include "ash/common/test/test_palette_delegate.h" | |
| 9 #include "ash/common/wm_shell.h" | |
| 10 #include "ash/test/ash_test_base.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 | |
| 15 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.
| |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Mock PaletteTool::Delegate class. | |
| 20 class MockPaletteToolDelegate : public PaletteTool::Delegate { | |
| 21 public: | |
| 22 MockPaletteToolDelegate() {} | |
| 23 ~MockPaletteToolDelegate() {} | |
|
James Cook
2016/08/16 22:08:45
override
jdufault
2016/08/16 22:45:52
Done.
| |
| 24 | |
| 25 MOCK_METHOD1(EnableTool, void(PaletteToolId tool_id)); | |
| 26 MOCK_METHOD1(DisableTool, void(PaletteToolId tool_id)); | |
| 27 MOCK_METHOD0(HidePalette, void()); | |
| 28 MOCK_METHOD0(GetWindow, WmWindow*()); | |
| 29 }; | |
| 30 | |
| 31 // Base class for all create note ash tests. | |
| 32 class CreateNoteTest : public test::AshTestBase { | |
| 33 public: | |
| 34 CreateNoteTest() {} | |
| 35 ~CreateNoteTest() override {} | |
| 36 | |
| 37 void SetUp() override { | |
| 38 test::AshTestBase::SetUp(); | |
| 39 | |
| 40 WmShell::Get()->SetPaletteDelegateForTesting( | |
| 41 base::MakeUnique<TestPaletteDelegate>()); | |
| 42 | |
| 43 palette_tool_delegate = base::MakeUnique<MockPaletteToolDelegate>(); | |
| 44 tool = base::MakeUnique<CreateNoteAction>(palette_tool_delegate.get()); | |
| 45 } | |
| 46 | |
| 47 TestPaletteDelegate* test_palette_delegate() { | |
| 48 return static_cast<TestPaletteDelegate*>( | |
| 49 WmShell::Get()->palette_delegate()); | |
| 50 } | |
| 51 | |
| 52 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.
| |
| 53 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.
| |
| 54 | |
| 55 private: | |
| 56 DISALLOW_COPY_AND_ASSIGN(CreateNoteTest); | |
| 57 }; | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 // The note tool is only visible when there is a note-taking app available. | |
| 62 TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) { | |
| 63 test_palette_delegate()->set_has_note_app(false); | |
| 64 EXPECT_FALSE(tool->CreateView()); | |
| 65 tool->OnViewDestroyed(); | |
| 66 | |
| 67 test_palette_delegate()->set_has_note_app(true); | |
| 68 std::unique_ptr<views::View> view = base::WrapUnique(tool->CreateView()); | |
| 69 EXPECT_TRUE(view); | |
| 70 tool->OnViewDestroyed(); | |
| 71 } | |
| 72 | |
| 73 // Activating the note tool both creates a note via the delegate and also | |
| 74 // disables the tool and hides the palette. | |
| 75 TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) { | |
| 76 test_palette_delegate()->set_has_note_app(true); | |
| 77 std::unique_ptr<views::View> view = base::WrapUnique(tool->CreateView()); | |
| 78 | |
| 79 EXPECT_CALL(*palette_tool_delegate.get(), | |
| 80 DisableTool(PaletteToolId::CREATE_NOTE)); | |
| 81 EXPECT_CALL(*palette_tool_delegate.get(), HidePalette()); | |
| 82 | |
| 83 tool->OnEnable(); | |
| 84 EXPECT_EQ(1, test_palette_delegate()->create_note_count()); | |
| 85 } | |
| OLD | NEW |