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 virtual ~TestModalDialogDelegate() {} |
25 | 25 |
26 // Overridden from views::WidgetDelegate: | 26 // Overridden from views::WidgetDelegate: |
27 virtual ui::ModalType GetModalType() const OVERRIDE { | 27 virtual ui::ModalType GetModalType() const override { |
28 return ui::MODAL_TYPE_SYSTEM; | 28 return ui::MODAL_TYPE_SYSTEM; |
29 } | 29 } |
30 | 30 |
31 private: | 31 private: |
32 DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate); | 32 DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate); |
33 }; | 33 }; |
34 | 34 |
35 class CountingEventHandler : public ui::EventHandler { | 35 class CountingEventHandler : public ui::EventHandler { |
36 public: | 36 public: |
37 // Handler resets |*mouse_events_registered_| during construction and updates | 37 // Handler resets |*mouse_events_registered_| during construction and updates |
38 // it after each registered event. | 38 // it after each registered event. |
39 explicit CountingEventHandler(int* mouse_events_registered) | 39 explicit CountingEventHandler(int* mouse_events_registered) |
40 : mouse_events_registered_(mouse_events_registered) { | 40 : mouse_events_registered_(mouse_events_registered) { |
41 *mouse_events_registered = 0; | 41 *mouse_events_registered = 0; |
42 } | 42 } |
43 | 43 |
44 virtual ~CountingEventHandler() {} | 44 virtual ~CountingEventHandler() {} |
45 | 45 |
46 private: | 46 private: |
47 // ui::EventHandler overrides. | 47 // ui::EventHandler overrides. |
48 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 48 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
49 ++*mouse_events_registered_; | 49 ++*mouse_events_registered_; |
50 } | 50 } |
51 | 51 |
52 int* mouse_events_registered_; | 52 int* mouse_events_registered_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(CountingEventHandler); | 54 DISALLOW_COPY_AND_ASSIGN(CountingEventHandler); |
55 }; | 55 }; |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 class FirstRunHelperTest : public AshTestBase, | 59 class FirstRunHelperTest : public AshTestBase, |
60 public FirstRunHelper::Observer { | 60 public FirstRunHelper::Observer { |
61 public: | 61 public: |
62 FirstRunHelperTest() : cancelled_times_(0) {} | 62 FirstRunHelperTest() : cancelled_times_(0) {} |
63 | 63 |
64 virtual ~FirstRunHelperTest() {} | 64 virtual ~FirstRunHelperTest() {} |
65 | 65 |
66 virtual void SetUp() OVERRIDE { | 66 virtual void SetUp() override { |
67 AshTestBase::SetUp(); | 67 AshTestBase::SetUp(); |
68 CheckContainersAreVisible(); | 68 CheckContainersAreVisible(); |
69 helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); | 69 helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); |
70 helper_->AddObserver(this); | 70 helper_->AddObserver(this); |
71 helper_->GetOverlayWidget()->Show(); | 71 helper_->GetOverlayWidget()->Show(); |
72 } | 72 } |
73 | 73 |
74 virtual void TearDown() OVERRIDE { | 74 virtual void TearDown() override { |
75 EXPECT_TRUE(helper_.get()); | 75 EXPECT_TRUE(helper_.get()); |
76 helper_.reset(); | 76 helper_.reset(); |
77 CheckContainersAreVisible(); | 77 CheckContainersAreVisible(); |
78 AshTestBase::TearDown(); | 78 AshTestBase::TearDown(); |
79 } | 79 } |
80 | 80 |
81 void CheckContainersAreVisible() const { | 81 void CheckContainersAreVisible() const { |
82 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 82 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
83 std::vector<int> containers_to_check = | 83 std::vector<int> containers_to_check = |
84 DesktopCleaner::GetContainersToHideForTest(); | 84 DesktopCleaner::GetContainersToHideForTest(); |
(...skipping 14 matching lines...) Expand all Loading... |
99 EXPECT_TRUE(!container->IsVisible()); | 99 EXPECT_TRUE(!container->IsVisible()); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 FirstRunHelper* helper() { return helper_.get(); } | 103 FirstRunHelper* helper() { return helper_.get(); } |
104 | 104 |
105 int cancelled_times() const { return cancelled_times_; } | 105 int cancelled_times() const { return cancelled_times_; } |
106 | 106 |
107 private: | 107 private: |
108 // FirstRunHelper::Observer overrides. | 108 // FirstRunHelper::Observer overrides. |
109 virtual void OnCancelled() OVERRIDE { | 109 virtual void OnCancelled() override { |
110 ++cancelled_times_; | 110 ++cancelled_times_; |
111 } | 111 } |
112 | 112 |
113 scoped_ptr<FirstRunHelper> helper_; | 113 scoped_ptr<FirstRunHelper> helper_; |
114 int cancelled_times_; | 114 int cancelled_times_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(FirstRunHelperTest); | 116 DISALLOW_COPY_AND_ASSIGN(FirstRunHelperTest); |
117 }; | 117 }; |
118 | 118 |
119 // This test creates helper, checks that containers are hidden and then | 119 // This test creates helper, checks that containers are hidden and then |
(...skipping 21 matching lines...) Expand all Loading... |
141 CountingEventHandler handler(&mouse_events); | 141 CountingEventHandler handler(&mouse_events); |
142 overlay_window->AddPreTargetHandler(&handler); | 142 overlay_window->AddPreTargetHandler(&handler); |
143 GetEventGenerator().PressLeftButton(); | 143 GetEventGenerator().PressLeftButton(); |
144 GetEventGenerator().ReleaseLeftButton(); | 144 GetEventGenerator().ReleaseLeftButton(); |
145 EXPECT_EQ(mouse_events, 2); | 145 EXPECT_EQ(mouse_events, 2); |
146 overlay_window->RemovePreTargetHandler(&handler); | 146 overlay_window->RemovePreTargetHandler(&handler); |
147 } | 147 } |
148 | 148 |
149 } // namespace test | 149 } // namespace test |
150 } // namespace ash | 150 } // namespace ash |
OLD | NEW |