| OLD | NEW |
| 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/common/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/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/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 public: | 73 public: |
| 74 TestItem() : SystemTrayItem(GetSystemTray(), UMA_TEST) {} | 74 TestItem() : SystemTrayItem(GetSystemTray(), UMA_TEST) {} |
| 75 | 75 |
| 76 views::View* CreateDefaultView(LoginStatus status) override { | 76 views::View* CreateDefaultView(LoginStatus status) override { |
| 77 views::View* default_view = new views::View; | 77 views::View* default_view = new views::View; |
| 78 default_view->SetLayoutManager(new views::FillLayout); | 78 default_view->SetLayoutManager(new views::FillLayout); |
| 79 default_view->AddChildView(new views::Label(base::UTF8ToUTF16("Default"))); | 79 default_view->AddChildView(new views::Label(base::UTF8ToUTF16("Default"))); |
| 80 return default_view; | 80 return default_view; |
| 81 } | 81 } |
| 82 | 82 |
| 83 views::View* CreateNotificationView(LoginStatus status) override { | |
| 84 return new views::View; | |
| 85 } | |
| 86 | |
| 87 private: | 83 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(TestItem); | 84 DISALLOW_COPY_AND_ASSIGN(TestItem); |
| 89 }; | 85 }; |
| 90 | 86 |
| 91 } // namespace | 87 } // namespace |
| 92 | 88 |
| 93 // TODO(jamescook): Move this to //ash/common. http://crbug.com/620955 | 89 // TODO(jamescook): Move this to //ash/common. http://crbug.com/620955 |
| 94 class WebNotificationTrayTest : public test::AshMDTestBase { | 90 class WebNotificationTrayTest : public test::AshMDTestBase { |
| 95 public: | 91 public: |
| 96 WebNotificationTrayTest() {} | 92 WebNotificationTrayTest() {} |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 AddNotification("test_id"); | 300 AddNotification("test_id"); |
| 305 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 301 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 306 int bottom = GetPopupWorkAreaBottom(); | 302 int bottom = GetPopupWorkAreaBottom(); |
| 307 | 303 |
| 308 // System tray is created, the popup's work area should be narrowed but still | 304 // System tray is created, the popup's work area should be narrowed but still |
| 309 // visible. | 305 // visible. |
| 310 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 306 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 311 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 307 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 312 int bottom_with_tray = GetPopupWorkAreaBottom(); | 308 int bottom_with_tray = GetPopupWorkAreaBottom(); |
| 313 EXPECT_GT(bottom, bottom_with_tray); | 309 EXPECT_GT(bottom, bottom_with_tray); |
| 314 | |
| 315 // System tray notification is also created, the popup's work area is narrowed | |
| 316 // even more, but still visible. | |
| 317 GetSystemTray()->ShowNotificationView(test_item); | |
| 318 EXPECT_TRUE(GetTray()->IsPopupVisible()); | |
| 319 int bottom_with_tray_notification = GetPopupWorkAreaBottom(); | |
| 320 EXPECT_GT(bottom, bottom_with_tray_notification); | |
| 321 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification); | |
| 322 | |
| 323 // Close system tray, only system tray notifications. | |
| 324 GetSystemTray()->ClickedOutsideBubble(); | |
| 325 EXPECT_TRUE(GetTray()->IsPopupVisible()); | |
| 326 int bottom_with_notification = GetPopupWorkAreaBottom(); | |
| 327 EXPECT_GT(bottom, bottom_with_notification); | |
| 328 EXPECT_LT(bottom_with_tray_notification, bottom_with_notification); | |
| 329 | |
| 330 // Close the system tray notifications. | |
| 331 GetSystemTray()->HideNotificationView(test_item); | |
| 332 EXPECT_TRUE(GetTray()->IsPopupVisible()); | |
| 333 EXPECT_EQ(bottom, GetPopupWorkAreaBottom()); | |
| 334 } | 310 } |
| 335 | 311 |
| 336 TEST_P(WebNotificationTrayTest, PopupAndAutoHideShelf) { | 312 TEST_P(WebNotificationTrayTest, PopupAndAutoHideShelf) { |
| 337 AddNotification("test_id"); | 313 AddNotification("test_id"); |
| 338 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 314 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 339 int bottom = GetPopupWorkAreaBottom(); | 315 int bottom = GetPopupWorkAreaBottom(); |
| 340 | 316 |
| 341 // Shelf's auto-hide state won't be HIDDEN unless window exists. | 317 // Shelf's auto-hide state won't be HIDDEN unless window exists. |
| 342 std::unique_ptr<views::Widget> widget(CreateTestWidget()); | 318 std::unique_ptr<views::Widget> widget(CreateTestWidget()); |
| 343 WmShelf* shelf = GetPrimaryShelf(); | 319 WmShelf* shelf = GetPrimaryShelf(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 357 widget = CreateTestWidget(); | 333 widget = CreateTestWidget(); |
| 358 TestItem* test_item = new TestItem; | 334 TestItem* test_item = new TestItem; |
| 359 GetSystemTray()->AddTrayItem(base::WrapUnique(test_item)); | 335 GetSystemTray()->AddTrayItem(base::WrapUnique(test_item)); |
| 360 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); | 336 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 361 UpdateAutoHideStateNow(); | 337 UpdateAutoHideStateNow(); |
| 362 | 338 |
| 363 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | 339 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); |
| 364 EXPECT_TRUE(GetTray()->IsPopupVisible()); | 340 EXPECT_TRUE(GetTray()->IsPopupVisible()); |
| 365 int bottom_with_tray = GetPopupWorkAreaBottom(); | 341 int bottom_with_tray = GetPopupWorkAreaBottom(); |
| 366 EXPECT_GT(bottom_auto_shown, bottom_with_tray); | 342 EXPECT_GT(bottom_auto_shown, bottom_with_tray); |
| 367 | |
| 368 // Create tray notification. | |
| 369 GetSystemTray()->ShowNotificationView(test_item); | |
| 370 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | |
| 371 int bottom_with_tray_notification = GetPopupWorkAreaBottom(); | |
| 372 EXPECT_GT(bottom_with_tray, bottom_with_tray_notification); | |
| 373 | |
| 374 // Close the system tray. | |
| 375 GetSystemTray()->ClickedOutsideBubble(); | |
| 376 shelf->UpdateAutoHideState(); | |
| 377 RunAllPendingInMessageLoop(); | |
| 378 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | |
| 379 int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom(); | |
| 380 EXPECT_LT(bottom_with_tray_notification, | |
| 381 bottom_hidden_with_tray_notification); | |
| 382 EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification); | |
| 383 | |
| 384 // Close the window again, which shows the shelf. | |
| 385 widget.reset(); | |
| 386 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | |
| 387 int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom(); | |
| 388 EXPECT_GT(bottom_hidden_with_tray_notification, | |
| 389 bottom_shown_with_tray_notification); | |
| 390 EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification); | |
| 391 } | 343 } |
| 392 | 344 |
| 393 TEST_P(WebNotificationTrayTest, PopupAndFullscreen) { | 345 TEST_P(WebNotificationTrayTest, PopupAndFullscreen) { |
| 394 AddNotification("test_id"); | 346 AddNotification("test_id"); |
| 395 EXPECT_TRUE(IsPopupVisible()); | 347 EXPECT_TRUE(IsPopupVisible()); |
| 396 int bottom = GetPopupWorkAreaBottom(); | 348 int bottom = GetPopupWorkAreaBottom(); |
| 397 | 349 |
| 398 // Checks the work area for normal auto-hidden state. | 350 // Checks the work area for normal auto-hidden state. |
| 399 std::unique_ptr<views::Widget> widget(CreateTestWidget()); | 351 std::unique_ptr<views::Widget> widget(CreateTestWidget()); |
| 400 WmShelf* shelf = GetPrimaryShelf(); | 352 WmShelf* shelf = GetPrimaryShelf(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); | 452 gfx::Point out_of_bounds(bounds.x() - 1, center_point.y()); |
| 501 generator.MoveTouch(out_of_bounds); | 453 generator.MoveTouch(out_of_bounds); |
| 502 EXPECT_FALSE(tray->is_active()); | 454 EXPECT_FALSE(tray->is_active()); |
| 503 | 455 |
| 504 generator.ReleaseTouch(); | 456 generator.ReleaseTouch(); |
| 505 EXPECT_FALSE(tray->is_active()); | 457 EXPECT_FALSE(tray->is_active()); |
| 506 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); | 458 EXPECT_FALSE(tray->IsMessageCenterBubbleVisible()); |
| 507 } | 459 } |
| 508 | 460 |
| 509 } // namespace ash | 461 } // namespace ash |
| OLD | NEW |