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/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" | |
| 12 #include "ash/system/tray/special_popup_row.h" | |
| 11 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
| 12 #include "ash/system/tray/system_tray_item.h" | 14 #include "ash/system/tray/system_tray_item.h" |
| 13 #include "ash/system/tray/tray_details_view.h" | 15 #include "ash/system/tray/tray_details_view.h" |
| 14 #include "ash/system/tray/view_click_listener.h" | 16 #include "ash/system/tray/view_click_listener.h" |
| 15 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 18 #include "base/command_line.h" | |
| 16 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 17 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 18 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/base/ui_base_switches.h" | |
| 23 #include "ui/events/test/event_generator.h" | |
| 19 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 21 | 26 |
| 22 namespace ash { | 27 namespace ash { |
| 23 namespace test { | 28 namespace test { |
| 24 | 29 |
| 25 namespace { | 30 namespace { |
| 26 | 31 |
| 27 SystemTray* GetSystemTray() { | 32 SystemTray* GetSystemTray() { |
| 28 return Shell::GetPrimaryRootWindowController()->shelf()-> | 33 return Shell::GetPrimaryRootWindowController()->shelf()-> |
| 29 status_area_widget()->system_tray(); | 34 status_area_widget()->system_tray(); |
| 30 } | 35 } |
| 31 | 36 |
| 32 class TestDetailsView : public TrayDetailsView, public ViewClickListener { | 37 class TestDetailsView : public TrayDetailsView, public ViewClickListener { |
| 33 public: | 38 public: |
| 34 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) {} | 39 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { |
| 40 // Uses bluetooth label for testing purpose. It can be changed to any | |
| 41 // string_id. | |
| 42 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | |
| 43 } | |
| 35 | 44 |
| 36 virtual ~TestDetailsView() {} | 45 virtual ~TestDetailsView() {} |
| 37 | 46 |
| 38 void CreateFooterAndFocus() { | 47 void FocusFooter() { |
| 39 // Uses bluetooth label for testing purpose. It can be changed to any | |
| 40 // string_id. | |
| 41 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | |
| 42 footer()->content()->RequestFocus(); | 48 footer()->content()->RequestFocus(); |
| 43 } | 49 } |
| 44 | 50 |
| 45 // Overridden from ViewClickListener: | 51 // Overridden from ViewClickListener: |
| 46 virtual void OnViewClicked(views::View* sender) OVERRIDE {} | 52 virtual void OnViewClicked(views::View* sender) OVERRIDE {} |
| 47 | 53 |
| 48 private: | 54 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 55 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
| 50 }; | 56 }; |
| 51 | 57 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 private: | 91 private: |
| 86 views::View* tray_view_; | 92 views::View* tray_view_; |
| 87 views::View* default_view_; | 93 views::View* default_view_; |
| 88 TestDetailsView* detailed_view_; | 94 TestDetailsView* detailed_view_; |
| 89 | 95 |
| 90 DISALLOW_COPY_AND_ASSIGN(TestItem); | 96 DISALLOW_COPY_AND_ASSIGN(TestItem); |
| 91 }; | 97 }; |
| 92 | 98 |
| 93 } // namespace | 99 } // namespace |
| 94 | 100 |
| 95 typedef AshTestBase TrayDetailsViewTest; | 101 class TrayDetailsViewTest : public AshTestBase { |
| 102 public: | |
| 103 TrayDetailsViewTest() {} | |
| 104 virtual ~TrayDetailsViewTest() {} | |
| 105 | |
| 106 virtual void SetUp() OVERRIDE { | |
| 107 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 108 switches::kEnableTouchFeedback); | |
| 109 test::AshTestBase::SetUp(); | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); | |
| 114 }; | |
| 96 | 115 |
| 97 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { | 116 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { |
| 98 SystemTray* tray = GetSystemTray(); | 117 SystemTray* tray = GetSystemTray(); |
| 99 ASSERT_TRUE(tray->GetWidget()); | 118 ASSERT_TRUE(tray->GetWidget()); |
| 100 | 119 |
| 101 TestItem* test_item_1 = new TestItem; | 120 TestItem* test_item_1 = new TestItem; |
| 102 TestItem* test_item_2 = new TestItem; | 121 TestItem* test_item_2 = new TestItem; |
| 103 tray->AddTrayItem(test_item_1); | 122 tray->AddTrayItem(test_item_1); |
| 104 tray->AddTrayItem(test_item_2); | 123 tray->AddTrayItem(test_item_2); |
| 105 | 124 |
| 106 // Ensure the tray views are created. | 125 // Ensure the tray views are created. |
| 107 ASSERT_TRUE(test_item_1->tray_view() != NULL); | 126 ASSERT_TRUE(test_item_1->tray_view() != NULL); |
| 108 ASSERT_TRUE(test_item_2->tray_view() != NULL); | 127 ASSERT_TRUE(test_item_2->tray_view() != NULL); |
| 109 | 128 |
| 110 // Show the default view. | 129 // Show the default view. |
| 111 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 130 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 112 RunAllPendingInMessageLoop(); | 131 RunAllPendingInMessageLoop(); |
| 113 | 132 |
| 114 // Show the detailed view of item 2. | 133 // Show the detailed view of item 2. |
| 115 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 134 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 116 EXPECT_TRUE(test_item_2->detailed_view()); | 135 EXPECT_TRUE(test_item_2->detailed_view()); |
| 117 RunAllPendingInMessageLoop(); | 136 RunAllPendingInMessageLoop(); |
| 118 EXPECT_FALSE(test_item_2->default_view()); | 137 EXPECT_FALSE(test_item_2->default_view()); |
| 119 | 138 |
| 120 // Transition back to default view, the default view of item 2 should have | 139 // Transition back to default view, the default view of item 2 should have |
| 121 // focus. | 140 // focus. |
| 122 test_item_2->detailed_view()->CreateFooterAndFocus(); | 141 test_item_2->detailed_view()->FocusFooter(); |
| 123 test_item_2->detailed_view()->TransitionToDefaultView(); | 142 test_item_2->detailed_view()->TransitionToDefaultView(); |
| 124 RunAllPendingInMessageLoop(); | 143 RunAllPendingInMessageLoop(); |
| 125 | 144 |
| 126 EXPECT_TRUE(test_item_2->default_view()); | 145 EXPECT_TRUE(test_item_2->default_view()); |
| 127 EXPECT_FALSE(test_item_2->detailed_view()); | 146 EXPECT_FALSE(test_item_2->detailed_view()); |
| 128 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); | 147 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); |
| 129 | 148 |
| 130 // Show the detailed view of item 2 again. | 149 // Show the detailed view of item 2 again. |
| 131 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 150 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 132 EXPECT_TRUE(test_item_2->detailed_view()); | 151 EXPECT_TRUE(test_item_2->detailed_view()); |
| 133 RunAllPendingInMessageLoop(); | 152 RunAllPendingInMessageLoop(); |
| 134 EXPECT_FALSE(test_item_2->default_view()); | 153 EXPECT_FALSE(test_item_2->default_view()); |
| 135 | 154 |
| 136 // Transition back to default view, the default view of item 2 should NOT have | 155 // Transition back to default view, the default view of item 2 should NOT have |
| 137 // focus. | 156 // focus. |
| 138 test_item_2->detailed_view()->TransitionToDefaultView(); | 157 test_item_2->detailed_view()->TransitionToDefaultView(); |
| 139 RunAllPendingInMessageLoop(); | 158 RunAllPendingInMessageLoop(); |
| 140 | 159 |
| 141 EXPECT_TRUE(test_item_2->default_view()); | 160 EXPECT_TRUE(test_item_2->default_view()); |
| 142 EXPECT_FALSE(test_item_2->detailed_view()); | 161 EXPECT_FALSE(test_item_2->detailed_view()); |
| 143 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); | 162 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); |
| 144 } | 163 } |
| 145 | 164 |
| 165 // Tests that HoverHighlightView enters hover state in response to touch. | |
| 166 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { | |
| 167 SystemTray* tray = GetSystemTray(); | |
| 168 TestItem* test_item = new TestItem; | |
| 169 tray->AddTrayItem(test_item); | |
| 170 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 171 RunAllPendingInMessageLoop(); | |
| 172 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | |
| 173 RunAllPendingInMessageLoop(); | |
| 174 | |
| 175 HoverHighlightView* view = static_cast<HoverHighlightView*>(test_item-> | |
| 176 detailed_view()->footer()->content()); | |
| 177 EXPECT_FALSE(view->hover()); | |
| 178 | |
| 179 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 180 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | |
| 181 generator.PressTouch(); | |
| 182 RunAllPendingInMessageLoop(); | |
| 183 EXPECT_TRUE(view->hover()); | |
| 184 | |
| 185 generator.ReleaseTouch(); | |
| 186 RunAllPendingInMessageLoop(); | |
| 187 EXPECT_FALSE(view->hover()); | |
| 188 } | |
| 189 | |
| 190 // Tests that touch events leaving HoverHighlightView cancel the hover state. | |
| 191 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) { | |
| 192 SystemTray* tray = GetSystemTray(); | |
| 193 TestItem* test_item = new TestItem; | |
| 194 tray->AddTrayItem(test_item); | |
| 195 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 196 RunAllPendingInMessageLoop(); | |
| 197 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | |
| 198 RunAllPendingInMessageLoop(); | |
| 199 | |
| 200 HoverHighlightView* view = static_cast<HoverHighlightView*>(test_item-> | |
| 201 detailed_view()->footer()->content()); | |
|
Mr4D (OOO till 08-26)
2014/10/07 22:51:45
indent
jonross
2014/10/08 14:18:00
Done.
| |
| 202 EXPECT_FALSE(view->hover()); | |
|
Mr4D (OOO till 08-26)
2014/10/07 22:51:45
Nit: The first part of these two tests appear to b
jonross
2014/10/08 14:18:00
Done.
| |
| 203 | |
| 204 gfx::Rect view_bounds = view->GetBoundsInScreen(); | |
| 205 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 206 generator.set_current_location(view_bounds.CenterPoint()); | |
| 207 generator.PressTouch(); | |
| 208 RunAllPendingInMessageLoop(); | |
| 209 EXPECT_TRUE(view->hover()); | |
| 210 | |
| 211 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | |
| 212 generator.MoveTouch(move_point); | |
| 213 RunAllPendingInMessageLoop(); | |
| 214 EXPECT_FALSE(view->hover()); | |
| 215 | |
| 216 generator.set_current_location(move_point); | |
| 217 generator.ReleaseTouch(); | |
| 218 RunAllPendingInMessageLoop(); | |
| 219 EXPECT_FALSE(view->hover()); | |
| 220 } | |
| 221 | |
| 146 } // namespace test | 222 } // namespace test |
| 147 } // namespace ash | 223 } // namespace ash |
| OLD | NEW |