Chromium Code Reviews| 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 |
| 54 namespace { | |
| 55 | |
| 56 // Helper class that has to be created in the stack to check if the fullscreen | |
| 57 // setting of a browser is in the desired state. | |
| 58 class FullscreenStateWaiter { | |
| 59 public: | |
| 60 explicit FullscreenStateWaiter(Browser* browser, bool desired_state) | |
| 61 : browser_(browser), | |
| 62 desired_state_(desired_state) {} | |
| 63 | |
| 64 void Wait() { | |
| 65 while (desired_state_ != | |
| 66 browser_->exclusive_access_manager()->context()->IsFullscreen()) | |
| 67 content::RunAllPendingInMessageLoop(); | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 Browser* browser_; | |
| 72 bool desired_state_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(FullscreenStateWaiter); | |
| 75 }; | |
| 76 | |
| 77 } // namespace | |
| 78 | |
| 47 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { | 79 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { |
| 48 public: | 80 public: |
| 49 PlatformNotificationServiceBrowserTest(); | 81 PlatformNotificationServiceBrowserTest(); |
| 50 ~PlatformNotificationServiceBrowserTest() override {} | 82 ~PlatformNotificationServiceBrowserTest() override {} |
| 51 | 83 |
| 52 // InProcessBrowserTest overrides. | 84 // InProcessBrowserTest overrides. |
| 53 void SetUpCommandLine(base::CommandLine* command_line) override; | 85 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 54 void SetUp() override; | 86 void SetUp() override; |
| 55 void SetUpOnMainThread() override; | 87 void SetUpOnMainThread() override; |
| 56 void TearDown() override; | 88 void TearDown() override; |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 553 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
| 522 | 554 |
| 523 notification.delegate()->ButtonClick(0); | 555 notification.delegate()->ButtonClick(0); |
| 524 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 556 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 525 EXPECT_EQ("action_button_click actionId1", script_result); | 557 EXPECT_EQ("action_button_click actionId1", script_result); |
| 526 | 558 |
| 527 notification.delegate()->ButtonClick(1); | 559 notification.delegate()->ButtonClick(1); |
| 528 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 560 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 529 EXPECT_EQ("action_button_click actionId2", script_result); | 561 EXPECT_EQ("action_button_click actionId2", script_result); |
| 530 } | 562 } |
| 563 | |
| 564 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | |
|
dewittj
2016/09/28 20:01:54
The tests and utilities are essentially copies bet
bmalcolm
2016/09/29 20:53:14
I've moved the utilities into the common utilities
| |
| 565 TestShouldDisplayNormal) { | |
| 566 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | |
| 567 | |
| 568 std::string script_result; | |
| 569 ASSERT_TRUE(RunScript( | |
| 570 "DisplayPersistentNotification('display_normal')", &script_result)); | |
| 571 EXPECT_EQ("ok", script_result); | |
| 572 | |
| 573 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | |
| 574 const Notification& notification = ui_manager()->GetNotificationAt(0); | |
| 575 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); | |
| 576 } | |
| 577 | |
| 578 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | |
| 579 TestShouldDisplayFullscreen) { | |
| 580 #if defined(OS_MACOSX) | |
| 581 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | |
| 582 #endif | |
| 583 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | |
| 584 | |
| 585 std::string script_result; | |
| 586 ASSERT_TRUE(RunScript( | |
| 587 "DisplayPersistentNotification('display_normal')", &script_result)); | |
| 588 EXPECT_EQ("ok", script_result); | |
| 589 | |
| 590 // Set the page fullscreen | |
| 591 browser()->exclusive_access_manager()->fullscreen_controller()-> | |
| 592 ToggleBrowserFullscreenMode(); | |
| 593 | |
| 594 { | |
| 595 FullscreenStateWaiter fs_state(browser(), true); | |
| 596 fs_state.Wait(); | |
| 597 } | |
| 598 | |
| 599 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | |
| 600 const Notification& notification = ui_manager()->GetNotificationAt(0); | |
| 601 EXPECT_TRUE(notification.delegate()->ShouldDisplayOverFullscreen()); | |
|
dewittj
2016/09/28 20:01:53
does this fail on android?
bmalcolm
2016/09/29 20:53:14
No it passes. Probably because these tests don't g
dewittj
2016/09/29 20:57:38
There's a TODO in chrome/test/BUILD.gn to get thes
Peter Beverloo
2016/09/29 21:30:51
I think the answer has been "soon" for as long as
| |
| 602 } | |
| 603 | |
| 604 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen | |
| 605 // window when another is visible. | |
| 606 #if !defined(OS_MACOSX) | |
| 607 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | |
| 608 TestShouldDisplayMultiFullscreen) { | |
| 609 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | |
| 610 | |
| 611 Browser* other_browser = CreateBrowser(browser()->profile()); | |
| 612 ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); | |
| 613 | |
| 614 std::string script_result; | |
| 615 ASSERT_TRUE(RunScript( | |
| 616 "DisplayPersistentNotification('display_normal')", &script_result)); | |
| 617 EXPECT_EQ("ok", script_result); | |
| 618 | |
| 619 // Set the notifcation page fullscreen | |
| 620 browser()->exclusive_access_manager()->fullscreen_controller()-> | |
| 621 ToggleBrowserFullscreenMode(); | |
| 622 { | |
| 623 FullscreenStateWaiter fs_state(browser(), true); | |
| 624 fs_state.Wait(); | |
| 625 } | |
| 626 | |
| 627 // Set the other browser fullscreen | |
| 628 other_browser->exclusive_access_manager()->fullscreen_controller()-> | |
| 629 ToggleBrowserFullscreenMode(); | |
| 630 { | |
| 631 FullscreenStateWaiter fs_state(other_browser, true); | |
| 632 fs_state.Wait(); | |
| 633 } | |
| 634 | |
| 635 ASSERT_TRUE(browser()->exclusive_access_manager()->context()->IsFullscreen()); | |
| 636 ASSERT_TRUE( | |
| 637 other_browser->exclusive_access_manager()->context()->IsFullscreen()); | |
| 638 | |
| 639 ASSERT_FALSE(browser()->window()->IsActive()); | |
| 640 ASSERT_TRUE(other_browser->window()->IsActive()); | |
| 641 | |
| 642 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | |
| 643 const Notification& notification = ui_manager()->GetNotificationAt(0); | |
| 644 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); | |
| 645 } | |
| 646 #endif | |
| 647 | |
| OLD | NEW |