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