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 <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 25 matching lines...) Expand all Loading... | |
| 36 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 36 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
| 39 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
| 40 #include "components/content_settings/core/browser/host_content_settings_map.h" | 40 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 41 #include "components/content_settings/core/common/content_settings.h" | 41 #include "components/content_settings/core/common/content_settings.h" |
| 42 #include "components/content_settings/core/common/content_settings_types.h" | 42 #include "components/content_settings/core/common/content_settings_types.h" |
| 43 #include "components/gcm_driver/common/gcm_messages.h" | 43 #include "components/gcm_driver/common/gcm_messages.h" |
| 44 #include "components/gcm_driver/gcm_client.h" | 44 #include "components/gcm_driver/gcm_client.h" |
| 45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/common/content_switches.h" | |
| 46 #include "content/public/test/browser_test_utils.h" | 47 #include "content/public/test/browser_test_utils.h" |
| 47 #include "content/public/test/test_utils.h" | 48 #include "content/public/test/test_utils.h" |
| 48 #include "net/test/embedded_test_server/embedded_test_server.h" | 49 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 49 #include "ui/base/window_open_disposition.h" | 50 #include "ui/base/window_open_disposition.h" |
| 50 | 51 |
| 51 #if defined(ENABLE_BACKGROUND) | 52 #if defined(ENABLE_BACKGROUND) |
| 52 #include "chrome/browser/background/background_mode_manager.h" | 53 #include "chrome/browser/background/background_mode_manager.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 92 |
| 92 #if defined(ENABLE_NOTIFICATIONS) | 93 #if defined(ENABLE_NOTIFICATIONS) |
| 93 notification_manager_.reset(new StubNotificationUIManager); | 94 notification_manager_.reset(new StubNotificationUIManager); |
| 94 notification_service()->SetNotificationUIManagerForTesting( | 95 notification_service()->SetNotificationUIManagerForTesting( |
| 95 notification_manager()); | 96 notification_manager()); |
| 96 #endif | 97 #endif |
| 97 | 98 |
| 98 InProcessBrowserTest::SetUp(); | 99 InProcessBrowserTest::SetUp(); |
| 99 } | 100 } |
| 100 | 101 |
| 102 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 103 // Enable experiemntal features for subscription restrictions. | |
|
Avi (use Gerrit)
2016/03/01 20:02:58
typo: experimental
| |
| 104 command_line->AppendSwitch( | |
| 105 switches::kEnableExperimentalWebPlatformFeatures); | |
| 106 InProcessBrowserTest::SetUpCommandLine(command_line); | |
| 107 } | |
| 108 | |
| 101 // InProcessBrowserTest: | 109 // InProcessBrowserTest: |
| 102 void SetUpOnMainThread() override { | 110 void SetUpOnMainThread() override { |
| 103 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 111 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 104 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 112 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 105 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 113 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
| 106 gcm_service_->set_collect(true); | 114 gcm_service_->set_collect(true); |
| 107 push_service_ = | 115 push_service_ = |
| 108 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); | 116 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); |
| 109 | 117 |
| 110 LoadTestPage(); | 118 LoadTestPage(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 164 |
| 157 PermissionBubbleManager* GetPermissionBubbleManager() { | 165 PermissionBubbleManager* GetPermissionBubbleManager() { |
| 158 return PermissionBubbleManager::FromWebContents( | 166 return PermissionBubbleManager::FromWebContents( |
| 159 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 167 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 160 } | 168 } |
| 161 | 169 |
| 162 void RequestAndAcceptPermission(); | 170 void RequestAndAcceptPermission(); |
| 163 void RequestAndDenyPermission(); | 171 void RequestAndDenyPermission(); |
| 164 | 172 |
| 165 void TryToSubscribeSuccessfully( | 173 void TryToSubscribeSuccessfully( |
| 166 const std::string& expected_push_subscription_id); | 174 const std::string& expected_push_subscription_info, |
| 175 bool use_key = true); | |
| 167 | 176 |
| 168 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { | 177 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { |
| 169 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; | 178 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; |
| 170 } | 179 } |
| 171 | 180 |
| 172 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 181 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
| 173 int64_t service_worker_registration_id); | 182 int64_t service_worker_registration_id); |
| 174 | 183 |
| 175 void SendMessageAndWaitUntilHandled( | 184 void SendMessageAndWaitUntilHandled( |
| 176 const PushMessagingAppIdentifier& app_identifier, | 185 const PushMessagingAppIdentifier& app_identifier, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 | 247 |
| 239 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 248 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
| 240 std::string script_result; | 249 std::string script_result; |
| 241 GetPermissionBubbleManager()->set_auto_response_for_test( | 250 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 242 PermissionBubbleManager::DENY_ALL); | 251 PermissionBubbleManager::DENY_ALL); |
| 243 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 252 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 244 EXPECT_EQ("permission status - denied", script_result); | 253 EXPECT_EQ("permission status - denied", script_result); |
| 245 } | 254 } |
| 246 | 255 |
| 247 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 256 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( |
| 248 const std::string& expected_push_subscription_id) { | 257 const std::string& expected_push_subscription_info, |
| 258 bool use_key) { | |
| 249 std::string script_result; | 259 std::string script_result; |
| 250 | 260 |
| 251 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 261 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 252 EXPECT_EQ("ok - service worker registered", script_result); | 262 EXPECT_EQ("ok - service worker registered", script_result); |
| 253 | 263 |
| 254 RequestAndAcceptPermission(); | 264 RequestAndAcceptPermission(); |
| 255 | 265 |
| 256 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); | 266 if (use_key) { |
| 257 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_id), | 267 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); |
| 268 } else { | |
| 269 // Test backwards compatibility with old ID based subscriptions. | |
| 270 EXPECT_TRUE(RunScript("subscribePushWithoutKey()", &script_result)); | |
| 271 } | |
| 272 | |
| 273 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), | |
| 258 script_result); | 274 script_result); |
| 259 } | 275 } |
| 260 | 276 |
| 261 PushMessagingAppIdentifier | 277 PushMessagingAppIdentifier |
| 262 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 278 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
| 263 int64_t service_worker_registration_id) { | 279 int64_t service_worker_registration_id) { |
| 264 GURL origin = https_server()->GetURL("/").GetOrigin(); | 280 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 265 PushMessagingAppIdentifier app_identifier = | 281 PushMessagingAppIdentifier app_identifier = |
| 266 PushMessagingAppIdentifier::FindByServiceWorker( | 282 PushMessagingAppIdentifier::FindByServiceWorker( |
| 267 GetBrowser()->profile(), origin, service_worker_registration_id); | 283 GetBrowser()->profile(), origin, service_worker_registration_id); |
| 268 EXPECT_FALSE(app_identifier.is_null()); | 284 EXPECT_FALSE(app_identifier.is_null()); |
| 269 return app_identifier; | 285 return app_identifier; |
| 270 } | 286 } |
| 271 | 287 |
| 272 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( | 288 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( |
| 273 const PushMessagingAppIdentifier& app_identifier, | 289 const PushMessagingAppIdentifier& app_identifier, |
| 274 const gcm::IncomingMessage& message) { | 290 const gcm::IncomingMessage& message) { |
| 275 base::RunLoop run_loop; | 291 base::RunLoop run_loop; |
| 276 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 292 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
| 277 push_service()->OnMessage(app_identifier.app_id(), message); | 293 push_service()->OnMessage(app_identifier.app_id(), message); |
| 278 run_loop.Run(); | 294 run_loop.Run(); |
| 279 } | 295 } |
| 280 | 296 |
| 281 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 297 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 298 SubscribeWithoutKeySuccessNotificationsGranted) { | |
| 299 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | |
| 300 | |
| 301 PushMessagingAppIdentifier app_identifier = | |
| 302 GetAppIdentifierForServiceWorkerRegistration(0LL); | |
| 303 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 304 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | |
| 305 } | |
| 306 | |
| 307 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
| 282 SubscribeSuccessNotificationsGranted) { | 308 SubscribeSuccessNotificationsGranted) { |
| 283 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 309 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 284 | 310 |
| 285 PushMessagingAppIdentifier app_identifier = | 311 PushMessagingAppIdentifier app_identifier = |
| 286 GetAppIdentifierForServiceWorkerRegistration(0LL); | 312 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 287 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 313 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 288 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 314 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 289 } | 315 } |
| 290 | 316 |
| 291 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 317 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 292 SubscribeSuccessNotificationsPrompt) { | 318 SubscribeSuccessNotificationsPrompt) { |
| 293 std::string script_result; | 319 std::string script_result; |
| 294 | 320 |
| 295 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 321 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 296 ASSERT_EQ("ok - service worker registered", script_result); | 322 ASSERT_EQ("ok - service worker registered", script_result); |
| 297 | 323 |
| 298 GetPermissionBubbleManager()->set_auto_response_for_test( | 324 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 299 PermissionBubbleManager::ACCEPT_ALL); | 325 PermissionBubbleManager::ACCEPT_ALL); |
| 300 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 326 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); |
| 301 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 327 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 302 | 328 |
| 303 PushMessagingAppIdentifier app_identifier = | 329 PushMessagingAppIdentifier app_identifier = |
| 304 GetAppIdentifierForServiceWorkerRegistration(0LL); | 330 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 305 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 331 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 306 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 332 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 307 } | 333 } |
| 308 | 334 |
| 335 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { | |
| 336 std::string script_result; | |
| 337 | |
| 338 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | |
| 339 ASSERT_EQ("ok - service worker registered", script_result); | |
| 340 | |
| 341 RequestAndAcceptPermission(); | |
| 342 | |
| 343 ASSERT_TRUE(RunScript("subscribePushBadKey()", &script_result)); | |
| 344 EXPECT_EQ( | |
| 345 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " | |
| 346 "The provided applicationServerKey is not valid.", | |
| 347 script_result); | |
| 348 } | |
| 349 | |
| 309 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 350 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 310 SubscribeFailureNotificationsBlocked) { | 351 SubscribeFailureNotificationsBlocked) { |
| 311 std::string script_result; | 352 std::string script_result; |
| 312 | 353 |
| 313 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 354 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 314 ASSERT_EQ("ok - service worker registered", script_result); | 355 ASSERT_EQ("ok - service worker registered", script_result); |
| 315 | 356 |
| 316 RequestAndDenyPermission(); | 357 RequestAndDenyPermission(); |
| 317 | 358 |
| 318 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 359 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1315 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1275 | 1316 |
| 1276 // After dropping the last subscription background mode is still inactive. | 1317 // After dropping the last subscription background mode is still inactive. |
| 1277 std::string script_result; | 1318 std::string script_result; |
| 1278 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1319 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1279 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1320 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1280 EXPECT_EQ("unsubscribe result: true", script_result); | 1321 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1281 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1322 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1282 } | 1323 } |
| 1283 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1324 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |