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

Side by Side Diff: ash/system/tray/system_tray_unittest.cc

Issue 2072023003: mash: Break ash system tray dependencies on ash::ShelfWidget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/system/tray/system_tray_item.h" 10 #include "ash/common/system/tray/system_tray_item.h"
11 #include "ash/common/system/tray/tray_constants.h" 11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_popup_item_container.h" 12 #include "ash/common/system/tray/tray_popup_item_container.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/shelf/shelf.h" 14 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_widget.h"
16 #include "ash/shell.h" 15 #include "ash/shell.h"
17 #include "ash/system/status_area_widget.h" 16 #include "ash/system/status_area_widget.h"
18 #include "ash/system/tray/system_tray_bubble.h" 17 #include "ash/system/tray/system_tray_bubble.h"
19 #include "ash/system/web_notification/web_notification_tray.h" 18 #include "ash/system/web_notification/web_notification_tray.h"
20 #include "ash/test/ash_test_base.h" 19 #include "ash/test/ash_test_base.h"
20 #include "ash/test/status_area_widget_test_helper.h"
21 #include "ash/wm/window_util.h" 21 #include "ash/wm/window_util.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
27 #include "ui/events/test/event_generator.h" 27 #include "ui/events/test/event_generator.h"
28 #include "ui/gfx/geometry/point.h" 28 #include "ui/gfx/geometry/point.h"
29 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/views/controls/label.h" 30 #include "ui/views/controls/label.h"
31 #include "ui/views/layout/fill_layout.h" 31 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/view.h" 32 #include "ui/views/view.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 #include "ui/views/widget/widget_delegate.h" 34 #include "ui/views/widget/widget_delegate.h"
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 #include "base/win/windows_version.h" 37 #include "base/win/windows_version.h"
38 #endif 38 #endif
39 39
40 namespace ash { 40 namespace ash {
41 namespace test { 41 namespace test {
42 42
43 namespace { 43 namespace {
44 44
45 SystemTray* GetSystemTray() {
46 return Shell::GetPrimaryRootWindowController()
47 ->shelf_widget()
48 ->status_area_widget()
49 ->system_tray();
50 }
51
52 // Trivial item implementation that tracks its views for testing. 45 // Trivial item implementation that tracks its views for testing.
53 class TestItem : public SystemTrayItem { 46 class TestItem : public SystemTrayItem {
54 public: 47 public:
55 TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} 48 TestItem()
49 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()),
50 tray_view_(nullptr),
51 default_view_(nullptr),
52 detailed_view_(nullptr),
53 notification_view_(nullptr) {}
56 54
57 views::View* CreateTrayView(LoginStatus status) override { 55 views::View* CreateTrayView(LoginStatus status) override {
58 tray_view_ = new views::View; 56 tray_view_ = new views::View;
59 // Add a label so it has non-zero width. 57 // Add a label so it has non-zero width.
60 tray_view_->SetLayoutManager(new views::FillLayout); 58 tray_view_->SetLayoutManager(new views::FillLayout);
61 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray"))); 59 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray")));
62 return tray_view_; 60 return tray_view_;
63 } 61 }
64 62
65 views::View* CreateDefaultView(LoginStatus status) override { 63 views::View* CreateDefaultView(LoginStatus status) override {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 views::View* tray_view_; 99 views::View* tray_view_;
102 views::View* default_view_; 100 views::View* default_view_;
103 views::View* detailed_view_; 101 views::View* detailed_view_;
104 views::View* notification_view_; 102 views::View* notification_view_;
105 }; 103 };
106 104
107 // Trivial item implementation that returns NULL from tray/default/detailed 105 // Trivial item implementation that returns NULL from tray/default/detailed
108 // view creation methods. 106 // view creation methods.
109 class TestNoViewItem : public SystemTrayItem { 107 class TestNoViewItem : public SystemTrayItem {
110 public: 108 public:
111 TestNoViewItem() : SystemTrayItem(GetSystemTray()) {} 109 TestNoViewItem() : SystemTrayItem(AshTestBase::GetPrimarySystemTray()) {}
112 110
113 views::View* CreateTrayView(LoginStatus status) override { return nullptr; } 111 views::View* CreateTrayView(LoginStatus status) override { return nullptr; }
114 112
115 views::View* CreateDefaultView(LoginStatus status) override { 113 views::View* CreateDefaultView(LoginStatus status) override {
116 return nullptr; 114 return nullptr;
117 } 115 }
118 116
119 views::View* CreateDetailedView(LoginStatus status) override { 117 views::View* CreateDetailedView(LoginStatus status) override {
120 return nullptr; 118 return nullptr;
121 } 119 }
(...skipping 19 matching lines...) Expand all
141 139
142 private: 140 private:
143 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); 141 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
144 }; 142 };
145 143
146 } // namespace 144 } // namespace
147 145
148 typedef AshTestBase SystemTrayTest; 146 typedef AshTestBase SystemTrayTest;
149 147
150 TEST_F(SystemTrayTest, SystemTrayDefaultView) { 148 TEST_F(SystemTrayTest, SystemTrayDefaultView) {
151 SystemTray* tray = GetSystemTray(); 149 SystemTray* tray = GetPrimarySystemTray();
152 ASSERT_TRUE(tray->GetWidget()); 150 ASSERT_TRUE(tray->GetWidget());
153 151
154 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 152 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
155 153
156 // Ensure that closing the bubble destroys it. 154 // Ensure that closing the bubble destroys it.
157 ASSERT_TRUE(tray->CloseSystemBubble()); 155 ASSERT_TRUE(tray->CloseSystemBubble());
158 RunAllPendingInMessageLoop(); 156 RunAllPendingInMessageLoop();
159 ASSERT_FALSE(tray->CloseSystemBubble()); 157 ASSERT_FALSE(tray->CloseSystemBubble());
160 } 158 }
161 159
162 // Opening and closing the bubble should change the coloring of the tray. 160 // Opening and closing the bubble should change the coloring of the tray.
163 TEST_F(SystemTrayTest, SystemTrayColoring) { 161 TEST_F(SystemTrayTest, SystemTrayColoring) {
164 SystemTray* tray = GetSystemTray(); 162 SystemTray* tray = GetPrimarySystemTray();
165 ASSERT_TRUE(tray->GetWidget()); 163 ASSERT_TRUE(tray->GetWidget());
166 // At the beginning the tray coloring is not active. 164 // At the beginning the tray coloring is not active.
167 ASSERT_FALSE(tray->draw_background_as_active()); 165 ASSERT_FALSE(tray->draw_background_as_active());
168 166
169 // Showing the system bubble should show the background as active. 167 // Showing the system bubble should show the background as active.
170 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 168 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
171 ASSERT_TRUE(tray->draw_background_as_active()); 169 ASSERT_TRUE(tray->draw_background_as_active());
172 170
173 // Closing the system menu should change the coloring back to normal. 171 // Closing the system menu should change the coloring back to normal.
174 ASSERT_TRUE(tray->CloseSystemBubble()); 172 ASSERT_TRUE(tray->CloseSystemBubble());
175 RunAllPendingInMessageLoop(); 173 RunAllPendingInMessageLoop();
176 ASSERT_FALSE(tray->draw_background_as_active()); 174 ASSERT_FALSE(tray->draw_background_as_active());
177 } 175 }
178 176
179 // Closing the system bubble through an alignment change should change the 177 // Closing the system bubble through an alignment change should change the
180 // system tray coloring back to normal. 178 // system tray coloring back to normal.
181 TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) { 179 TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) {
182 SystemTray* tray = GetSystemTray(); 180 SystemTray* tray = GetPrimarySystemTray();
183 ASSERT_TRUE(tray->GetWidget()); 181 ASSERT_TRUE(tray->GetWidget());
184 Shelf* shelf = Shelf::ForPrimaryDisplay(); 182 Shelf* shelf = Shelf::ForPrimaryDisplay();
185 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 183 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
186 // At the beginning the tray coloring is not active. 184 // At the beginning the tray coloring is not active.
187 ASSERT_FALSE(tray->draw_background_as_active()); 185 ASSERT_FALSE(tray->draw_background_as_active());
188 186
189 // Showing the system bubble should show the background as active. 187 // Showing the system bubble should show the background as active.
190 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 188 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
191 ASSERT_TRUE(tray->draw_background_as_active()); 189 ASSERT_TRUE(tray->draw_background_as_active());
192 190
193 // Changing the alignment should close the system bubble and change the 191 // Changing the alignment should close the system bubble and change the
194 // background color. 192 // background color.
195 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 193 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
196 ASSERT_FALSE(tray->draw_background_as_active()); 194 ASSERT_FALSE(tray->draw_background_as_active());
197 RunAllPendingInMessageLoop(); 195 RunAllPendingInMessageLoop();
198 // The bubble should already be closed by now. 196 // The bubble should already be closed by now.
199 ASSERT_FALSE(tray->CloseSystemBubble()); 197 ASSERT_FALSE(tray->CloseSystemBubble());
200 } 198 }
201 199
202 TEST_F(SystemTrayTest, SystemTrayTestItems) { 200 TEST_F(SystemTrayTest, SystemTrayTestItems) {
203 SystemTray* tray = GetSystemTray(); 201 SystemTray* tray = GetPrimarySystemTray();
204 ASSERT_TRUE(tray->GetWidget()); 202 ASSERT_TRUE(tray->GetWidget());
205 203
206 TestItem* test_item = new TestItem; 204 TestItem* test_item = new TestItem;
207 TestItem* detailed_item = new TestItem; 205 TestItem* detailed_item = new TestItem;
208 tray->AddTrayItem(test_item); 206 tray->AddTrayItem(test_item);
209 tray->AddTrayItem(detailed_item); 207 tray->AddTrayItem(detailed_item);
210 208
211 // Check items have been added 209 // Check items have been added
212 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); 210 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems();
213 ASSERT_TRUE( 211 ASSERT_TRUE(
(...skipping 17 matching lines...) Expand all
231 ASSERT_TRUE(detailed_item->detailed_view() != NULL); 229 ASSERT_TRUE(detailed_item->detailed_view() != NULL);
232 230
233 // Show the default view, ensure it's created and the detailed view destroyed. 231 // Show the default view, ensure it's created and the detailed view destroyed.
234 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 232 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
235 RunAllPendingInMessageLoop(); 233 RunAllPendingInMessageLoop();
236 ASSERT_TRUE(test_item->default_view() != NULL); 234 ASSERT_TRUE(test_item->default_view() != NULL);
237 ASSERT_TRUE(detailed_item->detailed_view() == NULL); 235 ASSERT_TRUE(detailed_item->detailed_view() == NULL);
238 } 236 }
239 237
240 TEST_F(SystemTrayTest, SystemTrayNoViewItems) { 238 TEST_F(SystemTrayTest, SystemTrayNoViewItems) {
241 SystemTray* tray = GetSystemTray(); 239 SystemTray* tray = GetPrimarySystemTray();
242 ASSERT_TRUE(tray->GetWidget()); 240 ASSERT_TRUE(tray->GetWidget());
243 241
244 // Verify that no crashes occur on items lacking some views. 242 // Verify that no crashes occur on items lacking some views.
245 TestNoViewItem* no_view_item = new TestNoViewItem; 243 TestNoViewItem* no_view_item = new TestNoViewItem;
246 tray->AddTrayItem(no_view_item); 244 tray->AddTrayItem(no_view_item);
247 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 245 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
248 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING); 246 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING);
249 RunAllPendingInMessageLoop(); 247 RunAllPendingInMessageLoop();
250 } 248 }
251 249
252 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { 250 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) {
253 SystemTray* tray = GetSystemTray(); 251 SystemTray* tray = GetPrimarySystemTray();
254 ASSERT_TRUE(tray->GetWidget()); 252 ASSERT_TRUE(tray->GetWidget());
255 253
256 // Add an initial tray item so that the tray gets laid out correctly. 254 // Add an initial tray item so that the tray gets laid out correctly.
257 TestItem* initial_item = new TestItem; 255 TestItem* initial_item = new TestItem;
258 tray->AddTrayItem(initial_item); 256 tray->AddTrayItem(initial_item);
259 257
260 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); 258 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size();
261 259
262 TestItem* new_item = new TestItem; 260 TestItem* new_item = new TestItem;
263 tray->AddTrayItem(new_item); 261 tray->AddTrayItem(new_item);
264 262
265 gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); 263 gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size();
266 264
267 // Adding the new item should change the size of the tray. 265 // Adding the new item should change the size of the tray.
268 EXPECT_NE(initial_size.ToString(), new_size.ToString()); 266 EXPECT_NE(initial_size.ToString(), new_size.ToString());
269 267
270 // Hiding the tray view of the new item should also change the size of the 268 // Hiding the tray view of the new item should also change the size of the
271 // tray. 269 // tray.
272 new_item->tray_view()->SetVisible(false); 270 new_item->tray_view()->SetVisible(false);
273 EXPECT_EQ(initial_size.ToString(), 271 EXPECT_EQ(initial_size.ToString(),
274 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 272 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString());
275 273
276 new_item->tray_view()->SetVisible(true); 274 new_item->tray_view()->SetVisible(true);
277 EXPECT_EQ(new_size.ToString(), 275 EXPECT_EQ(new_size.ToString(),
278 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 276 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString());
279 } 277 }
280 278
281 TEST_F(SystemTrayTest, SystemTrayNotifications) { 279 TEST_F(SystemTrayTest, SystemTrayNotifications) {
282 SystemTray* tray = GetSystemTray(); 280 SystemTray* tray = GetPrimarySystemTray();
283 ASSERT_TRUE(tray->GetWidget()); 281 ASSERT_TRUE(tray->GetWidget());
284 282
285 TestItem* test_item = new TestItem; 283 TestItem* test_item = new TestItem;
286 TestItem* detailed_item = new TestItem; 284 TestItem* detailed_item = new TestItem;
287 tray->AddTrayItem(test_item); 285 tray->AddTrayItem(test_item);
288 tray->AddTrayItem(detailed_item); 286 tray->AddTrayItem(detailed_item);
289 287
290 // Ensure the tray views are created. 288 // Ensure the tray views are created.
291 ASSERT_TRUE(test_item->tray_view() != NULL); 289 ASSERT_TRUE(test_item->tray_view() != NULL);
292 ASSERT_TRUE(detailed_item->tray_view() != NULL); 290 ASSERT_TRUE(detailed_item->tray_view() != NULL);
(...skipping 14 matching lines...) Expand all
307 ASSERT_TRUE(test_item->notification_view() != NULL); 305 ASSERT_TRUE(test_item->notification_view() != NULL);
308 306
309 // Hide the detailed view, ensure the notification view still exists. 307 // Hide the detailed view, ensure the notification view still exists.
310 ASSERT_TRUE(tray->CloseSystemBubble()); 308 ASSERT_TRUE(tray->CloseSystemBubble());
311 RunAllPendingInMessageLoop(); 309 RunAllPendingInMessageLoop();
312 ASSERT_TRUE(detailed_item->detailed_view() == NULL); 310 ASSERT_TRUE(detailed_item->detailed_view() == NULL);
313 ASSERT_TRUE(test_item->notification_view() != NULL); 311 ASSERT_TRUE(test_item->notification_view() != NULL);
314 } 312 }
315 313
316 TEST_F(SystemTrayTest, BubbleCreationTypesTest) { 314 TEST_F(SystemTrayTest, BubbleCreationTypesTest) {
317 SystemTray* tray = GetSystemTray(); 315 SystemTray* tray = GetPrimarySystemTray();
318 ASSERT_TRUE(tray->GetWidget()); 316 ASSERT_TRUE(tray->GetWidget());
319 317
320 TestItem* test_item = new TestItem; 318 TestItem* test_item = new TestItem;
321 tray->AddTrayItem(test_item); 319 tray->AddTrayItem(test_item);
322 320
323 // Ensure the tray views are created. 321 // Ensure the tray views are created.
324 ASSERT_TRUE(test_item->tray_view() != NULL); 322 ASSERT_TRUE(test_item->tray_view() != NULL);
325 323
326 // Show the default view, ensure the notification view is destroyed. 324 // Show the default view, ensure the notification view is destroyed.
327 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 325 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
(...skipping 16 matching lines...) Expand all
344 342
345 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> 343 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()->
346 GetWindowBoundsInScreen().ToString()); 344 GetWindowBoundsInScreen().ToString());
347 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); 345 EXPECT_EQ(widget, test_item->default_view()->GetWidget());
348 } 346 }
349 347
350 // Tests that the tray is laid out properly and is fully contained within 348 // Tests that the tray is laid out properly and is fully contained within
351 // the shelf. 349 // the shelf.
352 TEST_F(SystemTrayTest, TrayBoundsInWidget) { 350 TEST_F(SystemTrayTest, TrayBoundsInWidget) {
353 Shelf* shelf = Shelf::ForPrimaryDisplay(); 351 Shelf* shelf = Shelf::ForPrimaryDisplay();
354 StatusAreaWidget* widget = Shell::GetPrimaryRootWindowController() 352 StatusAreaWidget* widget = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
msw 2016/06/17 19:58:37 aside: This test is confusing... partly because of
James Cook 2016/06/17 20:14:32 Converted to Rect::Contains() and clarified the te
355 ->shelf_widget() 353 SystemTray* tray = GetPrimarySystemTray();
356 ->status_area_widget();
357 SystemTray* tray = widget->system_tray();
358 354
359 // Test in bottom alignment. 355 // Test in bottom alignment.
360 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 356 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
361 gfx::Rect window_bounds = widget->GetWindowBoundsInScreen(); 357 gfx::Rect window_bounds = widget->GetWindowBoundsInScreen();
362 gfx::Rect tray_bounds = tray->GetBoundsInScreen(); 358 gfx::Rect tray_bounds = tray->GetBoundsInScreen();
363 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 359 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom());
364 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right()); 360 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
365 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x()); 361 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
366 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y()); 362 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
367 363
(...skipping 19 matching lines...) Expand all
387 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 383 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
388 window_bounds = widget->GetWindowBoundsInScreen(); 384 window_bounds = widget->GetWindowBoundsInScreen();
389 tray_bounds = tray->GetBoundsInScreen(); 385 tray_bounds = tray->GetBoundsInScreen();
390 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 386 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom());
391 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right()); 387 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
392 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x()); 388 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
393 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y()); 389 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
394 } 390 }
395 391
396 TEST_F(SystemTrayTest, PersistentBubble) { 392 TEST_F(SystemTrayTest, PersistentBubble) {
397 SystemTray* tray = GetSystemTray(); 393 SystemTray* tray = GetPrimarySystemTray();
398 ASSERT_TRUE(tray->GetWidget()); 394 ASSERT_TRUE(tray->GetWidget());
399 395
400 TestItem* test_item = new TestItem; 396 TestItem* test_item = new TestItem;
401 tray->AddTrayItem(test_item); 397 tray->AddTrayItem(test_item);
402 398
403 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 399 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
404 400
405 // Tests for usual default view. 401 // Tests for usual default view.
406 // Activating window. 402 // Activating window.
407 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 403 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Check if the accessibility item is created even with system modal 440 // Check if the accessibility item is created even with system modal
445 // dialog. 441 // dialog.
446 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( 442 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled(
447 true); 443 true);
448 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 444 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
449 new ModalWidgetDelegate(), 445 new ModalWidgetDelegate(),
450 Shell::GetPrimaryRootWindow(), 446 Shell::GetPrimaryRootWindow(),
451 gfx::Rect(0, 0, 100, 100)); 447 gfx::Rect(0, 0, 100, 100));
452 widget->Show(); 448 widget->Show();
453 449
454 SystemTray* tray = GetSystemTray(); 450 SystemTray* tray = GetPrimarySystemTray();
455 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 451 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
456 452
457 ASSERT_TRUE(tray->HasSystemBubble()); 453 ASSERT_TRUE(tray->HasSystemBubble());
458 const views::View* accessibility = 454 const views::View* accessibility =
459 tray->GetSystemBubble()->bubble_view()->GetViewByID( 455 tray->GetSystemBubble()->bubble_view()->GetViewByID(
460 test::kAccessibilityTrayItemViewId); 456 test::kAccessibilityTrayItemViewId);
461 ASSERT_TRUE(accessibility); 457 ASSERT_TRUE(accessibility);
462 EXPECT_TRUE(accessibility->visible()); 458 EXPECT_TRUE(accessibility->visible());
463 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID( 459 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID(
464 test::kSettingsTrayItemViewId)); 460 test::kSettingsTrayItemViewId));
(...skipping 11 matching lines...) Expand all
476 const views::View* settings = 472 const views::View* settings =
477 tray->GetSystemBubble()->bubble_view()->GetViewByID( 473 tray->GetSystemBubble()->bubble_view()->GetViewByID(
478 test::kSettingsTrayItemViewId); 474 test::kSettingsTrayItemViewId);
479 ASSERT_TRUE(settings); 475 ASSERT_TRUE(settings);
480 EXPECT_TRUE(settings->visible()); 476 EXPECT_TRUE(settings->visible());
481 } 477 }
482 478
483 // Tests that if SetVisible(true) is called while animating to hidden that the 479 // Tests that if SetVisible(true) is called while animating to hidden that the
484 // tray becomes visible, and stops animating to hidden. 480 // tray becomes visible, and stops animating to hidden.
485 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) { 481 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) {
486 SystemTray* tray = GetSystemTray(); 482 SystemTray* tray = GetPrimarySystemTray();
487 ASSERT_TRUE(tray->visible()); 483 ASSERT_TRUE(tray->visible());
488 484
489 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration; 485 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration;
490 animation_duration.reset( 486 animation_duration.reset(
491 new ui::ScopedAnimationDurationScaleMode( 487 new ui::ScopedAnimationDurationScaleMode(
492 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 488 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
493 tray->SetVisible(false); 489 tray->SetVisible(false);
494 EXPECT_TRUE(tray->visible()); 490 EXPECT_TRUE(tray->visible());
495 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity()); 491 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity());
496 492
497 tray->SetVisible(true); 493 tray->SetVisible(true);
498 animation_duration.reset(); 494 animation_duration.reset();
499 tray->layer()->GetAnimator()->StopAnimating(); 495 tray->layer()->GetAnimator()->StopAnimating();
500 EXPECT_TRUE(tray->visible()); 496 EXPECT_TRUE(tray->visible());
501 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity()); 497 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity());
502 } 498 }
503 499
504 #if defined(OS_CHROMEOS) 500 #if defined(OS_CHROMEOS)
505 // Tests that touch on an item in the system bubble triggers it to become 501 // Tests that touch on an item in the system bubble triggers it to become
506 // active. 502 // active.
507 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { 503 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) {
508 SystemTray* tray = GetSystemTray(); 504 SystemTray* tray = GetPrimarySystemTray();
509 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 505 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
510 506
511 TrayPopupItemContainer* view = 507 TrayPopupItemContainer* view =
512 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> 508 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()->
513 bubble_view()->child_at(0)); 509 bubble_view()->child_at(0));
514 EXPECT_FALSE(view->active()); 510 EXPECT_FALSE(view->active());
515 511
516 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 512 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
517 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); 513 generator.set_current_location(view->GetBoundsInScreen().CenterPoint());
518 generator.PressTouch(); 514 generator.PressTouch();
519 EXPECT_TRUE(view->active()); 515 EXPECT_TRUE(view->active());
520 516
521 generator.ReleaseTouch(); 517 generator.ReleaseTouch();
522 EXPECT_FALSE(view->active()); 518 EXPECT_FALSE(view->active());
523 } 519 }
524 520
525 // Tests that touch events on an item in the system bubble cause it to stop 521 // Tests that touch events on an item in the system bubble cause it to stop
526 // being active. 522 // being active.
527 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { 523 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) {
528 SystemTray* tray = GetSystemTray(); 524 SystemTray* tray = GetPrimarySystemTray();
529 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 525 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
530 526
531 TrayPopupItemContainer* view = 527 TrayPopupItemContainer* view =
532 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> 528 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()->
533 bubble_view()->child_at(0)); 529 bubble_view()->child_at(0));
534 EXPECT_FALSE(view->active()); 530 EXPECT_FALSE(view->active());
535 531
536 gfx::Rect view_bounds = view->GetBoundsInScreen(); 532 gfx::Rect view_bounds = view->GetBoundsInScreen();
537 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 533 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
538 generator.set_current_location(view_bounds.CenterPoint()); 534 generator.set_current_location(view_bounds.CenterPoint());
539 generator.PressTouch(); 535 generator.PressTouch();
540 EXPECT_TRUE(view->active()); 536 EXPECT_TRUE(view->active());
541 537
542 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); 538 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
543 generator.MoveTouch(move_point); 539 generator.MoveTouch(move_point);
544 EXPECT_FALSE(view->active()); 540 EXPECT_FALSE(view->active());
545 541
546 generator.set_current_location(move_point); 542 generator.set_current_location(move_point);
547 generator.ReleaseTouch(); 543 generator.ReleaseTouch();
548 EXPECT_FALSE(view->active()); 544 EXPECT_FALSE(view->active());
549 } 545 }
550 546
551 TEST_F(SystemTrayTest, SystemTrayHeightWithBubble) { 547 TEST_F(SystemTrayTest, SystemTrayHeightWithBubble) {
552 StatusAreaWidget* widget = Shell::GetPrimaryRootWindowController() 548 SystemTray* tray = GetPrimarySystemTray();
553 ->shelf_widget()
554 ->status_area_widget();
555 SystemTray* tray = widget->system_tray();
556 WebNotificationTray* notification_tray = 549 WebNotificationTray* notification_tray =
557 tray->status_area_widget()->web_notification_tray(); 550 tray->status_area_widget()->web_notification_tray();
558 551
559 // Ensure the initial system tray height is zero. 552 // Ensure the initial system tray height is zero.
560 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); 553 EXPECT_EQ(0, notification_tray->system_tray_height_for_test());
561 554
562 // Show the default view, ensure the system tray height is changed. 555 // Show the default view, ensure the system tray height is changed.
563 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 556 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
564 RunAllPendingInMessageLoop(); 557 RunAllPendingInMessageLoop();
565 EXPECT_LT(0, notification_tray->system_tray_height_for_test()); 558 EXPECT_LT(0, notification_tray->system_tray_height_for_test());
566 559
567 // Hide the default view, ensure the system tray height is back to zero. 560 // Hide the default view, ensure the system tray height is back to zero.
568 ASSERT_TRUE(tray->CloseSystemBubble()); 561 ASSERT_TRUE(tray->CloseSystemBubble());
569 RunAllPendingInMessageLoop(); 562 RunAllPendingInMessageLoop();
570 563
571 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); 564 EXPECT_EQ(0, notification_tray->system_tray_height_for_test());
572 } 565 }
573 #endif // OS_CHROMEOS 566 #endif // OS_CHROMEOS
574 567
575 } // namespace test 568 } // namespace test
576 } // namespace ash 569 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698