Chromium Code Reviews| 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/common/system/tray/hover_highlight_view.h" | 7 #include "ash/common/system/tray/hover_highlight_view.h" |
| 8 #include "ash/common/system/tray/special_popup_row.h" | 8 #include "ash/common/system/tray/special_popup_row.h" |
| 9 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
| 10 #include "ash/common/system/tray/tray_popup_header_button.h" | 10 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 11 #include "ash/common/system/tray/view_click_listener.h" | 11 #include "ash/common/system/tray/view_click_listener.h" |
| 12 #include "ash/root_window_controller.h" | |
| 13 #include "ash/shelf/shelf_widget.h" | |
| 14 #include "ash/shell.h" | |
| 15 #include "ash/system/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
| 16 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
| 17 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 18 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 19 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 20 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 21 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 22 #include "ui/events/test/event_generator.h" | 19 #include "ui/events/test/event_generator.h" |
| 23 #include "ui/views/controls/button/button.h" | 20 #include "ui/views/controls/button/button.h" |
| 24 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 26 | 23 |
| 27 namespace ash { | 24 namespace ash { |
| 28 namespace test { | 25 namespace test { |
| 29 | 26 |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| 32 SystemTray* GetSystemTray() { | |
| 33 return Shell::GetPrimaryRootWindowController() | |
| 34 ->shelf_widget() | |
| 35 ->status_area_widget() | |
| 36 ->system_tray(); | |
| 37 } | |
| 38 | |
| 39 class TestDetailsView : public TrayDetailsView, | 29 class TestDetailsView : public TrayDetailsView, |
| 40 public ViewClickListener, | 30 public ViewClickListener, |
| 41 public views::ButtonListener { | 31 public views::ButtonListener { |
| 42 public: | 32 public: |
| 43 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { | 33 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { |
| 44 // Uses bluetooth label for testing purpose. It can be changed to any | 34 // Uses bluetooth label for testing purpose. It can be changed to any |
| 45 // string_id. | 35 // string_id. |
| 46 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | 36 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
| 47 tray_popup_header_button_ = | 37 tray_popup_header_button_ = |
| 48 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | 38 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 71 | 61 |
| 72 private: | 62 private: |
| 73 TrayPopupHeaderButton* tray_popup_header_button_; | 63 TrayPopupHeaderButton* tray_popup_header_button_; |
| 74 | 64 |
| 75 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 65 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
| 76 }; | 66 }; |
| 77 | 67 |
| 78 // Trivial item implementation that tracks its views for testing. | 68 // Trivial item implementation that tracks its views for testing. |
| 79 class TestItem : public SystemTrayItem { | 69 class TestItem : public SystemTrayItem { |
| 80 public: | 70 public: |
| 81 TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} | 71 TestItem() |
| 72 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()), | |
| 73 tray_view_(nullptr), | |
| 74 default_view_(nullptr), | |
| 75 detailed_view_(nullptr) {} | |
| 82 | 76 |
| 83 // Overridden from SystemTrayItem: | 77 // Overridden from SystemTrayItem: |
| 84 views::View* CreateTrayView(LoginStatus status) override { | 78 views::View* CreateTrayView(LoginStatus status) override { |
| 85 tray_view_ = new views::View; | 79 tray_view_ = new views::View; |
| 86 return tray_view_; | 80 return tray_view_; |
| 87 } | 81 } |
| 88 views::View* CreateDefaultView(LoginStatus status) override { | 82 views::View* CreateDefaultView(LoginStatus status) override { |
| 89 default_view_ = new views::View; | 83 default_view_ = new views::View; |
| 90 default_view_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | 84 default_view_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 91 return default_view_; | 85 return default_view_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 111 }; | 105 }; |
| 112 | 106 |
| 113 } // namespace | 107 } // namespace |
| 114 | 108 |
| 115 class TrayDetailsViewTest : public AshTestBase { | 109 class TrayDetailsViewTest : public AshTestBase { |
| 116 public: | 110 public: |
| 117 TrayDetailsViewTest() {} | 111 TrayDetailsViewTest() {} |
| 118 ~TrayDetailsViewTest() override {} | 112 ~TrayDetailsViewTest() override {} |
| 119 | 113 |
| 120 HoverHighlightView* CreateAndShowHoverHighlightView() { | 114 HoverHighlightView* CreateAndShowHoverHighlightView() { |
| 121 SystemTray* tray = GetSystemTray(); | 115 SystemTray* tray = GetPrimarySystemTray(); |
| 122 TestItem* test_item = new TestItem; | 116 TestItem* test_item = new TestItem; |
| 123 tray->AddTrayItem(test_item); | 117 tray->AddTrayItem(test_item); |
| 124 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 118 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 125 RunAllPendingInMessageLoop(); | 119 RunAllPendingInMessageLoop(); |
| 126 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 120 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 127 RunAllPendingInMessageLoop(); | 121 RunAllPendingInMessageLoop(); |
| 128 | 122 |
| 129 return static_cast<HoverHighlightView*>(test_item->detailed_view()-> | 123 return static_cast<HoverHighlightView*>(test_item->detailed_view()-> |
| 130 footer()->content()); | 124 footer()->content()); |
| 131 } | 125 } |
| 132 | 126 |
| 133 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { | 127 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { |
| 134 SystemTray* tray = GetSystemTray(); | 128 SystemTray* tray = GetPrimarySystemTray(); |
| 135 TestItem* test_item = new TestItem; | 129 TestItem* test_item = new TestItem; |
| 136 tray->AddTrayItem(test_item); | 130 tray->AddTrayItem(test_item); |
| 137 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 131 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 138 RunAllPendingInMessageLoop(); | 132 RunAllPendingInMessageLoop(); |
| 139 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 133 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 140 RunAllPendingInMessageLoop(); | 134 RunAllPendingInMessageLoop(); |
| 141 | 135 |
| 142 return test_item->detailed_view()->tray_popup_header_button(); | 136 return test_item->detailed_view()->tray_popup_header_button(); |
| 143 } | 137 } |
| 144 | 138 |
| 145 private: | 139 private: |
| 146 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); | 140 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); |
| 147 }; | 141 }; |
| 148 | 142 |
| 149 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { | 143 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { |
| 150 SystemTray* tray = GetSystemTray(); | 144 SystemTray* tray = GetPrimarySystemTray(); |
| 151 ASSERT_TRUE(tray->GetWidget()); | 145 ASSERT_TRUE(tray->GetWidget()); |
| 152 | 146 |
| 153 TestItem* test_item_1 = new TestItem; | 147 TestItem* test_item_1 = new TestItem; |
| 154 TestItem* test_item_2 = new TestItem; | 148 TestItem* test_item_2 = new TestItem; |
| 155 tray->AddTrayItem(test_item_1); | 149 tray->AddTrayItem(test_item_1); |
| 156 tray->AddTrayItem(test_item_2); | 150 tray->AddTrayItem(test_item_2); |
| 157 | 151 |
| 158 // Ensure the tray views are created. | 152 // Ensure the tray views are created. |
| 159 ASSERT_TRUE(test_item_1->tray_view() != NULL); | 153 ASSERT_TRUE(test_item_1->tray_view() != NULL); |
| 160 ASSERT_TRUE(test_item_2->tray_view() != NULL); | 154 ASSERT_TRUE(test_item_2->tray_view() != NULL); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 EXPECT_TRUE(test_item_2->default_view()); | 187 EXPECT_TRUE(test_item_2->default_view()); |
| 194 EXPECT_FALSE(test_item_2->detailed_view()); | 188 EXPECT_FALSE(test_item_2->detailed_view()); |
| 195 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); | 189 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); |
| 196 } | 190 } |
| 197 | 191 |
| 198 // Tests that HoverHighlightView enters hover state in response to touch. | 192 // Tests that HoverHighlightView enters hover state in response to touch. |
| 199 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { | 193 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { |
| 200 HoverHighlightView* view = CreateAndShowHoverHighlightView(); | 194 HoverHighlightView* view = CreateAndShowHoverHighlightView(); |
| 201 EXPECT_FALSE(view->hover()); | 195 EXPECT_FALSE(view->hover()); |
| 202 | 196 |
| 203 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 197 ui::test::EventGenerator& generator = GetEventGenerator(); |
|
msw
2016/06/17 19:58:37
Hmm, I thought we discouraged non-const refs, but
James Cook
2016/06/17 20:14:32
Yeah, this is bad, but GetEventGenerator() predate
| |
| 204 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | 198 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); |
| 205 generator.PressTouch(); | 199 generator.PressTouch(); |
| 206 EXPECT_TRUE(view->hover()); | 200 EXPECT_TRUE(view->hover()); |
| 207 | 201 |
| 208 generator.ReleaseTouch(); | 202 generator.ReleaseTouch(); |
| 209 EXPECT_FALSE(view->hover()); | 203 EXPECT_FALSE(view->hover()); |
| 210 } | 204 } |
| 211 | 205 |
| 212 // Tests that touch events leaving HoverHighlightView cancel the hover state. | 206 // Tests that touch events leaving HoverHighlightView cancel the hover state. |
| 213 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) { | 207 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) { |
| 214 HoverHighlightView* view = CreateAndShowHoverHighlightView(); | 208 HoverHighlightView* view = CreateAndShowHoverHighlightView(); |
| 215 EXPECT_FALSE(view->hover()); | 209 EXPECT_FALSE(view->hover()); |
| 216 | 210 |
| 217 gfx::Rect view_bounds = view->GetBoundsInScreen(); | 211 gfx::Rect view_bounds = view->GetBoundsInScreen(); |
| 218 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 212 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 219 generator.set_current_location(view_bounds.CenterPoint()); | 213 generator.set_current_location(view_bounds.CenterPoint()); |
| 220 generator.PressTouch(); | 214 generator.PressTouch(); |
| 221 EXPECT_TRUE(view->hover()); | 215 EXPECT_TRUE(view->hover()); |
| 222 | 216 |
| 223 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | 217 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
| 224 generator.MoveTouch(move_point); | 218 generator.MoveTouch(move_point); |
| 225 EXPECT_FALSE(view->hover()); | 219 EXPECT_FALSE(view->hover()); |
| 226 | 220 |
| 227 generator.set_current_location(move_point); | 221 generator.set_current_location(move_point); |
| 228 generator.ReleaseTouch(); | 222 generator.ReleaseTouch(); |
| 229 EXPECT_FALSE(view->hover()); | 223 EXPECT_FALSE(view->hover()); |
| 230 } | 224 } |
| 231 | 225 |
| 232 // Tests that TrayPopupHeaderButton renders a background in response to touch. | 226 // Tests that TrayPopupHeaderButton renders a background in response to touch. |
| 233 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { | 227 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { |
| 234 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 228 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 235 EXPECT_FALSE(button->background()); | 229 EXPECT_FALSE(button->background()); |
| 236 | 230 |
| 237 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 231 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 238 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); | 232 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); |
| 239 generator.PressTouch(); | 233 generator.PressTouch(); |
| 240 EXPECT_TRUE(button->background()); | 234 EXPECT_TRUE(button->background()); |
| 241 | 235 |
| 242 generator.ReleaseTouch(); | 236 generator.ReleaseTouch(); |
| 243 EXPECT_FALSE(button->background()); | 237 EXPECT_FALSE(button->background()); |
| 244 } | 238 } |
| 245 | 239 |
| 246 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch | 240 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch |
| 247 // feedback background. | 241 // feedback background. |
| 248 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { | 242 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { |
| 249 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 243 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 250 EXPECT_FALSE(button->background()); | 244 EXPECT_FALSE(button->background()); |
| 251 | 245 |
| 252 gfx::Rect view_bounds = button->GetBoundsInScreen(); | 246 gfx::Rect view_bounds = button->GetBoundsInScreen(); |
| 253 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 247 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 254 generator.set_current_location(view_bounds.CenterPoint()); | 248 generator.set_current_location(view_bounds.CenterPoint()); |
| 255 generator.PressTouch(); | 249 generator.PressTouch(); |
| 256 EXPECT_TRUE(button->background()); | 250 EXPECT_TRUE(button->background()); |
| 257 | 251 |
| 258 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | 252 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
| 259 generator.MoveTouch(move_point); | 253 generator.MoveTouch(move_point); |
| 260 EXPECT_FALSE(button->background()); | 254 EXPECT_FALSE(button->background()); |
| 261 | 255 |
| 262 generator.set_current_location(move_point); | 256 generator.set_current_location(move_point); |
| 263 generator.ReleaseTouch(); | 257 generator.ReleaseTouch(); |
| 264 EXPECT_FALSE(button->background()); | 258 EXPECT_FALSE(button->background()); |
| 265 } | 259 } |
| 266 | 260 |
| 267 // Tests that a mouse entering TrayPopupHeaderButton renders a background as | 261 // Tests that a mouse entering TrayPopupHeaderButton renders a background as |
| 268 // visual feedback. | 262 // visual feedback. |
| 269 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { | 263 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { |
| 270 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 264 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
| 271 EXPECT_FALSE(button->background()); | 265 EXPECT_FALSE(button->background()); |
| 272 | 266 |
| 273 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 267 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 274 gfx::Rect bounds = button->GetBoundsInScreen(); | 268 gfx::Rect bounds = button->GetBoundsInScreen(); |
| 275 gfx::Point initial_point(bounds.x() - 1, bounds.y()); | 269 gfx::Point initial_point(bounds.x() - 1, bounds.y()); |
| 276 generator.set_current_location(initial_point); | 270 generator.set_current_location(initial_point); |
| 277 generator.MoveMouseBy(1, 0); | 271 generator.MoveMouseBy(1, 0); |
| 278 RunAllPendingInMessageLoop(); | 272 RunAllPendingInMessageLoop(); |
| 279 EXPECT_TRUE(button->background()); | 273 EXPECT_TRUE(button->background()); |
| 280 } | 274 } |
| 281 | 275 |
| 282 } // namespace test | 276 } // namespace test |
| 283 } // namespace ash | 277 } // namespace ash |
| OLD | NEW |