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/system/tray/tray_details_view.h" | 5 #include "ash/system/tray/tray_details_view.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_widget.h" | 8 #include "ash/shelf/shelf_widget.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
11 #include "ash/system/tray/hover_highlight_view.h" | 11 #include "ash/system/tray/hover_highlight_view.h" |
12 #include "ash/system/tray/special_popup_row.h" | 12 #include "ash/system/tray/special_popup_row.h" |
13 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_item.h" | 14 #include "ash/system/tray/system_tray_item.h" |
15 #include "ash/system/tray/tray_details_view.h" | 15 #include "ash/system/tray/tray_popup_header_button.h" |
16 #include "ash/system/tray/view_click_listener.h" | 16 #include "ash/system/tray/view_click_listener.h" |
17 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "grit/ash_resources.h" |
19 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
21 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
| 23 #include "ui/views/controls/button/button.h" |
22 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
24 | 26 |
25 namespace ash { | 27 namespace ash { |
26 namespace test { | 28 namespace test { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 SystemTray* GetSystemTray() { | 32 SystemTray* GetSystemTray() { |
31 return Shell::GetPrimaryRootWindowController()->shelf()-> | 33 return Shell::GetPrimaryRootWindowController()->shelf()-> |
32 status_area_widget()->system_tray(); | 34 status_area_widget()->system_tray(); |
33 } | 35 } |
34 | 36 |
35 class TestDetailsView : public TrayDetailsView, public ViewClickListener { | 37 class TestDetailsView : public TrayDetailsView, |
| 38 public ViewClickListener, |
| 39 public views::ButtonListener { |
36 public: | 40 public: |
37 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { | 41 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { |
38 // Uses bluetooth label for testing purpose. It can be changed to any | 42 // Uses bluetooth label for testing purpose. It can be changed to any |
39 // string_id. | 43 // string_id. |
40 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | 44 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
| 45 tray_popup_header_button_ = |
| 46 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| 47 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, |
| 48 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, |
| 49 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, |
| 50 IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| 51 footer()->AddButton(tray_popup_header_button_); |
41 } | 52 } |
42 | 53 |
43 ~TestDetailsView() override {} | 54 ~TestDetailsView() override {} |
44 | 55 |
| 56 TrayPopupHeaderButton* tray_popup_header_button() { |
| 57 return tray_popup_header_button_; |
| 58 } |
| 59 |
45 void FocusFooter() { | 60 void FocusFooter() { |
46 footer()->content()->RequestFocus(); | 61 footer()->content()->RequestFocus(); |
47 } | 62 } |
48 | 63 |
49 // Overridden from ViewClickListener: | 64 // ViewClickListener: |
50 void OnViewClicked(views::View* sender) override {} | 65 void OnViewClicked(views::View* sender) override {} |
51 | 66 |
| 67 // views::ButtonListener: |
| 68 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} |
| 69 |
52 private: | 70 private: |
| 71 TrayPopupHeaderButton* tray_popup_header_button_; |
| 72 |
53 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 73 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
54 }; | 74 }; |
55 | 75 |
56 // Trivial item implementation that tracks its views for testing. | 76 // Trivial item implementation that tracks its views for testing. |
57 class TestItem : public SystemTrayItem { | 77 class TestItem : public SystemTrayItem { |
58 public: | 78 public: |
59 TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} | 79 TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} |
60 | 80 |
61 // Overridden from SystemTrayItem: | 81 // Overridden from SystemTrayItem: |
62 views::View* CreateTrayView(user::LoginStatus status) override { | 82 views::View* CreateTrayView(user::LoginStatus status) override { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 tray->AddTrayItem(test_item); | 121 tray->AddTrayItem(test_item); |
102 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 122 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
103 RunAllPendingInMessageLoop(); | 123 RunAllPendingInMessageLoop(); |
104 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 124 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
105 RunAllPendingInMessageLoop(); | 125 RunAllPendingInMessageLoop(); |
106 | 126 |
107 return static_cast<HoverHighlightView*>(test_item->detailed_view()-> | 127 return static_cast<HoverHighlightView*>(test_item->detailed_view()-> |
108 footer()->content()); | 128 footer()->content()); |
109 } | 129 } |
110 | 130 |
| 131 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { |
| 132 SystemTray* tray = GetSystemTray(); |
| 133 TestItem* test_item = new TestItem; |
| 134 tray->AddTrayItem(test_item); |
| 135 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 136 RunAllPendingInMessageLoop(); |
| 137 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 138 RunAllPendingInMessageLoop(); |
| 139 |
| 140 return test_item->detailed_view()->tray_popup_header_button(); |
| 141 } |
| 142 |
111 private: | 143 private: |
112 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); | 144 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); |
113 }; | 145 }; |
114 | 146 |
115 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { | 147 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { |
116 SystemTray* tray = GetSystemTray(); | 148 SystemTray* tray = GetSystemTray(); |
117 ASSERT_TRUE(tray->GetWidget()); | 149 ASSERT_TRUE(tray->GetWidget()); |
118 | 150 |
119 TestItem* test_item_1 = new TestItem; | 151 TestItem* test_item_1 = new TestItem; |
120 TestItem* test_item_2 = new TestItem; | 152 TestItem* test_item_2 = new TestItem; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 generator.MoveTouch(move_point); | 225 generator.MoveTouch(move_point); |
194 RunAllPendingInMessageLoop(); | 226 RunAllPendingInMessageLoop(); |
195 EXPECT_FALSE(view->hover()); | 227 EXPECT_FALSE(view->hover()); |
196 | 228 |
197 generator.set_current_location(move_point); | 229 generator.set_current_location(move_point); |
198 generator.ReleaseTouch(); | 230 generator.ReleaseTouch(); |
199 RunAllPendingInMessageLoop(); | 231 RunAllPendingInMessageLoop(); |
200 EXPECT_FALSE(view->hover()); | 232 EXPECT_FALSE(view->hover()); |
201 } | 233 } |
202 | 234 |
| 235 // Tests that TrayPopupHeaderButton renders a background in response to touch. |
| 236 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { |
| 237 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 238 EXPECT_FALSE(button->background()); |
| 239 |
| 240 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 241 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); |
| 242 generator.PressTouch(); |
| 243 RunAllPendingInMessageLoop(); |
| 244 EXPECT_TRUE(button->background()); |
| 245 |
| 246 generator.ReleaseTouch(); |
| 247 RunAllPendingInMessageLoop(); |
| 248 EXPECT_FALSE(button->background()); |
| 249 } |
| 250 |
| 251 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch |
| 252 // feedback background. |
| 253 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { |
| 254 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 255 EXPECT_FALSE(button->background()); |
| 256 |
| 257 gfx::Rect view_bounds = button->GetBoundsInScreen(); |
| 258 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 259 generator.set_current_location(view_bounds.CenterPoint()); |
| 260 generator.PressTouch(); |
| 261 RunAllPendingInMessageLoop(); |
| 262 EXPECT_TRUE(button->background()); |
| 263 |
| 264 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
| 265 generator.MoveTouch(move_point); |
| 266 RunAllPendingInMessageLoop(); |
| 267 EXPECT_FALSE(button->background()); |
| 268 |
| 269 generator.set_current_location(move_point); |
| 270 generator.ReleaseTouch(); |
| 271 RunAllPendingInMessageLoop(); |
| 272 EXPECT_FALSE(button->background()); |
| 273 } |
| 274 |
| 275 // Tests that a mouse entering TrayPopupHeaderButton renders a background as |
| 276 // visual feedback. |
| 277 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { |
| 278 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 279 EXPECT_FALSE(button->background()); |
| 280 |
| 281 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 282 gfx::Rect bounds = button->GetBoundsInScreen(); |
| 283 gfx::Point initial_point(bounds.x() - 1, bounds.y()); |
| 284 generator.set_current_location(initial_point); |
| 285 generator.MoveMouseBy(1, 0); |
| 286 RunAllPendingInMessageLoop(); |
| 287 EXPECT_TRUE(button->background()); |
| 288 } |
| 289 |
203 } // namespace test | 290 } // namespace test |
204 } // namespace ash | 291 } // namespace ash |
OLD | NEW |