| 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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return PlatformNotificationServiceImpl::GetInstance(); | 81 return PlatformNotificationServiceImpl::GetInstance(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Grants permission to display Web Notifications for origin of the test | 84 // Grants permission to display Web Notifications for origin of the test |
| 85 // page that's being used in this browser test. | 85 // page that's being used in this browser test. |
| 86 void GrantNotificationPermissionForTest() const; | 86 void GrantNotificationPermissionForTest() const; |
| 87 | 87 |
| 88 bool RequestAndAcceptPermission(); | 88 bool RequestAndAcceptPermission(); |
| 89 bool RequestAndDenyPermission(); | 89 bool RequestAndDenyPermission(); |
| 90 | 90 |
| 91 void EnableFullscreenNotifications(); | 91 void EnableFullscreenNotifications( |
| 92 void DisableFullscreenNotifications(); | 92 base::test::ScopedFeatureList* scoped_feature_list); |
| 93 void DisableFullscreenNotifications( |
| 94 base::test::ScopedFeatureList* scoped_feature_list); |
| 93 | 95 |
| 94 double GetEngagementScore(const GURL& origin) const; | 96 double GetEngagementScore(const GURL& origin) const; |
| 95 GURL GetLastCommittedURL() const; | 97 GURL GetLastCommittedURL() const; |
| 96 | 98 |
| 97 // Returns the UI Manager on which notifications will be displayed. | 99 // Returns the UI Manager on which notifications will be displayed. |
| 98 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } | 100 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } |
| 99 | 101 |
| 100 const base::FilePath& server_root() const { return server_root_; } | 102 const base::FilePath& server_root() const { return server_root_; } |
| 101 | 103 |
| 102 // Navigates the browser to the test page indicated by |path|. | 104 // Navigates the browser to the test page indicated by |path|. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // The test server has a base directory that doesn't exist in the | 139 // The test server has a base directory that doesn't exist in the |
| 138 // filesystem. | 140 // filesystem. |
| 139 test_page_url_(std::string("/") + kTestFileName) {} | 141 test_page_url_(std::string("/") + kTestFileName) {} |
| 140 | 142 |
| 141 void PlatformNotificationServiceBrowserTest::SetUpDefaultCommandLine( | 143 void PlatformNotificationServiceBrowserTest::SetUpDefaultCommandLine( |
| 142 base::CommandLine* command_line) { | 144 base::CommandLine* command_line) { |
| 143 InProcessBrowserTest::SetUpDefaultCommandLine(command_line); | 145 InProcessBrowserTest::SetUpDefaultCommandLine(command_line); |
| 144 | 146 |
| 145 // Needed for the Reply button tests | 147 // Needed for the Reply button tests |
| 146 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 148 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| 147 | |
| 148 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) | |
| 149 // TODO(crbug.com/714679): Temporary change while tests are upgraded to deal | |
| 150 // with native notifications. | |
| 151 command_line->AppendSwitchASCII(switches::kDisableFeatures, | |
| 152 features::kNativeNotifications.name); | |
| 153 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) | |
| 154 } | 149 } |
| 155 | 150 |
| 156 void PlatformNotificationServiceBrowserTest::SetUp() { | 151 void PlatformNotificationServiceBrowserTest::SetUp() { |
| 157 ui_manager_.reset(new StubNotificationUIManager); | 152 ui_manager_.reset(new StubNotificationUIManager); |
| 158 https_server_.reset( | 153 https_server_.reset( |
| 159 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 154 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 160 https_server_->ServeFilesFromSourceDirectory(server_root_); | 155 https_server_->ServeFilesFromSourceDirectory(server_root_); |
| 161 ASSERT_TRUE(https_server_->Start()); | 156 ASSERT_TRUE(https_server_->Start()); |
| 157 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) |
| 158 // TODO(crbug.com/714679): Temporary change while tests are upgraded to deal |
| 159 // with native notifications. |
| 160 feature_list_.InitAndDisableFeature(features::kNativeNotifications); |
| 161 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) |
| 162 InProcessBrowserTest::SetUp(); | 162 InProcessBrowserTest::SetUp(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { | 165 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
| 166 SiteEngagementScore::SetParamValuesForTesting(); | 166 SiteEngagementScore::SetParamValuesForTesting(); |
| 167 engagement_service_ = SiteEngagementService::Get(browser()->profile()); | 167 engagement_service_ = SiteEngagementService::Get(browser()->profile()); |
| 168 NavigateToTestPage(test_page_url_); | 168 NavigateToTestPage(test_page_url_); |
| 169 display_service_.reset( | 169 display_service_.reset( |
| 170 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); | 170 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); |
| 171 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); | 171 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 RequestAndRespondToPermission(PermissionRequestManager::ACCEPT_ALL); | 225 RequestAndRespondToPermission(PermissionRequestManager::ACCEPT_ALL); |
| 226 return "granted" == result; | 226 return "granted" == result; |
| 227 } | 227 } |
| 228 | 228 |
| 229 bool PlatformNotificationServiceBrowserTest::RequestAndDenyPermission() { | 229 bool PlatformNotificationServiceBrowserTest::RequestAndDenyPermission() { |
| 230 std::string result = | 230 std::string result = |
| 231 RequestAndRespondToPermission(PermissionRequestManager::DENY_ALL); | 231 RequestAndRespondToPermission(PermissionRequestManager::DENY_ALL); |
| 232 return "denied" == result; | 232 return "denied" == result; |
| 233 } | 233 } |
| 234 | 234 |
| 235 void PlatformNotificationServiceBrowserTest::EnableFullscreenNotifications() { | 235 void PlatformNotificationServiceBrowserTest::EnableFullscreenNotifications( |
| 236 feature_list_.InitWithFeatures({ | 236 base::test::ScopedFeatureList* scoped_feature_list) { |
| 237 features::kPreferHtmlOverPlugins, | 237 scoped_feature_list->InitWithFeatures( |
| 238 features::kAllowFullscreenWebNotificationsFeature}, {}); | 238 {features::kPreferHtmlOverPlugins, |
| 239 features::kAllowFullscreenWebNotificationsFeature}, |
| 240 {}); |
| 239 } | 241 } |
| 240 | 242 |
| 241 void PlatformNotificationServiceBrowserTest::DisableFullscreenNotifications() { | 243 void PlatformNotificationServiceBrowserTest::DisableFullscreenNotifications( |
| 242 feature_list_.InitWithFeatures( | 244 base::test::ScopedFeatureList* scoped_feature_list) { |
| 245 scoped_feature_list->InitWithFeatures( |
| 243 {features::kPreferHtmlOverPlugins}, | 246 {features::kPreferHtmlOverPlugins}, |
| 244 {features::kAllowFullscreenWebNotificationsFeature}); | 247 {features::kAllowFullscreenWebNotificationsFeature}); |
| 245 } | 248 } |
| 246 | 249 |
| 247 double PlatformNotificationServiceBrowserTest::GetEngagementScore( | 250 double PlatformNotificationServiceBrowserTest::GetEngagementScore( |
| 248 const GURL& origin) const { | 251 const GURL& origin) const { |
| 249 return engagement_service_->GetScore(origin); | 252 return engagement_service_->GetScore(origin); |
| 250 } | 253 } |
| 251 | 254 |
| 252 GURL PlatformNotificationServiceBrowserTest::GetLastCommittedURL() const { | 255 GURL PlatformNotificationServiceBrowserTest::GetLastCommittedURL() const { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 696 |
| 694 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); | 697 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); |
| 695 notifications = base::SplitString(script_message, ",", base::KEEP_WHITESPACE, | 698 notifications = base::SplitString(script_message, ",", base::KEEP_WHITESPACE, |
| 696 base::SPLIT_WANT_ALL); | 699 base::SPLIT_WANT_ALL); |
| 697 ASSERT_EQ(1u, notifications.size()); | 700 ASSERT_EQ(1u, notifications.size()); |
| 698 } | 701 } |
| 699 | 702 |
| 700 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 703 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 701 TestShouldDisplayNormal) { | 704 TestShouldDisplayNormal) { |
| 702 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 705 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 703 EnableFullscreenNotifications(); | 706 base::test::ScopedFeatureList scoped_feature_list; |
| 707 EnableFullscreenNotifications(&scoped_feature_list); |
| 704 | 708 |
| 705 std::string script_result; | 709 std::string script_result; |
| 706 ASSERT_TRUE(RunScript( | 710 ASSERT_TRUE(RunScript( |
| 707 "DisplayPersistentNotification('display_normal')", &script_result)); | 711 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 708 EXPECT_EQ("ok", script_result); | 712 EXPECT_EQ("ok", script_result); |
| 709 | 713 |
| 710 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 714 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 711 const Notification& notification = ui_manager()->GetNotificationAt(0); | 715 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 712 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); | 716 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 713 } | 717 } |
| 714 | 718 |
| 715 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 719 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 716 TestShouldDisplayFullscreen) { | 720 TestShouldDisplayFullscreen) { |
| 717 #if defined(OS_MACOSX) | 721 #if defined(OS_MACOSX) |
| 718 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 722 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 719 #endif | 723 #endif |
| 720 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 724 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 721 EnableFullscreenNotifications(); | 725 base::test::ScopedFeatureList scoped_feature_list; |
| 726 EnableFullscreenNotifications(&scoped_feature_list); |
| 722 | 727 |
| 723 std::string script_result; | 728 std::string script_result; |
| 724 ASSERT_TRUE(RunScript( | 729 ASSERT_TRUE(RunScript( |
| 725 "DisplayPersistentNotification('display_normal')", &script_result)); | 730 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 726 EXPECT_EQ("ok", script_result); | 731 EXPECT_EQ("ok", script_result); |
| 727 | 732 |
| 728 // Set the page fullscreen | 733 // Set the page fullscreen |
| 729 browser()->exclusive_access_manager()->fullscreen_controller()-> | 734 browser()->exclusive_access_manager()->fullscreen_controller()-> |
| 730 ToggleBrowserFullscreenMode(); | 735 ToggleBrowserFullscreenMode(); |
| 731 | 736 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 744 const Notification& notification = ui_manager()->GetNotificationAt(0); | 749 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 745 EXPECT_TRUE(notification.delegate()->ShouldDisplayOverFullscreen()); | 750 EXPECT_TRUE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 746 } | 751 } |
| 747 | 752 |
| 748 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 753 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 749 TestShouldDisplayFullscreenOff) { | 754 TestShouldDisplayFullscreenOff) { |
| 750 #if defined(OS_MACOSX) | 755 #if defined(OS_MACOSX) |
| 751 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 756 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 752 #endif | 757 #endif |
| 753 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 758 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 754 DisableFullscreenNotifications(); | 759 base::test::ScopedFeatureList scoped_feature_list; |
| 760 DisableFullscreenNotifications(&scoped_feature_list); |
| 755 | 761 |
| 756 std::string script_result; | 762 std::string script_result; |
| 757 ASSERT_TRUE(RunScript( | 763 ASSERT_TRUE(RunScript( |
| 758 "DisplayPersistentNotification('display_normal')", &script_result)); | 764 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 759 EXPECT_EQ("ok", script_result); | 765 EXPECT_EQ("ok", script_result); |
| 760 | 766 |
| 761 // Set the page fullscreen | 767 // Set the page fullscreen |
| 762 browser()->exclusive_access_manager()->fullscreen_controller()-> | 768 browser()->exclusive_access_manager()->fullscreen_controller()-> |
| 763 ToggleBrowserFullscreenMode(); | 769 ToggleBrowserFullscreenMode(); |
| 764 | 770 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 779 // return false. | 785 // return false. |
| 780 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); | 786 EXPECT_FALSE(notification.delegate()->ShouldDisplayOverFullscreen()); |
| 781 } | 787 } |
| 782 | 788 |
| 783 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen | 789 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen |
| 784 // window when another is visible. | 790 // window when another is visible. |
| 785 #if !defined(OS_MACOSX) | 791 #if !defined(OS_MACOSX) |
| 786 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 792 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 787 TestShouldDisplayMultiFullscreen) { | 793 TestShouldDisplayMultiFullscreen) { |
| 788 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 794 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 789 EnableFullscreenNotifications(); | 795 base::test::ScopedFeatureList scoped_feature_list; |
| 796 EnableFullscreenNotifications(&scoped_feature_list); |
| 790 | 797 |
| 791 Browser* other_browser = CreateBrowser(browser()->profile()); | 798 Browser* other_browser = CreateBrowser(browser()->profile()); |
| 792 ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); | 799 ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); |
| 793 | 800 |
| 794 std::string script_result; | 801 std::string script_result; |
| 795 ASSERT_TRUE(RunScript( | 802 ASSERT_TRUE(RunScript( |
| 796 "DisplayPersistentNotification('display_normal')", &script_result)); | 803 "DisplayPersistentNotification('display_normal')", &script_result)); |
| 797 EXPECT_EQ("ok", script_result); | 804 EXPECT_EQ("ok", script_result); |
| 798 | 805 |
| 799 // Set the notifcation page fullscreen | 806 // Set the notifcation page fullscreen |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); | 861 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); |
| 855 EXPECT_EQ("ok", script_result); | 862 EXPECT_EQ("ok", script_result); |
| 856 | 863 |
| 857 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 864 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 858 const Notification& notification = ui_manager()->GetNotificationAt(0); | 865 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 859 | 866 |
| 860 // Since the kNotificationContentImage kill switch has disabled images, the | 867 // Since the kNotificationContentImage kill switch has disabled images, the |
| 861 // notification should be shown without an image. | 868 // notification should be shown without an image. |
| 862 EXPECT_TRUE(notification.image().IsEmpty()); | 869 EXPECT_TRUE(notification.image().IsEmpty()); |
| 863 } | 870 } |
| OLD | NEW |