OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/first_run/first_run_helper.h" | 5 #include "ash/first_run/first_run_helper.h" |
6 | 6 |
7 #include "ash/first_run/desktop_cleaner.h" | 7 #include "ash/first_run/desktop_cleaner.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ui/events/event_handler.h" | 11 #include "ui/events/event_handler.h" |
12 #include "ui/events/test/event_generator.h" | 12 #include "ui/events/test/event_generator.h" |
13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
14 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
15 | 15 |
16 namespace ash { | 16 namespace ash { |
17 namespace test { | 17 namespace test { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class TestModalDialogDelegate : public views::DialogDelegateView { | 21 class TestModalDialogDelegate : public views::DialogDelegateView { |
22 public: | 22 public: |
23 TestModalDialogDelegate() {} | 23 TestModalDialogDelegate() {} |
24 virtual ~TestModalDialogDelegate() {} | 24 ~TestModalDialogDelegate() override {} |
25 | 25 |
26 // Overridden from views::WidgetDelegate: | 26 // Overridden from views::WidgetDelegate: |
27 virtual ui::ModalType GetModalType() const override { | 27 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } |
28 return ui::MODAL_TYPE_SYSTEM; | |
29 } | |
30 | 28 |
31 private: | 29 private: |
32 DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate); | 30 DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate); |
33 }; | 31 }; |
34 | 32 |
35 class CountingEventHandler : public ui::EventHandler { | 33 class CountingEventHandler : public ui::EventHandler { |
36 public: | 34 public: |
37 // Handler resets |*mouse_events_registered_| during construction and updates | 35 // Handler resets |*mouse_events_registered_| during construction and updates |
38 // it after each registered event. | 36 // it after each registered event. |
39 explicit CountingEventHandler(int* mouse_events_registered) | 37 explicit CountingEventHandler(int* mouse_events_registered) |
40 : mouse_events_registered_(mouse_events_registered) { | 38 : mouse_events_registered_(mouse_events_registered) { |
41 *mouse_events_registered = 0; | 39 *mouse_events_registered = 0; |
42 } | 40 } |
43 | 41 |
44 virtual ~CountingEventHandler() {} | 42 ~CountingEventHandler() override {} |
45 | 43 |
46 private: | 44 private: |
47 // ui::EventHandler overrides. | 45 // ui::EventHandler overrides. |
48 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 46 void OnMouseEvent(ui::MouseEvent* event) override { |
49 ++*mouse_events_registered_; | 47 ++*mouse_events_registered_; |
50 } | 48 } |
51 | 49 |
52 int* mouse_events_registered_; | 50 int* mouse_events_registered_; |
53 | 51 |
54 DISALLOW_COPY_AND_ASSIGN(CountingEventHandler); | 52 DISALLOW_COPY_AND_ASSIGN(CountingEventHandler); |
55 }; | 53 }; |
56 | 54 |
57 } // namespace | 55 } // namespace |
58 | 56 |
59 class FirstRunHelperTest : public AshTestBase, | 57 class FirstRunHelperTest : public AshTestBase, |
60 public FirstRunHelper::Observer { | 58 public FirstRunHelper::Observer { |
61 public: | 59 public: |
62 FirstRunHelperTest() : cancelled_times_(0) {} | 60 FirstRunHelperTest() : cancelled_times_(0) {} |
63 | 61 |
64 virtual ~FirstRunHelperTest() {} | 62 ~FirstRunHelperTest() override {} |
65 | 63 |
66 virtual void SetUp() override { | 64 void SetUp() override { |
67 AshTestBase::SetUp(); | 65 AshTestBase::SetUp(); |
68 CheckContainersAreVisible(); | 66 CheckContainersAreVisible(); |
69 helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); | 67 helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); |
70 helper_->AddObserver(this); | 68 helper_->AddObserver(this); |
71 helper_->GetOverlayWidget()->Show(); | 69 helper_->GetOverlayWidget()->Show(); |
72 } | 70 } |
73 | 71 |
74 virtual void TearDown() override { | 72 void TearDown() override { |
75 EXPECT_TRUE(helper_.get()); | 73 EXPECT_TRUE(helper_.get()); |
76 helper_.reset(); | 74 helper_.reset(); |
77 CheckContainersAreVisible(); | 75 CheckContainersAreVisible(); |
78 AshTestBase::TearDown(); | 76 AshTestBase::TearDown(); |
79 } | 77 } |
80 | 78 |
81 void CheckContainersAreVisible() const { | 79 void CheckContainersAreVisible() const { |
82 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 80 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
83 std::vector<int> containers_to_check = | 81 std::vector<int> containers_to_check = |
84 DesktopCleaner::GetContainersToHideForTest(); | 82 DesktopCleaner::GetContainersToHideForTest(); |
(...skipping 14 matching lines...) Expand all Loading... |
99 EXPECT_TRUE(!container->IsVisible()); | 97 EXPECT_TRUE(!container->IsVisible()); |
100 } | 98 } |
101 } | 99 } |
102 | 100 |
103 FirstRunHelper* helper() { return helper_.get(); } | 101 FirstRunHelper* helper() { return helper_.get(); } |
104 | 102 |
105 int cancelled_times() const { return cancelled_times_; } | 103 int cancelled_times() const { return cancelled_times_; } |
106 | 104 |
107 private: | 105 private: |
108 // FirstRunHelper::Observer overrides. | 106 // FirstRunHelper::Observer overrides. |
109 virtual void OnCancelled() override { | 107 void OnCancelled() override { ++cancelled_times_; } |
110 ++cancelled_times_; | |
111 } | |
112 | 108 |
113 scoped_ptr<FirstRunHelper> helper_; | 109 scoped_ptr<FirstRunHelper> helper_; |
114 int cancelled_times_; | 110 int cancelled_times_; |
115 | 111 |
116 DISALLOW_COPY_AND_ASSIGN(FirstRunHelperTest); | 112 DISALLOW_COPY_AND_ASSIGN(FirstRunHelperTest); |
117 }; | 113 }; |
118 | 114 |
119 // This test creates helper, checks that containers are hidden and then | 115 // This test creates helper, checks that containers are hidden and then |
120 // destructs helper. | 116 // destructs helper. |
121 TEST_F(FirstRunHelperTest, ContainersAreHidden) { | 117 TEST_F(FirstRunHelperTest, ContainersAreHidden) { |
(...skipping 19 matching lines...) Expand all Loading... |
141 CountingEventHandler handler(&mouse_events); | 137 CountingEventHandler handler(&mouse_events); |
142 overlay_window->AddPreTargetHandler(&handler); | 138 overlay_window->AddPreTargetHandler(&handler); |
143 GetEventGenerator().PressLeftButton(); | 139 GetEventGenerator().PressLeftButton(); |
144 GetEventGenerator().ReleaseLeftButton(); | 140 GetEventGenerator().ReleaseLeftButton(); |
145 EXPECT_EQ(mouse_events, 2); | 141 EXPECT_EQ(mouse_events, 2); |
146 overlay_window->RemovePreTargetHandler(&handler); | 142 overlay_window->RemovePreTargetHandler(&handler); |
147 } | 143 } |
148 | 144 |
149 } // namespace test | 145 } // namespace test |
150 } // namespace ash | 146 } // namespace ash |
OLD | NEW |