Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: ash/common/system/tray/tray_details_view_unittest.cc

Issue 2300423002: Reland of Make TrayDetailsView a ViewClickListener and ButtonListener (Closed)
Patch Set: for review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/system/tray/tray_details_view.h" 5 #include "ash/common/system/tray/tray_details_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
7 #include "ash/common/system/tray/hover_highlight_view.h" 8 #include "ash/common/system/tray/hover_highlight_view.h"
8 #include "ash/common/system/tray/special_popup_row.h" 9 #include "ash/common/system/tray/special_popup_row.h"
9 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
10 #include "ash/common/system/tray/system_tray_item.h" 11 #include "ash/common/system/tray/system_tray_item.h"
11 #include "ash/common/system/tray/tray_popup_header_button.h" 12 #include "ash/common/system/tray/tray_popup_header_button.h"
12 #include "ash/common/system/tray/view_click_listener.h" 13 #include "ash/common/system/tray/view_click_listener.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
17 #include "ui/events/test/event_generator.h" 18 #include "ui/events/test/event_generator.h"
18 #include "ui/views/controls/button/button.h" 19 #include "ui/views/controls/button/button.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
21 22
22 namespace ash { 23 namespace ash {
23 namespace test { 24 namespace test {
24 25
25 namespace { 26 namespace {
26 27
27 class TestDetailsView : public TrayDetailsView, 28 class TestDetailsView : public TrayDetailsView {
28 public ViewClickListener,
29 public views::ButtonListener {
30 public: 29 public:
31 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { 30 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) {
32 // Uses bluetooth label for testing purpose. It can be changed to any 31 // Uses bluetooth label for testing purpose. It can be changed to any
33 // string_id. 32 // string_id.
34 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); 33 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
35 tray_popup_header_button_ =
36 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
37 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
38 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
39 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
40 IDS_ASH_STATUS_TRAY_BLUETOOTH);
41 footer()->AddButton(tray_popup_header_button_);
42 } 34 }
43 35
44 ~TestDetailsView() override {} 36 ~TestDetailsView() override {}
45 37
46 TrayPopupHeaderButton* tray_popup_header_button() { 38 TrayPopupHeaderButton* tray_popup_header_button() {
47 return tray_popup_header_button_; 39 return tray_popup_header_button_;
48 } 40 }
49 41
50 void FocusFooter() { footer()->content()->RequestFocus(); } 42 void FocusTitleRow() { title_row()->content()->RequestFocus(); }
51 43
52 // ViewClickListener: 44 // TrayDetailsView:
53 void OnViewClicked(views::View* sender) override {} 45 void CreateExtraTitleRowButtons() override {
46 // TODO(tdanderson): Add test coverage for material design buttons in the
47 // title row once they are implemented.
48 if (MaterialDesignController::IsSystemTrayMenuMaterial())
49 return;
54 50
55 // views::ButtonListener: 51 tray_popup_header_button_ =
56 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} 52 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
53 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
54 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
55 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
56 IDS_ASH_STATUS_TRAY_BLUETOOTH);
57 title_row()->AddButton(tray_popup_header_button_);
58 }
57 59
58 private: 60 private:
59 TrayPopupHeaderButton* tray_popup_header_button_; 61 TrayPopupHeaderButton* tray_popup_header_button_;
60 62
61 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); 63 DISALLOW_COPY_AND_ASSIGN(TestDetailsView);
62 }; 64 };
63 65
64 // Trivial item implementation that tracks its views for testing. 66 // Trivial item implementation that tracks its views for testing.
65 class TestItem : public SystemTrayItem { 67 class TestItem : public SystemTrayItem {
66 public: 68 public:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 HoverHighlightView* CreateAndShowHoverHighlightView() { 112 HoverHighlightView* CreateAndShowHoverHighlightView() {
111 SystemTray* tray = GetPrimarySystemTray(); 113 SystemTray* tray = GetPrimarySystemTray();
112 TestItem* test_item = new TestItem; 114 TestItem* test_item = new TestItem;
113 tray->AddTrayItem(test_item); 115 tray->AddTrayItem(test_item);
114 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 116 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
115 RunAllPendingInMessageLoop(); 117 RunAllPendingInMessageLoop();
116 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); 118 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING);
117 RunAllPendingInMessageLoop(); 119 RunAllPendingInMessageLoop();
118 120
119 return static_cast<HoverHighlightView*>( 121 return static_cast<HoverHighlightView*>(
120 test_item->detailed_view()->footer()->content()); 122 test_item->detailed_view()->title_row()->content());
121 } 123 }
122 124
123 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { 125 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() {
124 SystemTray* tray = GetPrimarySystemTray(); 126 SystemTray* tray = GetPrimarySystemTray();
125 TestItem* test_item = new TestItem; 127 TestItem* test_item = new TestItem;
126 tray->AddTrayItem(test_item); 128 tray->AddTrayItem(test_item);
127 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 129 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
128 RunAllPendingInMessageLoop(); 130 RunAllPendingInMessageLoop();
129 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); 131 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING);
130 RunAllPendingInMessageLoop(); 132 RunAllPendingInMessageLoop();
131 133
132 return test_item->detailed_view()->tray_popup_header_button(); 134 return test_item->detailed_view()->tray_popup_header_button();
133 } 135 }
134 136
137 void TransitionFromDetailedToDefaultView(TestDetailsView* detailed) {
138 detailed->TransitionToDefaultView();
139 }
140
135 private: 141 private:
136 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); 142 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest);
137 }; 143 };
138 144
139 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { 145 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) {
140 SystemTray* tray = GetPrimarySystemTray(); 146 SystemTray* tray = GetPrimarySystemTray();
141 ASSERT_TRUE(tray->GetWidget()); 147 ASSERT_TRUE(tray->GetWidget());
142 148
143 TestItem* test_item_1 = new TestItem; 149 TestItem* test_item_1 = new TestItem;
144 TestItem* test_item_2 = new TestItem; 150 TestItem* test_item_2 = new TestItem;
145 tray->AddTrayItem(test_item_1); 151 tray->AddTrayItem(test_item_1);
146 tray->AddTrayItem(test_item_2); 152 tray->AddTrayItem(test_item_2);
147 153
148 // Ensure the tray views are created. 154 // Ensure the tray views are created.
149 ASSERT_TRUE(test_item_1->tray_view() != NULL); 155 ASSERT_TRUE(test_item_1->tray_view() != NULL);
150 ASSERT_TRUE(test_item_2->tray_view() != NULL); 156 ASSERT_TRUE(test_item_2->tray_view() != NULL);
151 157
152 // Show the default view. 158 // Show the default view.
153 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 159 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
154 RunAllPendingInMessageLoop(); 160 RunAllPendingInMessageLoop();
155 161
156 // Show the detailed view of item 2. 162 // Show the detailed view of item 2.
157 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); 163 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
158 EXPECT_TRUE(test_item_2->detailed_view()); 164 EXPECT_TRUE(test_item_2->detailed_view());
159 RunAllPendingInMessageLoop(); 165 RunAllPendingInMessageLoop();
160 EXPECT_FALSE(test_item_2->default_view()); 166 EXPECT_FALSE(test_item_2->default_view());
161 167
162 // Transition back to default view, the default view of item 2 should have 168 // Transition back to default view, the default view of item 2 should have
163 // focus. 169 // focus.
164 test_item_2->detailed_view()->FocusFooter(); 170 test_item_2->detailed_view()->FocusTitleRow();
165 test_item_2->detailed_view()->TransitionToDefaultView(); 171 TransitionFromDetailedToDefaultView(test_item_2->detailed_view());
166 RunAllPendingInMessageLoop(); 172 RunAllPendingInMessageLoop();
167 173
168 EXPECT_TRUE(test_item_2->default_view()); 174 EXPECT_TRUE(test_item_2->default_view());
169 EXPECT_FALSE(test_item_2->detailed_view()); 175 EXPECT_FALSE(test_item_2->detailed_view());
170 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); 176 EXPECT_TRUE(test_item_2->default_view()->HasFocus());
171 177
172 // Show the detailed view of item 2 again. 178 // Show the detailed view of item 2 again.
173 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); 179 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
174 EXPECT_TRUE(test_item_2->detailed_view()); 180 EXPECT_TRUE(test_item_2->detailed_view());
175 RunAllPendingInMessageLoop(); 181 RunAllPendingInMessageLoop();
176 EXPECT_FALSE(test_item_2->default_view()); 182 EXPECT_FALSE(test_item_2->default_view());
177 183
178 // Transition back to default view, the default view of item 2 should NOT have 184 // Transition back to default view, the default view of item 2 should NOT have
179 // focus. 185 // focus.
180 test_item_2->detailed_view()->TransitionToDefaultView(); 186 TransitionFromDetailedToDefaultView(test_item_2->detailed_view());
181 RunAllPendingInMessageLoop(); 187 RunAllPendingInMessageLoop();
182 188
183 EXPECT_TRUE(test_item_2->default_view()); 189 EXPECT_TRUE(test_item_2->default_view());
184 EXPECT_FALSE(test_item_2->detailed_view()); 190 EXPECT_FALSE(test_item_2->detailed_view());
185 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); 191 EXPECT_FALSE(test_item_2->default_view()->HasFocus());
186 } 192 }
187 193
188 // Tests that HoverHighlightView enters hover state in response to touch. 194 // Tests that HoverHighlightView enters hover state in response to touch.
189 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { 195 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) {
190 HoverHighlightView* view = CreateAndShowHoverHighlightView(); 196 HoverHighlightView* view = CreateAndShowHoverHighlightView();
191 EXPECT_FALSE(view->hover()); 197 EXPECT_FALSE(view->hover());
192 198
193 ui::test::EventGenerator& generator = GetEventGenerator(); 199 ui::test::EventGenerator& generator = GetEventGenerator();
194 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); 200 generator.set_current_location(view->GetBoundsInScreen().CenterPoint());
195 generator.PressTouch(); 201 generator.PressTouch();
196 EXPECT_TRUE(view->hover()); 202 EXPECT_TRUE(view->hover());
197 203
198 generator.ReleaseTouch(); 204 generator.ReleaseTouch();
199 EXPECT_FALSE(view->hover());
tdanderson 2016/09/02 15:47:00 This is the only change from Patch Set 5 in https:
200 } 205 }
201 206
202 // Tests that touch events leaving HoverHighlightView cancel the hover state. 207 // Tests that touch events leaving HoverHighlightView cancel the hover state.
203 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) { 208 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) {
204 HoverHighlightView* view = CreateAndShowHoverHighlightView(); 209 HoverHighlightView* view = CreateAndShowHoverHighlightView();
205 EXPECT_FALSE(view->hover()); 210 EXPECT_FALSE(view->hover());
206 211
207 gfx::Rect view_bounds = view->GetBoundsInScreen(); 212 gfx::Rect view_bounds = view->GetBoundsInScreen();
208 ui::test::EventGenerator& generator = GetEventGenerator(); 213 ui::test::EventGenerator& generator = GetEventGenerator();
209 generator.set_current_location(view_bounds.CenterPoint()); 214 generator.set_current_location(view_bounds.CenterPoint());
210 generator.PressTouch(); 215 generator.PressTouch();
211 EXPECT_TRUE(view->hover()); 216 EXPECT_TRUE(view->hover());
212 217
213 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); 218 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
214 generator.MoveTouch(move_point); 219 generator.MoveTouch(move_point);
215 EXPECT_FALSE(view->hover()); 220 EXPECT_FALSE(view->hover());
216 221
217 generator.set_current_location(move_point); 222 generator.set_current_location(move_point);
218 generator.ReleaseTouch(); 223 generator.ReleaseTouch();
219 EXPECT_FALSE(view->hover()); 224 EXPECT_FALSE(view->hover());
220 } 225 }
221 226
222 // Tests that TrayPopupHeaderButton renders a background in response to touch. 227 // Tests that TrayPopupHeaderButton renders a background in response to touch.
223 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { 228 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) {
229 // Material design detailed views will not use TrayPopupHeaderButton.
230 if (MaterialDesignController::IsSystemTrayMenuMaterial())
231 return;
232
224 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); 233 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
225 EXPECT_FALSE(button->background()); 234 EXPECT_FALSE(button->background());
226 235
227 ui::test::EventGenerator& generator = GetEventGenerator(); 236 ui::test::EventGenerator& generator = GetEventGenerator();
228 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); 237 generator.set_current_location(button->GetBoundsInScreen().CenterPoint());
229 generator.PressTouch(); 238 generator.PressTouch();
230 EXPECT_TRUE(button->background()); 239 EXPECT_TRUE(button->background());
231 240
232 generator.ReleaseTouch(); 241 generator.ReleaseTouch();
233 EXPECT_FALSE(button->background()); 242 EXPECT_FALSE(button->background());
234 } 243 }
235 244
236 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch 245 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch
237 // feedback background. 246 // feedback background.
238 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { 247 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) {
248 // Material design detailed views will not use TrayPopupHeaderButton.
249 if (MaterialDesignController::IsSystemTrayMenuMaterial())
250 return;
251
239 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); 252 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
240 EXPECT_FALSE(button->background()); 253 EXPECT_FALSE(button->background());
241 254
242 gfx::Rect view_bounds = button->GetBoundsInScreen(); 255 gfx::Rect view_bounds = button->GetBoundsInScreen();
243 ui::test::EventGenerator& generator = GetEventGenerator(); 256 ui::test::EventGenerator& generator = GetEventGenerator();
244 generator.set_current_location(view_bounds.CenterPoint()); 257 generator.set_current_location(view_bounds.CenterPoint());
245 generator.PressTouch(); 258 generator.PressTouch();
246 EXPECT_TRUE(button->background()); 259 EXPECT_TRUE(button->background());
247 260
248 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); 261 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
249 generator.MoveTouch(move_point); 262 generator.MoveTouch(move_point);
250 EXPECT_FALSE(button->background()); 263 EXPECT_FALSE(button->background());
251 264
252 generator.set_current_location(move_point); 265 generator.set_current_location(move_point);
253 generator.ReleaseTouch(); 266 generator.ReleaseTouch();
254 EXPECT_FALSE(button->background()); 267 EXPECT_FALSE(button->background());
255 } 268 }
256 269
257 // Tests that a mouse entering TrayPopupHeaderButton renders a background as 270 // Tests that a mouse entering TrayPopupHeaderButton renders a background as
258 // visual feedback. 271 // visual feedback.
259 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { 272 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) {
273 // Material design detailed views will not use TrayPopupHeaderButton.
274 if (MaterialDesignController::IsSystemTrayMenuMaterial())
275 return;
276
260 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); 277 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
261 EXPECT_FALSE(button->background()); 278 EXPECT_FALSE(button->background());
262 279
263 ui::test::EventGenerator& generator = GetEventGenerator(); 280 ui::test::EventGenerator& generator = GetEventGenerator();
264 gfx::Rect bounds = button->GetBoundsInScreen(); 281 gfx::Rect bounds = button->GetBoundsInScreen();
265 gfx::Point initial_point(bounds.x() - 1, bounds.y()); 282 gfx::Point initial_point(bounds.x() - 1, bounds.y());
266 generator.set_current_location(initial_point); 283 generator.set_current_location(initial_point);
267 generator.MoveMouseBy(1, 0); 284 generator.MoveMouseBy(1, 0);
268 RunAllPendingInMessageLoop(); 285 RunAllPendingInMessageLoop();
269 EXPECT_TRUE(button->background()); 286 EXPECT_TRUE(button->background());
270 } 287 }
271 288
272 } // namespace test 289 } // namespace test
273 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_details_view.cc ('k') | ash/common/system/tray/view_click_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698