| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 PushMessagingBrowserTest() : gcm_service_(nullptr), gcm_driver_(nullptr) {} | 104 PushMessagingBrowserTest() : gcm_service_(nullptr), gcm_driver_(nullptr) {} |
| 105 ~PushMessagingBrowserTest() override {} | 105 ~PushMessagingBrowserTest() override {} |
| 106 | 106 |
| 107 // InProcessBrowserTest: | 107 // InProcessBrowserTest: |
| 108 void SetUp() override { | 108 void SetUp() override { |
| 109 https_server_.reset( | 109 https_server_.reset( |
| 110 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 110 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 111 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); | 111 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); |
| 112 ASSERT_TRUE(https_server_->Start()); | 112 ASSERT_TRUE(https_server_->Start()); |
| 113 | 113 |
| 114 #if defined(ENABLE_NOTIFICATIONS) | |
| 115 notification_manager_.reset(new StubNotificationUIManager); | 114 notification_manager_.reset(new StubNotificationUIManager); |
| 116 #endif | |
| 117 | 115 |
| 118 InProcessBrowserTest::SetUp(); | 116 InProcessBrowserTest::SetUp(); |
| 119 } | 117 } |
| 120 | 118 |
| 121 void SetUpCommandLine(base::CommandLine* command_line) override { | 119 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 122 // Enable experimental features for subscription restrictions. | 120 // Enable experimental features for subscription restrictions. |
| 123 command_line->AppendSwitch( | 121 command_line->AppendSwitch( |
| 124 switches::kEnableExperimentalWebPlatformFeatures); | 122 switches::kEnableExperimentalWebPlatformFeatures); |
| 125 InProcessBrowserTest::SetUpCommandLine(command_line); | 123 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 126 } | 124 } |
| 127 | 125 |
| 128 // InProcessBrowserTest: | 126 // InProcessBrowserTest: |
| 129 void SetUpOnMainThread() override { | 127 void SetUpOnMainThread() override { |
| 130 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 128 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 131 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 129 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 132 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 130 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
| 133 gcm_driver_ = static_cast<instance_id::FakeGCMDriverForInstanceID*>( | 131 gcm_driver_ = static_cast<instance_id::FakeGCMDriverForInstanceID*>( |
| 134 gcm_service_->driver()); | 132 gcm_service_->driver()); |
| 135 | 133 |
| 136 push_service_ = | 134 push_service_ = |
| 137 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); | 135 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); |
| 138 #if defined(ENABLE_NOTIFICATIONS) | |
| 139 display_service_.reset(new MessageCenterDisplayService( | 136 display_service_.reset(new MessageCenterDisplayService( |
| 140 GetBrowser()->profile(), notification_manager_.get())); | 137 GetBrowser()->profile(), notification_manager_.get())); |
| 141 notification_service()->SetNotificationDisplayServiceForTesting( | 138 notification_service()->SetNotificationDisplayServiceForTesting( |
| 142 display_service_.get()); | 139 display_service_.get()); |
| 143 #endif | |
| 144 | 140 |
| 145 LoadTestPage(); | 141 LoadTestPage(); |
| 146 InProcessBrowserTest::SetUpOnMainThread(); | 142 InProcessBrowserTest::SetUpOnMainThread(); |
| 147 } | 143 } |
| 148 | 144 |
| 149 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. | 145 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
| 150 void RestartPushService() { | 146 void RestartPushService() { |
| 151 Profile* profile = GetBrowser()->profile(); | 147 Profile* profile = GetBrowser()->profile(); |
| 152 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, | 148 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, |
| 153 nullptr); | 149 nullptr); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 167 return expectation == | 163 return expectation == |
| 168 KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 164 KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
| 169 KeepAliveOrigin::IN_FLIGHT_PUSH_MESSAGE); | 165 KeepAliveOrigin::IN_FLIGHT_PUSH_MESSAGE); |
| 170 #else | 166 #else |
| 171 return true; | 167 return true; |
| 172 #endif | 168 #endif |
| 173 } | 169 } |
| 174 | 170 |
| 175 // InProcessBrowserTest: | 171 // InProcessBrowserTest: |
| 176 void TearDown() override { | 172 void TearDown() override { |
| 177 #if defined(ENABLE_NOTIFICATIONS) | |
| 178 notification_service()->SetNotificationDisplayServiceForTesting(nullptr); | 173 notification_service()->SetNotificationDisplayServiceForTesting(nullptr); |
| 179 #endif | |
| 180 | |
| 181 InProcessBrowserTest::TearDown(); | 174 InProcessBrowserTest::TearDown(); |
| 182 } | 175 } |
| 183 | 176 |
| 184 void LoadTestPage(const std::string& path) { | 177 void LoadTestPage(const std::string& path) { |
| 185 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path)); | 178 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path)); |
| 186 } | 179 } |
| 187 | 180 |
| 188 void LoadTestPage() { LoadTestPage(GetTestURL()); } | 181 void LoadTestPage() { LoadTestPage(GetTestURL()); } |
| 189 | 182 |
| 190 void LoadTestPageWithoutManifest() { LoadTestPage(GetNoManifestTestURL()); } | 183 void LoadTestPageWithoutManifest() { LoadTestPage(GetNoManifestTestURL()); } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 226 |
| 234 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 227 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
| 235 int64_t service_worker_registration_id); | 228 int64_t service_worker_registration_id); |
| 236 | 229 |
| 237 void SendMessageAndWaitUntilHandled( | 230 void SendMessageAndWaitUntilHandled( |
| 238 const PushMessagingAppIdentifier& app_identifier, | 231 const PushMessagingAppIdentifier& app_identifier, |
| 239 const gcm::IncomingMessage& message); | 232 const gcm::IncomingMessage& message); |
| 240 | 233 |
| 241 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } | 234 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } |
| 242 | 235 |
| 243 #if defined(ENABLE_NOTIFICATIONS) | |
| 244 // To be called when delivery of a push message has finished. The |run_loop| | 236 // To be called when delivery of a push message has finished. The |run_loop| |
| 245 // will be told to quit after |messages_required| messages were received. | 237 // will be told to quit after |messages_required| messages were received. |
| 246 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, | 238 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, |
| 247 const base::Closure& done_closure) { | 239 const base::Closure& done_closure) { |
| 248 DCHECK(number_of_notifications_shown); | 240 DCHECK(number_of_notifications_shown); |
| 249 | 241 |
| 250 number_of_notifications_shown->push_back( | 242 number_of_notifications_shown->push_back( |
| 251 notification_manager_->GetNotificationCount()); | 243 notification_manager_->GetNotificationCount()); |
| 252 | 244 |
| 253 done_closure.Run(); | 245 done_closure.Run(); |
| 254 } | 246 } |
| 255 | 247 |
| 256 StubNotificationUIManager* notification_manager() const { | 248 StubNotificationUIManager* notification_manager() const { |
| 257 return notification_manager_.get(); | 249 return notification_manager_.get(); |
| 258 } | 250 } |
| 259 | 251 |
| 260 PlatformNotificationServiceImpl* notification_service() const { | 252 PlatformNotificationServiceImpl* notification_service() const { |
| 261 return PlatformNotificationServiceImpl::GetInstance(); | 253 return PlatformNotificationServiceImpl::GetInstance(); |
| 262 } | 254 } |
| 263 #endif | |
| 264 | 255 |
| 265 PushMessagingServiceImpl* push_service() const { return push_service_; } | 256 PushMessagingServiceImpl* push_service() const { return push_service_; } |
| 266 | 257 |
| 267 void SetSiteEngagementScore(const GURL& url, double score) { | 258 void SetSiteEngagementScore(const GURL& url, double score) { |
| 268 SiteEngagementService* service = | 259 SiteEngagementService* service = |
| 269 SiteEngagementService::Get(GetBrowser()->profile()); | 260 SiteEngagementService::Get(GetBrowser()->profile()); |
| 270 service->ResetScoreForURL(url, score); | 261 service->ResetScoreForURL(url, score); |
| 271 } | 262 } |
| 272 | 263 |
| 273 protected: | 264 protected: |
| 274 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } | 265 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
| 275 | 266 |
| 276 virtual std::string GetNoManifestTestURL() { | 267 virtual std::string GetNoManifestTestURL() { |
| 277 return "/push_messaging/test_no_manifest.html"; | 268 return "/push_messaging/test_no_manifest.html"; |
| 278 } | 269 } |
| 279 | 270 |
| 280 virtual Browser* GetBrowser() const { return browser(); } | 271 virtual Browser* GetBrowser() const { return browser(); } |
| 281 | 272 |
| 282 gcm::FakeGCMProfileService* gcm_service_; | 273 gcm::FakeGCMProfileService* gcm_service_; |
| 283 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; | 274 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; |
| 284 base::HistogramTester histogram_tester_; | 275 base::HistogramTester histogram_tester_; |
| 285 | 276 |
| 286 private: | 277 private: |
| 287 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 278 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| 288 PushMessagingServiceImpl* push_service_; | 279 PushMessagingServiceImpl* push_service_; |
| 289 | 280 |
| 290 #if defined(ENABLE_NOTIFICATIONS) | |
| 291 std::unique_ptr<StubNotificationUIManager> notification_manager_; | 281 std::unique_ptr<StubNotificationUIManager> notification_manager_; |
| 292 std::unique_ptr<MessageCenterDisplayService> display_service_; | 282 std::unique_ptr<MessageCenterDisplayService> display_service_; |
| 293 #endif | |
| 294 | 283 |
| 295 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 284 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
| 296 }; | 285 }; |
| 297 | 286 |
| 298 void PushMessagingBrowserTest::RequestAndAcceptPermission() { | 287 void PushMessagingBrowserTest::RequestAndAcceptPermission() { |
| 299 std::string script_result; | 288 std::string script_result; |
| 300 GetPermissionRequestManager()->set_auto_response_for_test( | 289 GetPermissionRequestManager()->set_auto_response_for_test( |
| 301 PermissionRequestManager::ACCEPT_ALL); | 290 PermissionRequestManager::ACCEPT_ALL); |
| 302 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 291 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 303 ASSERT_EQ("permission status - granted", script_result); | 292 ASSERT_EQ("permission status - granted", script_result); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1186 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1198 PushMessagingAppIdentifier app_identifier_afterwards = | 1187 PushMessagingAppIdentifier app_identifier_afterwards = |
| 1199 PushMessagingAppIdentifier::FindByServiceWorker(GetBrowser()->profile(), | 1188 PushMessagingAppIdentifier::FindByServiceWorker(GetBrowser()->profile(), |
| 1200 origin, 0LL); | 1189 origin, 0LL); |
| 1201 EXPECT_TRUE(app_identifier_afterwards.is_null()); | 1190 EXPECT_TRUE(app_identifier_afterwards.is_null()); |
| 1202 histogram_tester_.ExpectUniqueSample( | 1191 histogram_tester_.ExpectUniqueSample( |
| 1203 "PushMessaging.UnregistrationReason", | 1192 "PushMessaging.UnregistrationReason", |
| 1204 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED, 1); | 1193 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED, 1); |
| 1205 } | 1194 } |
| 1206 | 1195 |
| 1207 #if defined(ENABLE_NOTIFICATIONS) | |
| 1208 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1196 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1209 PushEventEnforcesUserVisibleNotification) { | 1197 PushEventEnforcesUserVisibleNotification) { |
| 1210 std::string script_result; | 1198 std::string script_result; |
| 1211 | 1199 |
| 1212 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); | 1200 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1213 PushMessagingAppIdentifier app_identifier = | 1201 PushMessagingAppIdentifier app_identifier = |
| 1214 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1202 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 1215 | 1203 |
| 1216 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1204 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 1217 ASSERT_EQ("false - is not controlled", script_result); | 1205 ASSERT_EQ("false - is not controlled", script_result); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 | 1450 |
| 1463 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 1451 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
| 1464 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 1452 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 1465 EXPECT_EQ("push_test_tag", | 1453 EXPECT_EQ("push_test_tag", |
| 1466 notification_manager()->GetNotificationAt(0).tag()); | 1454 notification_manager()->GetNotificationAt(0).tag()); |
| 1467 | 1455 |
| 1468 // Verify that the renderer process hasn't crashed. | 1456 // Verify that the renderer process hasn't crashed. |
| 1469 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1457 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1470 EXPECT_EQ("permission status - granted", script_result); | 1458 EXPECT_EQ("permission status - granted", script_result); |
| 1471 } | 1459 } |
| 1472 #endif | |
| 1473 | 1460 |
| 1474 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysPrompt) { | 1461 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysPrompt) { |
| 1475 std::string script_result; | 1462 std::string script_result; |
| 1476 | 1463 |
| 1477 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1464 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 1478 ASSERT_EQ("ok - service worker registered", script_result); | 1465 ASSERT_EQ("ok - service worker registered", script_result); |
| 1479 | 1466 |
| 1480 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1467 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1481 ASSERT_EQ("permission status - prompt", script_result); | 1468 ASSERT_EQ("permission status - prompt", script_result); |
| 1482 } | 1469 } |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); | 2120 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 2134 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 2121 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 2135 | 2122 |
| 2136 // After dropping the last subscription background mode is still inactive. | 2123 // After dropping the last subscription background mode is still inactive. |
| 2137 std::string script_result; | 2124 std::string script_result; |
| 2138 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 2125 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 2139 EXPECT_EQ("unsubscribe result: true", script_result); | 2126 EXPECT_EQ("unsubscribe result: true", script_result); |
| 2140 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 2127 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 2141 } | 2128 } |
| 2142 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 2129 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |