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

Side by Side Diff: ash/system/web_notification/web_notification_tray_unittest.cc

Issue 2033833002: ash: Remove aura dependencies from ash/system/web_notification (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/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm/wm_globals.h"
13 #include "ash/common/wm/wm_lookup.h"
14 #include "ash/common/wm/wm_root_window_controller.h"
15 #include "ash/common/wm/wm_window.h"
11 #include "ash/display/display_manager.h" 16 #include "ash/display/display_manager.h"
12 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
13 #include "ash/shelf/shelf_layout_manager.h" 18 #include "ash/shelf/shelf_layout_manager.h"
14 #include "ash/shelf/shelf_widget.h" 19 #include "ash/shelf/shelf_widget.h"
15 #include "ash/shell.h" 20 #include "ash/shell.h"
16 #include "ash/system/status_area_widget.h" 21 #include "ash/system/status_area_widget.h"
17 #include "ash/system/tray/system_tray.h" 22 #include "ash/system/tray/system_tray.h"
18 #include "ash/system/tray/system_tray_item.h" 23 #include "ash/system/tray/system_tray_item.h"
19 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h"
20 #include "ash/test/ash_test_base.h" 25 #include "ash/test/ash_test_base.h"
21 #include "ash/test/status_area_widget_test_helper.h" 26 #include "ash/test/status_area_widget_test_helper.h"
22 #include "ash/test/test_system_tray_delegate.h" 27 #include "ash/test/test_system_tray_delegate.h"
23 #include "ash/wm/window_state_aura.h"
24 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/window.h"
28 #include "ui/display/display.h" 30 #include "ui/display/display.h"
29 #include "ui/display/screen.h" 31 #include "ui/display/screen.h"
30 #include "ui/events/event.h" 32 #include "ui/events/event.h"
31 #include "ui/events/test/event_generator.h" 33 #include "ui/events/test/event_generator.h"
32 #include "ui/gfx/geometry/point.h" 34 #include "ui/gfx/geometry/point.h"
33 #include "ui/gfx/geometry/rect.h" 35 #include "ui/gfx/geometry/rect.h"
34 #include "ui/message_center/message_center_style.h" 36 #include "ui/message_center/message_center_style.h"
35 #include "ui/message_center/message_center_tray.h" 37 #include "ui/message_center/message_center_tray.h"
36 #include "ui/message_center/notification_list.h" 38 #include "ui/message_center/notification_list.h"
37 #include "ui/message_center/notification_types.h" 39 #include "ui/message_center/notification_types.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 142
141 int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) { 143 int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) {
142 return tray->popup_alignment_delegate_->GetWorkAreaBottom(); 144 return tray->popup_alignment_delegate_->GetWorkAreaBottom();
143 } 145 }
144 146
145 bool IsPopupVisible() { 147 bool IsPopupVisible() {
146 return GetTray()->IsPopupVisible(); 148 return GetTray()->IsPopupVisible();
147 } 149 }
148 150
151 std::unique_ptr<views::Widget> CreateTestWidget() {
152 std::unique_ptr<views::Widget> widget(new views::Widget);
153 views::Widget::InitParams params;
154 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
155 params.bounds = gfx::Rect(1, 2, 3, 4);
156 wm::WmGlobals::Get()
157 ->GetPrimaryRootWindow()
158 ->GetRootWindowController()
159 ->ConfigureWidgetInitParamsForContainer(
160 widget.get(), kShellWindowId_DefaultContainer, &params);
161 widget->Init(params);
162 widget->Show();
163 return widget;
164 }
165
149 private: 166 private:
150 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); 167 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest);
151 }; 168 };
152 169
153 TEST_F(WebNotificationTrayTest, WebNotifications) { 170 TEST_F(WebNotificationTrayTest, WebNotifications) {
154 // TODO(mukai): move this test case to ui/message_center. 171 // TODO(mukai): move this test case to ui/message_center.
155 ASSERT_TRUE(GetWidget()); 172 ASSERT_TRUE(GetWidget());
156 173
157 // Add a notification. 174 // Add a notification.
158 AddNotification("test_id1"); 175 AddNotification("test_id1");
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 EXPECT_TRUE(GetTray()->IsPopupVisible()); 365 EXPECT_TRUE(GetTray()->IsPopupVisible());
349 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); 366 EXPECT_EQ(bottom, GetPopupWorkAreaBottom());
350 } 367 }
351 368
352 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) { 369 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) {
353 AddNotification("test_id"); 370 AddNotification("test_id");
354 EXPECT_TRUE(GetTray()->IsPopupVisible()); 371 EXPECT_TRUE(GetTray()->IsPopupVisible());
355 int bottom = GetPopupWorkAreaBottom(); 372 int bottom = GetPopupWorkAreaBottom();
356 373
357 // Shelf's auto-hide state won't be HIDDEN unless window exists. 374 // Shelf's auto-hide state won't be HIDDEN unless window exists.
358 std::unique_ptr<aura::Window> window( 375 std::unique_ptr<views::Widget> widget(CreateTestWidget());
359 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
360 Shelf* shelf = Shelf::ForPrimaryDisplay(); 376 Shelf* shelf = Shelf::ForPrimaryDisplay();
361 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 377 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
362 378
363 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 379 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
364 int bottom_auto_hidden = GetPopupWorkAreaBottom(); 380 int bottom_auto_hidden = GetPopupWorkAreaBottom();
365 EXPECT_LT(bottom, bottom_auto_hidden); 381 EXPECT_LT(bottom, bottom_auto_hidden);
366 382
367 // Close the window, which shows the shelf. 383 // Close the window, which shows the shelf.
368 window.reset(); 384 widget.reset();
369 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 385 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
370 int bottom_auto_shown = GetPopupWorkAreaBottom(); 386 int bottom_auto_shown = GetPopupWorkAreaBottom();
371 EXPECT_EQ(bottom, bottom_auto_shown); 387 EXPECT_EQ(bottom, bottom_auto_shown);
372 388
373 // Create the system tray during auto-hide. 389 // Create the system tray during auto-hide.
374 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 390 widget = CreateTestWidget();
375 TestItem* test_item = new TestItem; 391 TestItem* test_item = new TestItem;
376 GetSystemTray()->AddTrayItem(test_item); 392 GetSystemTray()->AddTrayItem(test_item);
377 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); 393 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
378 394
379 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 395 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
380 EXPECT_TRUE(GetTray()->IsPopupVisible()); 396 EXPECT_TRUE(GetTray()->IsPopupVisible());
381 int bottom_with_tray = GetPopupWorkAreaBottom(); 397 int bottom_with_tray = GetPopupWorkAreaBottom();
382 EXPECT_GT(bottom_auto_shown, bottom_with_tray); 398 EXPECT_GT(bottom_auto_shown, bottom_with_tray);
383 399
384 // Create tray notification. 400 // Create tray notification.
385 GetSystemTray()->ShowNotificationView(test_item); 401 GetSystemTray()->ShowNotificationView(test_item);
386 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 402 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
387 int bottom_with_tray_notification = GetPopupWorkAreaBottom(); 403 int bottom_with_tray_notification = GetPopupWorkAreaBottom();
388 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification); 404 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification);
389 405
390 // Close the system tray. 406 // Close the system tray.
391 GetSystemTray()->ClickedOutsideBubble(); 407 GetSystemTray()->ClickedOutsideBubble();
392 shelf->shelf_layout_manager()->UpdateAutoHideState(); 408 shelf->shelf_layout_manager()->UpdateAutoHideState();
393 RunAllPendingInMessageLoop(); 409 RunAllPendingInMessageLoop();
394 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 410 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
395 int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom(); 411 int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom();
396 EXPECT_LT(bottom_with_tray_notification, 412 EXPECT_LT(bottom_with_tray_notification,
397 bottom_hidden_with_tray_notification); 413 bottom_hidden_with_tray_notification);
398 EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification); 414 EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification);
399 415
400 // Close the window again, which shows the shelf. 416 // Close the window again, which shows the shelf.
401 window.reset(); 417 widget.reset();
402 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 418 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
403 int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom(); 419 int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom();
404 EXPECT_GT(bottom_hidden_with_tray_notification, 420 EXPECT_GT(bottom_hidden_with_tray_notification,
405 bottom_shown_with_tray_notification); 421 bottom_shown_with_tray_notification);
406 EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification); 422 EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification);
407 } 423 }
408 424
409 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) { 425 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) {
410 AddNotification("test_id"); 426 AddNotification("test_id");
411 EXPECT_TRUE(IsPopupVisible()); 427 EXPECT_TRUE(IsPopupVisible());
412 int bottom = GetPopupWorkAreaBottom(); 428 int bottom = GetPopupWorkAreaBottom();
413 429
414 // Checks the work area for normal auto-hidden state. 430 // Checks the work area for normal auto-hidden state.
415 std::unique_ptr<aura::Window> window( 431 std::unique_ptr<views::Widget> widget(CreateTestWidget());
416 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
417 Shelf* shelf = Shelf::ForPrimaryDisplay(); 432 Shelf* shelf = Shelf::ForPrimaryDisplay();
418 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 433 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
419 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 434 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
420 int bottom_auto_hidden = GetPopupWorkAreaBottom(); 435 int bottom_auto_hidden = GetPopupWorkAreaBottom();
421 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 436 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
422 437
423 // Put |window| into fullscreen without forcing the shelf to hide. Currently, 438 // Put |widget| into fullscreen without forcing the shelf to hide. Currently,
424 // this is used by immersive fullscreen and forces the shelf to be auto 439 // this is used by immersive fullscreen and forces the shelf to be auto
425 // hidden. 440 // hidden.
426 wm::GetWindowState(window.get())->set_hide_shelf_when_fullscreen(false); 441 wm::WmLookup::Get()
427 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 442 ->GetWindowForWidget(widget.get())
443 ->GetWindowState()
444 ->set_hide_shelf_when_fullscreen(false);
445 widget->SetFullscreen(true);
428 RunAllPendingInMessageLoop(); 446 RunAllPendingInMessageLoop();
429 447
430 // The work area for auto-hidden status of fullscreen is a bit larger 448 // The work area for auto-hidden status of fullscreen is a bit larger
431 // since it doesn't even have the 3-pixel width. 449 // since it doesn't even have the 3-pixel width.
432 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 450 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
433 int bottom_fullscreen_hidden = GetPopupWorkAreaBottom(); 451 int bottom_fullscreen_hidden = GetPopupWorkAreaBottom();
434 EXPECT_EQ(bottom_auto_hidden, bottom_fullscreen_hidden); 452 EXPECT_EQ(bottom_auto_hidden, bottom_fullscreen_hidden);
435 453
436 // Move the mouse cursor at the bottom, which shows the shelf. 454 // Move the mouse cursor at the bottom, which shows the shelf.
437 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 455 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id, 540 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id,
523 move.time_stamp()+base::TimeDelta::FromMilliseconds(50)); 541 move.time_stamp()+base::TimeDelta::FromMilliseconds(50));
524 generator.Dispatch(&release); 542 generator.Dispatch(&release);
525 EXPECT_FALSE(tray->draw_background_as_active()); 543 EXPECT_FALSE(tray->draw_background_as_active());
526 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); 544 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
527 } 545 }
528 546
529 #endif // OS_CHROMEOS 547 #endif // OS_CHROMEOS
530 548
531 } // namespace ash 549 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698