OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
15 #include "chrome/browser/notifications/message_center_display_service.h" | 15 #include "chrome/browser/notifications/message_center_display_service.h" |
16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" |
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 18 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
19 #include "chrome/browser/permissions/permission_manager.h" | 19 #include "chrome/browser/permissions/permission_manager.h" |
20 #include "chrome/browser/permissions/permission_request_manager.h" | 20 #include "chrome/browser/permissions/permission_request_manager.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/public/browser/permission_type.h" | 27 #include "content/public/browser/permission_type.h" |
26 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
27 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
28 #include "net/base/filename_util.h" | 30 #include "net/base/filename_util.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 33 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
32 | 34 |
33 #if BUILDFLAG(ENABLE_BACKGROUND) | 35 #if BUILDFLAG(ENABLE_BACKGROUND) |
34 #include "chrome/browser/lifetime/keep_alive_registry.h" | 36 #include "chrome/browser/lifetime/keep_alive_registry.h" |
35 #include "chrome/browser/lifetime/keep_alive_types.h" | 37 #include "chrome/browser/lifetime/keep_alive_types.h" |
36 #endif | 38 #endif |
37 | 39 |
| 40 #if defined(OS_MACOSX) |
| 41 #include "base/mac/mac_util.h" |
| 42 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h" |
| 43 #endif |
| 44 |
38 // ----------------------------------------------------------------------------- | 45 // ----------------------------------------------------------------------------- |
39 | 46 |
40 // Dimensions of the icon.png resource in the notification test data directory. | 47 // Dimensions of the icon.png resource in the notification test data directory. |
41 const int kIconWidth = 100; | 48 const int kIconWidth = 100; |
42 const int kIconHeight = 100; | 49 const int kIconHeight = 100; |
43 | 50 |
44 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; | 51 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; |
45 const double kNotificationTimestamp = 621046800000.; | 52 const double kNotificationTimestamp = 621046800000.; |
46 | 53 |
47 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { | 54 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 528 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
522 | 529 |
523 notification.delegate()->ButtonClick(0); | 530 notification.delegate()->ButtonClick(0); |
524 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 531 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
525 EXPECT_EQ("action_button_click actionId1", script_result); | 532 EXPECT_EQ("action_button_click actionId1", script_result); |
526 | 533 |
527 notification.delegate()->ButtonClick(1); | 534 notification.delegate()->ButtonClick(1); |
528 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 535 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
529 EXPECT_EQ("action_button_click actionId2", script_result); | 536 EXPECT_EQ("action_button_click actionId2", script_result); |
530 } | 537 } |
| 538 |
| 539 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 540 TestShouldDisplayNormal) { |
| 541 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 542 |
| 543 std::string script_result; |
| 544 ASSERT_TRUE(RunScript( |
| 545 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 546 EXPECT_EQ("ok", script_result); |
| 547 |
| 548 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 549 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 550 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 551 } |
| 552 |
| 553 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 554 TestShouldDisplayFullscreen) { |
| 555 #if defined(OS_MACOSX) |
| 556 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 557 #endif |
| 558 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 559 |
| 560 std::string script_result; |
| 561 ASSERT_TRUE(RunScript( |
| 562 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 563 EXPECT_EQ("ok", script_result); |
| 564 |
| 565 // Set the page fullscreen |
| 566 browser()->exclusive_access_manager()->fullscreen_controller()-> |
| 567 ToggleBrowserFullscreenMode(); |
| 568 |
| 569 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 570 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 571 EXPECT_TRUE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 572 } |
| 573 |
| 574 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen |
| 575 // window when another is visible. |
| 576 #if !defined(OS_MACOSX) |
| 577 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 578 TestShouldDisplayMultiFullscreen) { |
| 579 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 580 |
| 581 Browser* other_browser = CreateBrowser(browser()->profile()); |
| 582 ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); |
| 583 |
| 584 std::string script_result; |
| 585 ASSERT_TRUE(RunScript( |
| 586 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 587 EXPECT_EQ("ok", script_result); |
| 588 |
| 589 // Set the notifcation page fullscreen |
| 590 browser()->exclusive_access_manager()->fullscreen_controller()-> |
| 591 ToggleBrowserFullscreenMode(); |
| 592 |
| 593 // Set the other browser fullscreen |
| 594 other_browser->exclusive_access_manager()->fullscreen_controller()-> |
| 595 ToggleBrowserFullscreenMode(); |
| 596 |
| 597 ASSERT_TRUE(browser()->exclusive_access_manager()->context()->IsFullscreen()); |
| 598 ASSERT_TRUE( |
| 599 other_browser->exclusive_access_manager()->context()->IsFullscreen()); |
| 600 |
| 601 ASSERT_FALSE(browser()->window()->IsActive()); |
| 602 ASSERT_TRUE(other_browser->window()->IsActive()); |
| 603 |
| 604 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 605 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 606 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 607 } |
| 608 #endif |
| 609 |
OLD | NEW |