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 30 matching lines...) Expand all Loading... | |
| 41 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 41 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/features.h" | 43 #include "chrome/common/features.h" |
| 44 #include "chrome/test/base/in_process_browser_test.h" | 44 #include "chrome/test/base/in_process_browser_test.h" |
| 45 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
| 46 #include "components/content_settings/core/browser/host_content_settings_map.h" | 46 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 47 #include "components/content_settings/core/common/content_settings.h" | 47 #include "components/content_settings/core/common/content_settings.h" |
| 48 #include "components/content_settings/core/common/content_settings_types.h" | 48 #include "components/content_settings/core/common/content_settings_types.h" |
| 49 #include "components/gcm_driver/common/gcm_messages.h" | 49 #include "components/gcm_driver/common/gcm_messages.h" |
| 50 #include "components/gcm_driver/gcm_client.h" | 50 #include "components/gcm_driver/gcm_client.h" |
| 51 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" | |
| 51 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
| 53 #include "content/public/test/browser_test_utils.h" | 54 #include "content/public/test/browser_test_utils.h" |
| 54 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
| 55 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 57 #include "testing/gmock/include/gmock/gmock.h" | |
| 56 #include "ui/base/window_open_disposition.h" | 58 #include "ui/base/window_open_disposition.h" |
| 57 | 59 |
| 58 #if BUILDFLAG(ENABLE_BACKGROUND) | 60 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 59 #include "chrome/browser/background/background_mode_manager.h" | 61 #include "chrome/browser/background/background_mode_manager.h" |
| 60 #endif | 62 #endif |
| 61 | 63 |
| 62 namespace { | 64 namespace { |
| 63 | 65 |
| 66 const char kManifestSenderId[] = "1234567890"; | |
| 67 | |
| 64 // NIST P-256 public key made available to tests. Must be an uncompressed | 68 // NIST P-256 public key made available to tests. Must be an uncompressed |
| 65 // point in accordance with SEC1 2.3.3. | 69 // point in accordance with SEC1 2.3.3. |
| 66 const uint8_t kApplicationServerKey[65] = { | 70 const uint8_t kApplicationServerKey[65] = { |
| 67 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, | 71 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, |
| 68 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, | 72 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, |
| 69 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, | 73 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, |
| 70 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13, | 74 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13, |
| 71 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76, | 75 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76, |
| 72 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD}; | 76 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD}; |
| 73 | 77 |
| 74 // URL-safe base64 encoded version of the |kApplicationServerKey|. | 78 // URL-safe base64 encoded version of the |kApplicationServerKey|. |
| 75 const char kEncodedApplicationServerKey[] = | 79 const char kEncodedApplicationServerKey[] = |
| 76 "BFVSaqVujqpHlzYQwWY8HmW_oXvuSMnGu78CGFNyHQx7qeMRtwNSIdNxkBOowc_tIPcf0X_ydr" | 80 "BFVSaqVujqpHlzYQwWY8HmW_oXvuSMnGu78CGFNyHQx7qeMRtwNSIdNxkBOowc_tIPcf0X_ydr" |
| 77 "YBINg1pdk8Q_0"; | 81 "YBINg1pdk8Q_0"; |
| 78 | 82 |
| 79 std::string GetTestApplicationServerKey() { | 83 std::string GetTestApplicationServerKey() { |
| 80 return std::string(kApplicationServerKey, | 84 return std::string(kApplicationServerKey, |
| 81 kApplicationServerKey + arraysize(kApplicationServerKey)); | 85 kApplicationServerKey + arraysize(kApplicationServerKey)); |
| 82 } | 86 } |
| 83 | 87 |
| 84 // Class to instantiate on the stack that is meant to be used with | 88 void LegacyRegisterCallback(const base::Closure& done_callback, |
| 85 // FakeGCMProfileService. The ::Run() method follows the signature of | 89 std::string* out_registration_id, |
| 86 // FakeGCMProfileService::UnregisterCallback. | 90 gcm::GCMClient::Result* out_result, |
| 87 class UnregistrationCallback { | 91 const std::string& registration_id, |
| 88 public: | 92 gcm::GCMClient::Result result) { |
| 89 UnregistrationCallback() | 93 *out_registration_id = registration_id; |
| 90 : message_loop_runner_(new content::MessageLoopRunner) {} | 94 *out_result = result; |
| 91 | 95 done_callback.Run(); |
| 92 void Run(const std::string& app_id) { | 96 } |
| 93 app_id_ = app_id; | |
| 94 message_loop_runner_->Quit(); | |
| 95 } | |
| 96 | |
| 97 void WaitUntilSatisfied() { message_loop_runner_->Run(); } | |
| 98 | |
| 99 const std::string& app_id() { return app_id_; } | |
| 100 | |
| 101 private: | |
| 102 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 103 std::string app_id_; | |
| 104 }; | |
| 105 | 97 |
| 106 } // namespace | 98 } // namespace |
| 107 | 99 |
| 108 class PushMessagingBrowserTest : public InProcessBrowserTest { | 100 class PushMessagingBrowserTest : public InProcessBrowserTest { |
| 109 public: | 101 public: |
| 110 PushMessagingBrowserTest() : gcm_service_(nullptr) {} | 102 PushMessagingBrowserTest() : gcm_service_(nullptr), gcm_driver_(nullptr) {} |
| 111 ~PushMessagingBrowserTest() override {} | 103 ~PushMessagingBrowserTest() override {} |
| 112 | 104 |
| 113 // InProcessBrowserTest: | 105 // InProcessBrowserTest: |
| 114 void SetUp() override { | 106 void SetUp() override { |
| 115 https_server_.reset( | 107 https_server_.reset( |
| 116 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 108 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 117 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); | 109 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); |
| 118 ASSERT_TRUE(https_server_->Start()); | 110 ASSERT_TRUE(https_server_->Start()); |
| 119 | 111 |
| 120 #if defined(ENABLE_NOTIFICATIONS) | 112 #if defined(ENABLE_NOTIFICATIONS) |
| 121 notification_manager_.reset(new StubNotificationUIManager); | 113 notification_manager_.reset(new StubNotificationUIManager); |
| 122 #endif | 114 #endif |
| 123 | 115 |
| 124 InProcessBrowserTest::SetUp(); | 116 InProcessBrowserTest::SetUp(); |
| 125 } | 117 } |
| 126 | 118 |
| 127 void SetUpCommandLine(base::CommandLine* command_line) override { | 119 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 128 // Enable experimental features for subscription restrictions. | 120 // Enable experimental features for subscription restrictions. |
| 129 command_line->AppendSwitch( | 121 command_line->AppendSwitch( |
| 130 switches::kEnableExperimentalWebPlatformFeatures); | 122 switches::kEnableExperimentalWebPlatformFeatures); |
| 131 InProcessBrowserTest::SetUpCommandLine(command_line); | 123 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 132 } | 124 } |
| 133 | 125 |
| 134 // InProcessBrowserTest: | 126 // InProcessBrowserTest: |
| 135 void SetUpOnMainThread() override { | 127 void SetUpOnMainThread() override { |
| 136 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 128 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 137 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 129 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 138 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 130 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
| 139 gcm_service_->set_collect(true); | 131 gcm_driver_ = static_cast<instance_id::FakeGCMDriverForInstanceID*>( |
| 132 gcm_service_->driver()); | |
| 133 | |
| 140 push_service_ = | 134 push_service_ = |
| 141 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); | 135 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); |
| 142 #if defined(ENABLE_NOTIFICATIONS) | 136 #if defined(ENABLE_NOTIFICATIONS) |
| 143 display_service_.reset(new MessageCenterDisplayService( | 137 display_service_.reset(new MessageCenterDisplayService( |
| 144 GetBrowser()->profile(), notification_manager_.get())); | 138 GetBrowser()->profile(), notification_manager_.get())); |
| 145 notification_service()->SetNotificationDisplayServiceForTesting( | 139 notification_service()->SetNotificationDisplayServiceForTesting( |
| 146 display_service_.get()); | 140 display_service_.get()); |
| 147 #endif | 141 #endif |
| 148 | 142 |
| 149 LoadTestPage(); | 143 LoadTestPage(); |
| 150 InProcessBrowserTest::SetUpOnMainThread(); | 144 InProcessBrowserTest::SetUpOnMainThread(); |
| 151 } | 145 } |
| 152 | 146 |
| 147 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. | |
| 153 void RestartPushService() { | 148 void RestartPushService() { |
| 154 Profile* profile = GetBrowser()->profile(); | 149 Profile* profile = GetBrowser()->profile(); |
| 155 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, | 150 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, |
| 156 nullptr); | 151 nullptr); |
| 157 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); | 152 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); |
| 158 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); | 153 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); |
| 159 PushMessagingServiceImpl::InitializeForProfile(profile); | 154 PushMessagingServiceImpl::InitializeForProfile(profile); |
| 160 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); | 155 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); |
| 161 } | 156 } |
| 162 | 157 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 191 |
| 197 bool RunScript(const std::string& script, std::string* result, | 192 bool RunScript(const std::string& script, std::string* result, |
| 198 content::WebContents* web_contents) { | 193 content::WebContents* web_contents) { |
| 199 if (!web_contents) | 194 if (!web_contents) |
| 200 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 195 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 201 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), | 196 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), |
| 202 script, result); | 197 script, result); |
| 203 } | 198 } |
| 204 | 199 |
| 205 gcm::GCMAppHandler* GetAppHandler() { | 200 gcm::GCMAppHandler* GetAppHandler() { |
| 206 return gcm_service()->driver()->GetAppHandler( | 201 return gcm_driver_->GetAppHandler(kPushMessagingAppIdentifierPrefix); |
| 207 kPushMessagingAppIdentifierPrefix); | |
| 208 } | 202 } |
| 209 | 203 |
| 210 PermissionBubbleManager* GetPermissionBubbleManager() { | 204 PermissionBubbleManager* GetPermissionBubbleManager() { |
| 211 return PermissionBubbleManager::FromWebContents( | 205 return PermissionBubbleManager::FromWebContents( |
| 212 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 206 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 213 } | 207 } |
| 214 | 208 |
| 209 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. | |
| 215 void RequestAndAcceptPermission(); | 210 void RequestAndAcceptPermission(); |
| 211 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. | |
| 216 void RequestAndDenyPermission(); | 212 void RequestAndDenyPermission(); |
| 217 | 213 |
| 218 void TryToSubscribeSuccessfully( | 214 // Sets out_token to the subscription token (not including server URL). |
| 219 const std::string& expected_push_subscription_info, | 215 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
| 220 bool use_key = true); | 216 void SubscribeSuccessfully(bool use_key = true, |
| 217 std::string* out_token = nullptr); | |
| 221 | 218 |
| 222 std::string GetEndpointForSubscriptionId(const std::string& subscription_id, | 219 // Legacy subscribe path using GCMDriver rather than Instance IDs. Only |
| 223 bool standard_protocol = true) { | 220 // for testing that we maintain support for existing stored registrations. |
| 224 return push_service()->GetEndpoint(standard_protocol).spec() + | 221 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
| 225 subscription_id; | 222 void LegacySubscribeSuccessfully(std::string* out_registration_id); |
| 226 } | 223 |
| 224 // Strips server URL from a registration endpoint to get subscription token. | |
| 225 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. | |
| 226 void EndpointToToken(const std::string& endpoint, | |
| 227 bool standard_protocol = true, | |
| 228 std::string* out_token = nullptr); | |
| 227 | 229 |
| 228 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 230 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
| 229 int64_t service_worker_registration_id); | 231 int64_t service_worker_registration_id); |
| 230 | 232 |
| 231 void SendMessageAndWaitUntilHandled( | 233 void SendMessageAndWaitUntilHandled( |
| 232 const PushMessagingAppIdentifier& app_identifier, | 234 const PushMessagingAppIdentifier& app_identifier, |
| 233 const gcm::IncomingMessage& message); | 235 const gcm::IncomingMessage& message); |
| 234 | 236 |
| 235 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } | 237 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } |
| 236 | 238 |
| 237 gcm::FakeGCMProfileService* gcm_service() const { return gcm_service_; } | |
| 238 | |
| 239 #if defined(ENABLE_NOTIFICATIONS) | 239 #if defined(ENABLE_NOTIFICATIONS) |
| 240 // To be called when delivery of a push message has finished. The |run_loop| | 240 // To be called when delivery of a push message has finished. The |run_loop| |
| 241 // will be told to quit after |messages_required| messages were received. | 241 // will be told to quit after |messages_required| messages were received. |
| 242 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, | 242 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, |
| 243 const base::Closure& done_closure) { | 243 const base::Closure& done_closure) { |
| 244 DCHECK(number_of_notifications_shown); | 244 DCHECK(number_of_notifications_shown); |
| 245 | 245 |
| 246 number_of_notifications_shown->push_back( | 246 number_of_notifications_shown->push_back( |
| 247 notification_manager_->GetNotificationCount()); | 247 notification_manager_->GetNotificationCount()); |
| 248 | 248 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 266 service->ResetScoreForURL(url, score); | 266 service->ResetScoreForURL(url, score); |
| 267 } | 267 } |
| 268 | 268 |
| 269 protected: | 269 protected: |
| 270 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } | 270 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
| 271 | 271 |
| 272 virtual Browser* GetBrowser() const { return browser(); } | 272 virtual Browser* GetBrowser() const { return browser(); } |
| 273 | 273 |
| 274 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } | 274 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } |
| 275 | 275 |
| 276 private: | 276 protected: |
| 277 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 277 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| 278 gcm::FakeGCMProfileService* gcm_service_; | 278 gcm::FakeGCMProfileService* gcm_service_; |
| 279 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; | |
| 279 PushMessagingServiceImpl* push_service_; | 280 PushMessagingServiceImpl* push_service_; |
| 280 base::HistogramTester histogram_tester_; | 281 base::HistogramTester histogram_tester_; |
| 281 | 282 |
| 282 #if defined(ENABLE_NOTIFICATIONS) | 283 #if defined(ENABLE_NOTIFICATIONS) |
| 283 std::unique_ptr<StubNotificationUIManager> notification_manager_; | 284 std::unique_ptr<StubNotificationUIManager> notification_manager_; |
| 284 std::unique_ptr<MessageCenterDisplayService> display_service_; | 285 std::unique_ptr<MessageCenterDisplayService> display_service_; |
| 285 #endif | 286 #endif |
| 286 | 287 |
| 287 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 288 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
| 288 }; | 289 }; |
| 289 | 290 |
| 290 class PushMessagingBrowserTestEmptySubscriptionOptions | 291 class PushMessagingBrowserTestEmptySubscriptionOptions |
| 291 : public PushMessagingBrowserTest { | 292 : public PushMessagingBrowserTest { |
| 292 std::string GetTestURL() override { | 293 std::string GetTestURL() override { |
| 293 return "/push_messaging/test_no_subscription_options.html"; | 294 return "/push_messaging/test_no_subscription_options.html"; |
| 294 } | 295 } |
| 295 }; | 296 }; |
| 296 | 297 |
| 297 void PushMessagingBrowserTest::RequestAndAcceptPermission() { | 298 void PushMessagingBrowserTest::RequestAndAcceptPermission() { |
| 298 std::string script_result; | 299 std::string script_result; |
| 299 GetPermissionBubbleManager()->set_auto_response_for_test( | 300 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 300 PermissionBubbleManager::ACCEPT_ALL); | 301 PermissionBubbleManager::ACCEPT_ALL); |
| 301 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 302 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 302 EXPECT_EQ("permission status - granted", script_result); | 303 ASSERT_EQ("permission status - granted", script_result); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 306 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
| 306 std::string script_result; | 307 std::string script_result; |
| 307 GetPermissionBubbleManager()->set_auto_response_for_test( | 308 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 308 PermissionBubbleManager::DENY_ALL); | 309 PermissionBubbleManager::DENY_ALL); |
| 309 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 310 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 310 EXPECT_EQ("permission status - denied", script_result); | 311 ASSERT_EQ("permission status - denied", script_result); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 314 void PushMessagingBrowserTest::SubscribeSuccessfully(bool use_key, |
| 314 const std::string& expected_push_subscription_info, | 315 std::string* out_token) { |
| 315 bool use_key) { | |
| 316 std::string script_result; | 316 std::string script_result; |
| 317 | 317 |
| 318 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 318 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 319 EXPECT_EQ("ok - service worker registered", script_result); | 319 ASSERT_EQ("ok - service worker registered", script_result); |
| 320 | 320 |
| 321 RequestAndAcceptPermission(); | 321 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 322 | 322 |
| 323 if (use_key) { | 323 if (use_key) { |
| 324 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 324 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| 325 ASSERT_EQ("manifest removed", script_result); | 325 ASSERT_EQ("manifest removed", script_result); |
| 326 | 326 |
| 327 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 327 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 328 } else { | 328 } else { |
| 329 // Test backwards compatibility with old ID based subscriptions. | 329 // Test backwards compatibility with old ID based subscriptions. |
| 330 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 330 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 331 } | 331 } |
| 332 | 332 |
| 333 EXPECT_EQ( | 333 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result, use_key, out_token)); |
| 334 GetEndpointForSubscriptionId(expected_push_subscription_info, use_key), | 334 } |
| 335 script_result); | 335 |
| 336 void PushMessagingBrowserTest::LegacySubscribeSuccessfully( | |
| 337 std::string* out_registration_id) { | |
| 338 // Create a non-InstanceID GCM registration. We have to directly access | |
|
Peter Beverloo
2016/06/02 15:53:17
micro nit: no 'we' in comments. I also question th
johnme
2016/06/07 14:16:42
Removed we. The 2nd part seems useful in explainin
| |
| 339 // GCMDriver, since this codepath has been deleted from Push. | |
| 340 DCHECK(out_registration_id); | |
| 341 | |
| 342 std::string script_result; | |
| 343 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | |
| 344 ASSERT_EQ("ok - service worker registered", script_result); | |
| 345 | |
| 346 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); | |
| 347 | |
| 348 GURL requesting_origin = https_server()->GetURL("/").GetOrigin(); | |
| 349 int64_t service_worker_registration_id = 0LL; | |
| 350 PushMessagingAppIdentifier app_identifier = | |
| 351 PushMessagingAppIdentifier::Generate(requesting_origin, | |
| 352 service_worker_registration_id); | |
| 353 push_service_->IncreasePushSubscriptionCount(1, true /* is_pending */); | |
| 354 | |
| 355 { | |
| 356 base::RunLoop run_loop; | |
| 357 gcm::GCMClient::Result register_result = gcm::GCMClient::UNKNOWN_ERROR; | |
| 358 gcm_driver_->Register( | |
| 359 app_identifier.app_id(), {kManifestSenderId}, | |
| 360 base::Bind(&LegacyRegisterCallback, run_loop.QuitClosure(), | |
| 361 out_registration_id, ®ister_result)); | |
| 362 run_loop.Run(); | |
| 363 ASSERT_EQ(gcm::GCMClient::SUCCESS, register_result); | |
| 364 } | |
| 365 | |
| 366 app_identifier.PersistToPrefs(GetBrowser()->profile()); | |
| 367 push_service_->IncreasePushSubscriptionCount(1, false /* is_pending */); | |
| 368 push_service_->DecreasePushSubscriptionCount(1, true /* was_pending */); | |
| 369 | |
| 370 { | |
| 371 base::RunLoop run_loop; | |
| 372 push_service_->StorePushSubscriptionForTesting( | |
| 373 GetBrowser()->profile(), | |
| 374 requesting_origin, | |
| 375 service_worker_registration_id, | |
| 376 *out_registration_id, | |
| 377 kManifestSenderId, | |
| 378 run_loop.QuitClosure()); | |
| 379 run_loop.Run(); | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 void PushMessagingBrowserTest::EndpointToToken(const std::string& endpoint, | |
| 384 bool standard_protocol, | |
| 385 std::string* out_token) { | |
|
Peter Beverloo
2016/06/02 15:53:17
This file has an inconsistency between requiring o
johnme
2016/06/07 14:16:42
Done. Made them all optional, since there are 21 c
| |
| 386 size_t last_slash = endpoint.rfind('/'); | |
| 387 | |
| 388 ASSERT_EQ(endpoint.substr(0, last_slash + 1), | |
| 389 push_service()->GetEndpoint(standard_protocol).spec()); | |
| 390 | |
| 391 // Generous token sanity check. | |
| 392 size_t min_token_length = 5; | |
|
Peter Beverloo
2016/06/02 15:53:17
Why 5? Why not >0? If there is no known size, let'
johnme
2016/06/07 14:16:42
Done (now only check it's non-empty).
| |
| 393 ASSERT_LT(last_slash, endpoint.length() - min_token_length); | |
| 394 | |
| 395 if (out_token) | |
| 396 *out_token = endpoint.substr(last_slash + 1); | |
| 336 } | 397 } |
| 337 | 398 |
| 338 PushMessagingAppIdentifier | 399 PushMessagingAppIdentifier |
| 339 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 400 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
| 340 int64_t service_worker_registration_id) { | 401 int64_t service_worker_registration_id) { |
| 341 GURL origin = https_server()->GetURL("/").GetOrigin(); | 402 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 342 PushMessagingAppIdentifier app_identifier = | 403 PushMessagingAppIdentifier app_identifier = |
| 343 PushMessagingAppIdentifier::FindByServiceWorker( | 404 PushMessagingAppIdentifier::FindByServiceWorker( |
| 344 GetBrowser()->profile(), origin, service_worker_registration_id); | 405 GetBrowser()->profile(), origin, service_worker_registration_id); |
| 345 EXPECT_FALSE(app_identifier.is_null()); | 406 EXPECT_FALSE(app_identifier.is_null()); |
| 346 return app_identifier; | 407 return app_identifier; |
| 347 } | 408 } |
| 348 | 409 |
| 349 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( | 410 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( |
| 350 const PushMessagingAppIdentifier& app_identifier, | 411 const PushMessagingAppIdentifier& app_identifier, |
| 351 const gcm::IncomingMessage& message) { | 412 const gcm::IncomingMessage& message) { |
| 352 base::RunLoop run_loop; | 413 base::RunLoop run_loop; |
| 353 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 414 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
| 354 push_service()->OnMessage(app_identifier.app_id(), message); | 415 push_service()->OnMessage(app_identifier.app_id(), message); |
| 355 run_loop.Run(); | 416 run_loop.Run(); |
| 356 } | 417 } |
| 357 | 418 |
| 358 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 419 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 359 SubscribeWithoutKeySuccessNotificationsGranted) { | 420 SubscribeWithoutKeySuccessNotificationsGranted) { |
| 360 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 421 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */)); |
| 361 | 422 EXPECT_EQ(kManifestSenderId, gcm_driver_->last_gettoken_authorized_entity()); |
| 362 PushMessagingAppIdentifier app_identifier = | 423 EXPECT_EQ(GetAppIdentifierForServiceWorkerRegistration(0LL).app_id(), |
| 363 GetAppIdentifierForServiceWorkerRegistration(0LL); | 424 gcm_driver_->last_gettoken_app_id()); |
| 364 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 365 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | |
| 366 } | 425 } |
| 367 | 426 |
| 368 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 427 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 369 SubscribeSuccessNotificationsGranted) { | 428 SubscribeSuccessNotificationsGranted) { |
| 370 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 429 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 371 | |
| 372 PushMessagingAppIdentifier app_identifier = | |
| 373 GetAppIdentifierForServiceWorkerRegistration(0LL); | |
| 374 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 375 EXPECT_EQ(kEncodedApplicationServerKey, | 430 EXPECT_EQ(kEncodedApplicationServerKey, |
| 376 gcm_service()->last_registered_sender_ids()[0]); | 431 gcm_driver_->last_gettoken_authorized_entity()); |
| 432 EXPECT_EQ(GetAppIdentifierForServiceWorkerRegistration(0LL).app_id(), | |
| 433 gcm_driver_->last_gettoken_app_id()); | |
| 377 } | 434 } |
| 378 | 435 |
| 379 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 436 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 380 SubscribeSuccessNotificationsPrompt) { | 437 SubscribeSuccessNotificationsPrompt) { |
| 381 std::string script_result; | 438 std::string script_result; |
| 382 | 439 |
| 383 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 440 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 384 ASSERT_EQ("ok - service worker registered", script_result); | 441 ASSERT_EQ("ok - service worker registered", script_result); |
| 385 | 442 |
| 386 GetPermissionBubbleManager()->set_auto_response_for_test( | 443 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 387 PermissionBubbleManager::ACCEPT_ALL); | 444 PermissionBubbleManager::ACCEPT_ALL); |
| 388 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 445 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 389 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 446 // Both of these methods EXPECT that they succeed. |
| 390 | 447 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); |
| 391 PushMessagingAppIdentifier app_identifier = | 448 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 392 GetAppIdentifierForServiceWorkerRegistration(0LL); | |
| 393 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 394 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 395 gcm_service()->last_registered_sender_ids()[0]); | |
| 396 } | 449 } |
| 397 | 450 |
| 398 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { | 451 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { |
| 399 std::string script_result; | 452 std::string script_result; |
| 400 | 453 |
| 401 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 454 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 402 ASSERT_EQ("ok - service worker registered", script_result); | 455 ASSERT_EQ("ok - service worker registered", script_result); |
| 403 | 456 |
| 404 RequestAndAcceptPermission(); | 457 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 405 | 458 |
| 406 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); | 459 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); |
| 407 EXPECT_EQ( | 460 EXPECT_EQ( |
| 408 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " | 461 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " |
| 409 "The provided applicationServerKey is not valid.", | 462 "The provided applicationServerKey is not valid.", |
| 410 script_result); | 463 script_result); |
| 411 } | 464 } |
| 412 | 465 |
| 413 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 466 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 414 SubscribeFailureNotificationsBlocked) { | 467 SubscribeFailureNotificationsBlocked) { |
| 415 std::string script_result; | 468 std::string script_result; |
| 416 | 469 |
| 417 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 470 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 418 ASSERT_EQ("ok - service worker registered", script_result); | 471 ASSERT_EQ("ok - service worker registered", script_result); |
| 419 | 472 |
| 420 RequestAndDenyPermission(); | 473 ASSERT_NO_FATAL_FAILURE(RequestAndDenyPermission()); |
| 421 | 474 |
| 422 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 475 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 423 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 476 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 424 script_result); | 477 script_result); |
| 425 } | 478 } |
| 426 | 479 |
| 427 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { | 480 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { |
| 428 std::string script_result; | 481 std::string script_result; |
| 429 | 482 |
| 430 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 483 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 431 ASSERT_EQ("ok - service worker registered", script_result); | 484 ASSERT_EQ("ok - service worker registered", script_result); |
| 432 | 485 |
| 433 RequestAndAcceptPermission(); | 486 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 434 | 487 |
| 435 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 488 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| 436 ASSERT_EQ("manifest removed", script_result); | 489 ASSERT_EQ("manifest removed", script_result); |
| 437 | 490 |
| 438 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 491 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 439 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing", | 492 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing", |
| 440 script_result); | 493 script_result); |
| 441 } | 494 } |
| 442 | 495 |
| 443 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { | 496 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { |
| 444 std::string script_result; | 497 std::string script_result; |
| 445 | 498 |
| 446 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 499 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 447 ASSERT_EQ("ok - service worker registered", script_result); | 500 ASSERT_EQ("ok - service worker registered", script_result); |
| 448 | 501 |
| 449 RequestAndAcceptPermission(); | 502 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 450 | 503 |
| 451 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); | 504 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); |
| 452 ASSERT_EQ("sender id removed from manifest", script_result); | 505 ASSERT_EQ("sender id removed from manifest", script_result); |
| 453 | 506 |
| 454 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 507 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 455 EXPECT_EQ( | 508 EXPECT_EQ( |
| 456 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 509 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 457 script_result); | 510 script_result); |
| 458 } | 511 } |
| 459 | 512 |
| 460 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, | 513 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, |
| 461 RegisterFailureEmptyPushSubscriptionOptions) { | 514 RegisterFailureEmptyPushSubscriptionOptions) { |
| 462 std::string script_result; | 515 std::string script_result; |
| 463 | 516 |
| 464 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 517 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 465 ASSERT_EQ("ok - service worker registered", script_result); | 518 ASSERT_EQ("ok - service worker registered", script_result); |
| 466 | 519 |
| 467 RequestAndAcceptPermission(); | 520 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 468 | 521 |
| 469 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 522 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 470 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 523 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 471 script_result); | 524 script_result); |
| 472 } | 525 } |
| 473 | 526 |
| 474 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { | 527 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { |
| 475 std::string script_result; | 528 std::string script_result; |
| 476 | 529 |
| 477 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 530 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 478 ASSERT_EQ("ok - service worker registered", script_result); | 531 ASSERT_EQ("ok - service worker registered", script_result); |
| 479 | 532 |
| 480 RequestAndAcceptPermission(); | 533 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 481 | 534 |
| 482 LoadTestPage(); // Reload to become controlled. | 535 LoadTestPage(); // Reload to become controlled. |
| 483 | 536 |
| 484 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 537 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 485 ASSERT_EQ("true - is controlled", script_result); | 538 ASSERT_EQ("true - is controlled", script_result); |
| 486 | 539 |
| 487 // Try to subscribe from a worker without a key. This should fail. | 540 // Try to subscribe from a worker without a key. This should fail. |
| 488 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 541 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 489 EXPECT_EQ( | 542 EXPECT_EQ( |
| 490 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 543 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 491 script_result); | 544 script_result); |
| 492 // Now run the subscribe from the service worker with a key. This | 545 // Now run the subscribe from the service worker with a key. This |
| 493 // should succeed, and write the key to the datastore. | 546 // should succeed, and write the key to the datastore. |
| 494 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); | 547 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); |
| 495 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 548 std::string token1; |
| 549 ASSERT_NO_FATAL_FAILURE( | |
| 550 EndpointToToken(script_result, true /* standard_protocol */, &token1)); | |
| 496 | 551 |
| 497 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 552 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 498 EXPECT_EQ("unsubscribe result: true", script_result); | 553 EXPECT_EQ("unsubscribe result: true", script_result); |
| 499 EXPECT_NE(push_service(), GetAppHandler()); | 554 EXPECT_NE(push_service(), GetAppHandler()); |
| 500 | 555 |
| 501 // Now run the subscribe from the service worker without a key. | 556 // Now run the subscribe from the service worker without a key. |
| 502 // In this case, the key will be read from the datastore. | 557 // In this case, the key will be read from the datastore. |
| 503 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 558 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 504 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); | 559 std::string token2; |
| 560 ASSERT_NO_FATAL_FAILURE( | |
| 561 EndpointToToken(script_result, true /* standard_protocol */, &token2)); | |
| 562 EXPECT_NE(token1, token2); | |
| 505 | 563 |
| 506 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 564 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 507 EXPECT_EQ("unsubscribe result: true", script_result); | 565 EXPECT_EQ("unsubscribe result: true", script_result); |
| 508 EXPECT_NE(push_service(), GetAppHandler()); | 566 EXPECT_NE(push_service(), GetAppHandler()); |
| 509 } | 567 } |
| 510 | 568 |
| 511 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) { | 569 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) { |
| 512 std::string script_result; | 570 std::string script_result; |
| 513 | 571 |
| 514 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 572 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 515 ASSERT_EQ("ok - service worker registered", script_result); | 573 ASSERT_EQ("ok - service worker registered", script_result); |
| 516 | 574 |
| 517 RequestAndAcceptPermission(); | 575 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 518 | 576 |
| 519 LoadTestPage(); // Reload to become controlled. | 577 LoadTestPage(); // Reload to become controlled. |
| 520 | 578 |
| 521 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 579 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 522 ASSERT_EQ("true - is controlled", script_result); | 580 ASSERT_EQ("true - is controlled", script_result); |
| 523 | 581 |
| 524 // Try to subscribe from a worker without a key. This should fail. | 582 // Try to subscribe from a worker without a key. This should fail. |
| 525 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 583 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 526 EXPECT_EQ( | 584 EXPECT_EQ( |
| 527 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 585 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 528 script_result); | 586 script_result); |
| 529 EXPECT_NE(push_service(), GetAppHandler()); | 587 EXPECT_NE(push_service(), GetAppHandler()); |
| 530 | 588 |
| 531 // Run the subscription from the document without a key, this will trigger | 589 // Run the subscription from the document without a key, this will trigger |
| 532 // the code to read sender id from the manifest and will write it to the | 590 // the code to read sender id from the manifest and will write it to the |
| 533 // datastore. | 591 // datastore. |
| 534 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 592 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 535 EXPECT_EQ(GetEndpointForSubscriptionId("1-0", false), script_result); | 593 std::string token1; |
| 594 ASSERT_NO_FATAL_FAILURE( | |
| 595 EndpointToToken(script_result, false /* standard_protocol */, &token1)); | |
| 536 | 596 |
| 537 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 597 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 538 EXPECT_EQ("unsubscribe result: true", script_result); | 598 EXPECT_EQ("unsubscribe result: true", script_result); |
| 539 EXPECT_NE(push_service(), GetAppHandler()); | 599 EXPECT_NE(push_service(), GetAppHandler()); |
| 540 | 600 |
| 541 // Now run the subscribe from the service worker without a key. | 601 // Now run the subscribe from the service worker without a key. |
| 542 // In this case, the sender id will be read from the datastore. | 602 // In this case, the sender id will be read from the datastore. |
| 543 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 603 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 544 EXPECT_EQ(GetEndpointForSubscriptionId("1-1", false), script_result); | 604 std::string token2; |
| 605 ASSERT_NO_FATAL_FAILURE( | |
| 606 EndpointToToken(script_result, false /* standard_protocol */, &token2)); | |
| 607 EXPECT_NE(token1, token2); | |
| 545 | 608 |
| 546 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 609 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 547 EXPECT_EQ("unsubscribe result: true", script_result); | 610 EXPECT_EQ("unsubscribe result: true", script_result); |
| 548 EXPECT_NE(push_service(), GetAppHandler()); | 611 EXPECT_NE(push_service(), GetAppHandler()); |
| 549 } | 612 } |
| 550 | 613 |
| 551 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 614 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
| 552 #if defined(OS_WIN) || defined(OS_LINUX) | 615 #if defined(OS_WIN) || defined(OS_LINUX) |
| 553 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 616 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
| 554 #else | 617 #else |
| 555 #define MAYBE_SubscribePersisted SubscribePersisted | 618 #define MAYBE_SubscribePersisted SubscribePersisted |
| 556 #endif | 619 #endif |
| 557 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { | 620 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { |
| 558 std::string script_result; | 621 std::string script_result; |
| 559 | 622 |
| 560 // First, test that Service Worker registration IDs are assigned in order of | 623 // First, test that Service Worker registration IDs are assigned in order of |
| 561 // registering the Service Workers, and the (fake) push subscription ids are | 624 // registering the Service Workers, and the (fake) push subscription ids are |
| 562 // assigned in order of push subscription (even when these orders are | 625 // assigned in order of push subscription (even when these orders are |
| 563 // different). | 626 // different). |
| 564 | 627 |
| 565 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 628 std::string token1; |
| 629 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); | |
| 566 PushMessagingAppIdentifier sw0_identifier = | 630 PushMessagingAppIdentifier sw0_identifier = |
| 567 GetAppIdentifierForServiceWorkerRegistration(0LL); | 631 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 568 EXPECT_EQ(sw0_identifier.app_id(), gcm_service()->last_registered_app_id()); | 632 EXPECT_EQ(sw0_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
| 569 | 633 |
| 570 LoadTestPage("/push_messaging/subscope1/test.html"); | 634 LoadTestPage("/push_messaging/subscope1/test.html"); |
| 571 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 635 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 572 ASSERT_EQ("ok - service worker registered", script_result); | 636 ASSERT_EQ("ok - service worker registered", script_result); |
| 573 | 637 |
| 574 LoadTestPage("/push_messaging/subscope2/test.html"); | 638 LoadTestPage("/push_messaging/subscope2/test.html"); |
| 575 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 639 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 576 ASSERT_EQ("ok - service worker registered", script_result); | 640 ASSERT_EQ("ok - service worker registered", script_result); |
| 577 | 641 |
| 578 // Note that we need to reload the page after registering, otherwise | 642 // Note that we need to reload the page after registering, otherwise |
| 579 // navigator.serviceWorker.ready is going to be resolved with the parent | 643 // navigator.serviceWorker.ready is going to be resolved with the parent |
| 580 // Service Worker which still controls the page. | 644 // Service Worker which still controls the page. |
| 581 LoadTestPage("/push_messaging/subscope2/test.html"); | 645 LoadTestPage("/push_messaging/subscope2/test.html"); |
| 582 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 646 std::string token2; |
| 647 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token2)); | |
| 648 EXPECT_NE(token1, token2); | |
| 583 PushMessagingAppIdentifier sw2_identifier = | 649 PushMessagingAppIdentifier sw2_identifier = |
| 584 GetAppIdentifierForServiceWorkerRegistration(2LL); | 650 GetAppIdentifierForServiceWorkerRegistration(2LL); |
| 585 EXPECT_EQ(sw2_identifier.app_id(), gcm_service()->last_registered_app_id()); | 651 EXPECT_EQ(sw2_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
| 586 | 652 |
| 587 LoadTestPage("/push_messaging/subscope1/test.html"); | 653 LoadTestPage("/push_messaging/subscope1/test.html"); |
| 588 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); | 654 std::string token3; |
| 655 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token3)); | |
| 656 EXPECT_NE(token1, token3); | |
| 657 EXPECT_NE(token2, token3); | |
| 589 PushMessagingAppIdentifier sw1_identifier = | 658 PushMessagingAppIdentifier sw1_identifier = |
| 590 GetAppIdentifierForServiceWorkerRegistration(1LL); | 659 GetAppIdentifierForServiceWorkerRegistration(1LL); |
| 591 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 660 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
| 592 | 661 |
| 593 // Now test that the Service Worker registration IDs and push subscription IDs | 662 // Now test that the Service Worker registration IDs and push subscription IDs |
| 594 // generated above were persisted to SW storage, by checking that they are | 663 // generated above were persisted to SW storage, by checking that they are |
| 595 // unchanged despite requesting them in a different order. | 664 // unchanged despite requesting them in a different order. |
| 596 // TODO(johnme): Ideally we would restart the browser at this point to check | 665 // TODO(johnme): Ideally we would restart the browser at this point to check |
| 597 // they were persisted to disk, but that's not currently possible since the | 666 // they were persisted to disk, but that's not currently possible since the |
| 598 // test server uses random port numbers for each test (even PRE_Foo and Foo), | 667 // test server uses random port numbers for each test (even PRE_Foo and Foo), |
| 599 // so we wouldn't be able to load the test pages with the same origin. | 668 // so we wouldn't be able to load the test pages with the same origin. |
| 600 | 669 |
| 601 LoadTestPage("/push_messaging/subscope1/test.html"); | 670 LoadTestPage("/push_messaging/subscope1/test.html"); |
| 602 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); | 671 std::string token4; |
| 603 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 672 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token4)); |
| 673 EXPECT_EQ(token3, token4); | |
| 674 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); | |
| 604 | 675 |
| 605 LoadTestPage("/push_messaging/subscope2/test.html"); | 676 LoadTestPage("/push_messaging/subscope2/test.html"); |
| 606 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 677 std::string token5; |
| 607 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 678 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token5)); |
| 679 EXPECT_EQ(token2, token5); | |
| 680 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); | |
| 608 | 681 |
| 609 LoadTestPage(); | 682 LoadTestPage(); |
| 610 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 683 std::string token6; |
| 611 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 684 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token6)); |
| 685 EXPECT_EQ(token1, token6); | |
| 686 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); | |
| 612 } | 687 } |
| 613 | 688 |
| 614 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) { | 689 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) { |
| 615 // This test restarts the push service to simulate restarting the browser. | 690 // This test restarts the push service to simulate restarting the browser. |
| 616 | 691 |
| 617 EXPECT_NE(push_service(), GetAppHandler()); | 692 EXPECT_NE(push_service(), GetAppHandler()); |
| 618 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 693 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
| 619 EXPECT_NE(push_service(), GetAppHandler()); | 694 EXPECT_NE(push_service(), GetAppHandler()); |
| 620 | 695 |
| 621 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 696 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 622 | 697 |
| 623 EXPECT_EQ(push_service(), GetAppHandler()); | 698 EXPECT_EQ(push_service(), GetAppHandler()); |
| 624 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 699 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
| 625 EXPECT_EQ(push_service(), GetAppHandler()); | 700 EXPECT_EQ(push_service(), GetAppHandler()); |
| 626 | 701 |
| 627 // Unsubscribe. | 702 // Unsubscribe. |
| 628 std::string script_result; | 703 std::string script_result; |
| 629 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 630 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 704 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 631 EXPECT_EQ("unsubscribe result: true", script_result); | 705 EXPECT_EQ("unsubscribe result: true", script_result); |
| 632 | 706 |
| 633 EXPECT_NE(push_service(), GetAppHandler()); | 707 EXPECT_NE(push_service(), GetAppHandler()); |
| 634 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 708 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
| 635 EXPECT_NE(push_service(), GetAppHandler()); | 709 EXPECT_NE(push_service(), GetAppHandler()); |
| 636 } | 710 } |
| 637 | 711 |
| 638 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 712 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| 639 std::string script_result; | 713 std::string script_result; |
| 640 | 714 |
| 641 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 715 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 642 | |
| 643 PushMessagingAppIdentifier app_identifier = | 716 PushMessagingAppIdentifier app_identifier = |
| 644 GetAppIdentifierForServiceWorkerRegistration(0LL); | 717 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 645 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 646 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 647 gcm_service()->last_registered_sender_ids()[0]); | |
| 648 | 718 |
| 649 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 719 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 650 ASSERT_EQ("false - is not controlled", script_result); | 720 ASSERT_EQ("false - is not controlled", script_result); |
| 651 | 721 |
| 652 LoadTestPage(); // Reload to become controlled. | 722 LoadTestPage(); // Reload to become controlled. |
| 653 | 723 |
| 654 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 724 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 655 ASSERT_EQ("true - is controlled", script_result); | 725 ASSERT_EQ("true - is controlled", script_result); |
| 656 | 726 |
| 657 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 727 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
| 658 gcm::IncomingMessage message; | 728 gcm::IncomingMessage message; |
| 659 message.sender_id = GetTestApplicationServerKey(); | 729 message.sender_id = GetTestApplicationServerKey(); |
| 660 message.raw_data = "testdata"; | 730 message.raw_data = "testdata"; |
| 661 message.decrypted = true; | 731 message.decrypted = true; |
| 662 push_service()->OnMessage(app_identifier.app_id(), message); | 732 push_service()->OnMessage(app_identifier.app_id(), message); |
| 663 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); | 733 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); |
| 664 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 734 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 665 EXPECT_EQ("testdata", script_result); | 735 EXPECT_EQ("testdata", script_result); |
| 666 } | 736 } |
| 667 | 737 |
| 668 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { | 738 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { |
| 669 std::string script_result; | 739 std::string script_result; |
| 670 | 740 |
| 671 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 741 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 672 | |
| 673 PushMessagingAppIdentifier app_identifier = | 742 PushMessagingAppIdentifier app_identifier = |
| 674 GetAppIdentifierForServiceWorkerRegistration(0LL); | 743 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 675 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 676 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 677 gcm_service()->last_registered_sender_ids()[0]); | |
| 678 | 744 |
| 679 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 745 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 680 ASSERT_EQ("false - is not controlled", script_result); | 746 ASSERT_EQ("false - is not controlled", script_result); |
| 681 | 747 |
| 682 LoadTestPage(); // Reload to become controlled. | 748 LoadTestPage(); // Reload to become controlled. |
| 683 | 749 |
| 684 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 750 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 685 ASSERT_EQ("true - is controlled", script_result); | 751 ASSERT_EQ("true - is controlled", script_result); |
| 686 | 752 |
| 687 gcm::IncomingMessage message; | 753 gcm::IncomingMessage message; |
| 688 message.sender_id = GetTestApplicationServerKey(); | 754 message.sender_id = GetTestApplicationServerKey(); |
| 689 message.decrypted = false; | 755 message.decrypted = false; |
| 690 | 756 |
| 691 push_service()->OnMessage(app_identifier.app_id(), message); | 757 push_service()->OnMessage(app_identifier.app_id(), message); |
| 692 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 758 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 693 EXPECT_EQ("[NULL]", script_result); | 759 EXPECT_EQ("[NULL]", script_result); |
| 694 } | 760 } |
| 695 | 761 |
| 696 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 762 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| 697 std::string script_result; | 763 std::string script_result; |
| 698 | 764 |
| 699 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 765 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 700 | |
| 701 PushMessagingAppIdentifier app_identifier = | 766 PushMessagingAppIdentifier app_identifier = |
| 702 GetAppIdentifierForServiceWorkerRegistration(0LL); | 767 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 703 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 704 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 705 gcm_service()->last_registered_sender_ids()[0]); | |
| 706 | 768 |
| 707 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 769 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 708 ASSERT_EQ("false - is not controlled", script_result); | 770 ASSERT_EQ("false - is not controlled", script_result); |
| 709 | 771 |
| 710 LoadTestPage(); // Reload to become controlled. | 772 LoadTestPage(); // Reload to become controlled. |
| 711 | 773 |
| 712 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 774 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 713 ASSERT_EQ("true - is controlled", script_result); | 775 ASSERT_EQ("true - is controlled", script_result); |
| 714 | 776 |
| 715 // Unregister service worker. Sending a message should now fail. | 777 // Unregister service worker. Sending a message should now fail. |
| 716 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 778 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 717 ASSERT_EQ("service worker unregistration status: true", script_result); | 779 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 718 | 780 |
| 719 // When the push service will receive it next message, given that there is no | 781 // Unregistering the service worker doesn't yet unsubscribe from push (though |
| 720 // SW available, it should unregister |app_identifier.app_id()|. | 782 // it should), and FindByServiceWorker doesn't require a live SW. |
| 721 UnregistrationCallback callback; | 783 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 722 gcm_service()->SetUnregisterCallback( | 784 PushMessagingAppIdentifier app_identifier2 = |
| 723 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); | 785 PushMessagingAppIdentifier::FindByServiceWorker( |
| 786 GetBrowser()->profile(), origin, | |
| 787 0LL /* service_worker_registration_id */); | |
| 788 EXPECT_FALSE(app_identifier2.is_null()); | |
| 789 EXPECT_EQ(app_identifier.app_id(), app_identifier2.app_id()); | |
| 724 | 790 |
| 725 gcm::IncomingMessage message; | 791 gcm::IncomingMessage message; |
| 726 message.sender_id = GetTestApplicationServerKey(); | 792 message.sender_id = GetTestApplicationServerKey(); |
| 727 message.raw_data = "testdata"; | 793 message.raw_data = "testdata"; |
| 728 message.decrypted = true; | 794 message.decrypted = true; |
| 795 | |
| 796 base::RunLoop run_loop; | |
| 797 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | |
| 729 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 798 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
| 730 push_service()->OnMessage(app_identifier.app_id(), message); | 799 push_service()->OnMessage(app_identifier.app_id(), message); |
| 731 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); | 800 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); |
| 732 callback.WaitUntilSatisfied(); | 801 run_loop.Run(); |
| 733 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 802 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
| 734 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); | 803 |
| 804 // Now the push service has received a message and failed to find its service | |
| 805 // worker, it should have automatically unsubscribed app_identifier.app_id(). | |
| 806 PushMessagingAppIdentifier app_identifier3 = | |
| 807 PushMessagingAppIdentifier::FindByServiceWorker( | |
| 808 GetBrowser()->profile(), origin, | |
| 809 0LL /* service_worker_registration_id */); | |
| 810 EXPECT_TRUE(app_identifier3.is_null()); | |
| 735 | 811 |
| 736 // No push data should have been received. | 812 // No push data should have been received. |
| 737 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 813 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 738 EXPECT_EQ("null", script_result); | 814 EXPECT_EQ("null", script_result); |
| 739 } | 815 } |
| 740 | 816 |
| 741 #if defined(ENABLE_NOTIFICATIONS) | 817 #if defined(ENABLE_NOTIFICATIONS) |
| 742 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 818 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 743 PushEventEnforcesUserVisibleNotification) { | 819 PushEventEnforcesUserVisibleNotification) { |
| 744 std::string script_result; | 820 std::string script_result; |
| 745 | 821 |
| 746 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 822 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 747 | |
| 748 PushMessagingAppIdentifier app_identifier = | 823 PushMessagingAppIdentifier app_identifier = |
| 749 GetAppIdentifierForServiceWorkerRegistration(0LL); | 824 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 750 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 751 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 752 gcm_service()->last_registered_sender_ids()[0]); | |
| 753 | 825 |
| 754 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 826 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 755 ASSERT_EQ("false - is not controlled", script_result); | 827 ASSERT_EQ("false - is not controlled", script_result); |
| 756 | 828 |
| 757 LoadTestPage(); // Reload to become controlled. | 829 LoadTestPage(); // Reload to become controlled. |
| 758 | 830 |
| 759 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 831 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 760 ASSERT_EQ("true - is controlled", script_result); | 832 ASSERT_EQ("true - is controlled", script_result); |
| 761 | 833 |
| 762 notification_manager()->CancelAll(); | 834 notification_manager()->CancelAll(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 "PushMessaging.SESForLowBudgetOrigin"); | 943 "PushMessaging.SESForLowBudgetOrigin"); |
| 872 ASSERT_EQ(1.0, low_budget_buckets.size()); | 944 ASSERT_EQ(1.0, low_budget_buckets.size()); |
| 873 EXPECT_EQ(4, low_budget_buckets[0].min); | 945 EXPECT_EQ(4, low_budget_buckets[0].min); |
| 874 EXPECT_EQ(1, low_budget_buckets[0].count); | 946 EXPECT_EQ(1, low_budget_buckets[0].count); |
| 875 } | 947 } |
| 876 | 948 |
| 877 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 949 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 878 PushEventAllowSilentPushCommandLineFlag) { | 950 PushEventAllowSilentPushCommandLineFlag) { |
| 879 std::string script_result; | 951 std::string script_result; |
| 880 | 952 |
| 881 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 953 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 882 | |
| 883 PushMessagingAppIdentifier app_identifier = | 954 PushMessagingAppIdentifier app_identifier = |
| 884 GetAppIdentifierForServiceWorkerRegistration(0LL); | 955 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 885 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 956 EXPECT_EQ(app_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
| 886 EXPECT_EQ(kEncodedApplicationServerKey, | 957 EXPECT_EQ(kEncodedApplicationServerKey, |
| 887 gcm_service()->last_registered_sender_ids()[0]); | 958 gcm_driver_->last_gettoken_authorized_entity()); |
| 888 | 959 |
| 889 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 960 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 890 ASSERT_EQ("false - is not controlled", script_result); | 961 ASSERT_EQ("false - is not controlled", script_result); |
| 891 | 962 |
| 892 LoadTestPage(); // Reload to become controlled. | 963 LoadTestPage(); // Reload to become controlled. |
| 893 | 964 |
| 894 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 965 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 895 ASSERT_EQ("true - is controlled", script_result); | 966 ASSERT_EQ("true - is controlled", script_result); |
| 896 | 967 |
| 897 notification_manager()->CancelAll(); | 968 notification_manager()->CancelAll(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 1013 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 943 EXPECT_EQ("testdata", script_result); | 1014 EXPECT_EQ("testdata", script_result); |
| 944 | 1015 |
| 945 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 1016 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 946 } | 1017 } |
| 947 | 1018 |
| 948 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1019 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 949 PushEventEnforcesUserVisibleNotificationAfterQueue) { | 1020 PushEventEnforcesUserVisibleNotificationAfterQueue) { |
| 950 std::string script_result; | 1021 std::string script_result; |
| 951 | 1022 |
| 952 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1023 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 953 | |
| 954 PushMessagingAppIdentifier app_identifier = | 1024 PushMessagingAppIdentifier app_identifier = |
| 955 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1025 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 956 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 957 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 958 gcm_service()->last_registered_sender_ids()[0]); | |
| 959 | 1026 |
| 960 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1027 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 961 ASSERT_EQ("false - is not controlled", script_result); | 1028 ASSERT_EQ("false - is not controlled", script_result); |
| 962 | 1029 |
| 963 LoadTestPage(); // Reload to become controlled. | 1030 LoadTestPage(); // Reload to become controlled. |
| 964 | 1031 |
| 965 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1032 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 966 ASSERT_EQ("true - is controlled", script_result); | 1033 ASSERT_EQ("true - is controlled", script_result); |
| 967 | 1034 |
| 968 // Fire off two push messages in sequence, only the second one of which will | 1035 // Fire off two push messages in sequence, only the second one of which will |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 996 EXPECT_EQ(0u, number_of_notifications_shown[0]); | 1063 EXPECT_EQ(0u, number_of_notifications_shown[0]); |
| 997 EXPECT_EQ(1u, number_of_notifications_shown[1]); | 1064 EXPECT_EQ(1u, number_of_notifications_shown[1]); |
| 998 } | 1065 } |
| 999 | 1066 |
| 1000 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1067 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1001 PushEventNotificationWithoutEventWaitUntil) { | 1068 PushEventNotificationWithoutEventWaitUntil) { |
| 1002 std::string script_result; | 1069 std::string script_result; |
| 1003 content::WebContents* web_contents = | 1070 content::WebContents* web_contents = |
| 1004 GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 1071 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 1005 | 1072 |
| 1006 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1073 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1007 | |
| 1008 PushMessagingAppIdentifier app_identifier = | 1074 PushMessagingAppIdentifier app_identifier = |
| 1009 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1075 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 1010 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 1011 EXPECT_EQ(kEncodedApplicationServerKey, | |
| 1012 gcm_service()->last_registered_sender_ids()[0]); | |
| 1013 | 1076 |
| 1014 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1077 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 1015 ASSERT_EQ("false - is not controlled", script_result); | 1078 ASSERT_EQ("false - is not controlled", script_result); |
| 1016 | 1079 |
| 1017 LoadTestPage(); // Reload to become controlled. | 1080 LoadTestPage(); // Reload to become controlled. |
| 1018 | 1081 |
| 1019 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1082 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 1020 ASSERT_EQ("true - is controlled", script_result); | 1083 ASSERT_EQ("true - is controlled", script_result); |
| 1021 | 1084 |
| 1022 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1085 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1119 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1057 ASSERT_EQ("permission status - prompt", script_result); | 1120 ASSERT_EQ("permission status - prompt", script_result); |
| 1058 } | 1121 } |
| 1059 | 1122 |
| 1060 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { | 1123 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { |
| 1061 std::string script_result; | 1124 std::string script_result; |
| 1062 | 1125 |
| 1063 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1126 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 1064 ASSERT_EQ("ok - service worker registered", script_result); | 1127 ASSERT_EQ("ok - service worker registered", script_result); |
| 1065 | 1128 |
| 1066 RequestAndAcceptPermission(); | 1129 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 1067 | 1130 |
| 1068 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 1131 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 1069 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 1132 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); |
| 1070 | 1133 |
| 1071 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1134 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1072 EXPECT_EQ("permission status - granted", script_result); | 1135 EXPECT_EQ("permission status - granted", script_result); |
| 1073 } | 1136 } |
| 1074 | 1137 |
| 1075 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { | 1138 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { |
| 1076 std::string script_result; | 1139 std::string script_result; |
| 1077 | 1140 |
| 1078 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1141 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 1079 ASSERT_EQ("ok - service worker registered", script_result); | 1142 ASSERT_EQ("ok - service worker registered", script_result); |
| 1080 | 1143 |
| 1081 RequestAndDenyPermission(); | 1144 ASSERT_NO_FATAL_FAILURE(RequestAndDenyPermission()); |
| 1082 | 1145 |
| 1083 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 1146 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 1084 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 1147 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 1085 script_result); | 1148 script_result); |
| 1086 | 1149 |
| 1087 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1150 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1088 EXPECT_EQ("permission status - denied", script_result); | 1151 EXPECT_EQ("permission status - denied", script_result); |
| 1089 } | 1152 } |
| 1090 | 1153 |
| 1091 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { | 1154 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { |
| 1092 std::string script_result; | 1155 std::string script_result; |
| 1093 | 1156 |
| 1094 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1157 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 1095 EXPECT_EQ("ok - service worker registered", script_result); | 1158 EXPECT_EQ("ok - service worker registered", script_result); |
| 1096 | 1159 |
| 1097 // Resolves true if there was a subscription. | 1160 // Resolves true if there was a subscription. |
| 1098 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 1161 std::string token1; |
| 1099 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1162 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token1)); |
| 1100 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1163 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1101 EXPECT_EQ("unsubscribe result: true", script_result); | 1164 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1102 | 1165 |
| 1166 // Resolves false if there was no longer a subscription. | |
| 1167 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 1168 EXPECT_EQ("unsubscribe result: false", script_result); | |
| 1169 | |
| 1170 // TODO(johnme): Test that doesn't reject if there was a network error (should | |
| 1171 // deactivate subscription locally anyway). | |
| 1172 // TODO(johnme): Test that doesn't reject if there were other push service | |
| 1173 // errors (should deactivate subscription locally anyway). | |
| 1174 | |
| 1175 // Unsubscribing (with an existing reference to a PushSubscription), after | |
| 1176 // unregistering the Service Worker, just means push subscription isn't found. | |
| 1177 std::string token2; | |
| 1178 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token2)); | |
| 1179 EXPECT_NE(token1, token2); | |
| 1180 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | |
| 1181 ASSERT_EQ("service worker unregistration status: true", script_result); | |
| 1182 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 1183 EXPECT_EQ("unsubscribe result: false", script_result); | |
| 1184 } | |
| 1185 | |
| 1186 // Push subscriptions used to be non-InstanceID GCM registrations. We still need | |
|
Peter Beverloo
2016/06/02 15:53:17
nit: no 'we'
johnme
2016/06/07 14:16:42
Done.
| |
| 1187 // to be able to unsubscribe these, even though we no longer create new ones. | |
| 1188 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, LegacyUnsubscribeSuccess) { | |
|
Peter Beverloo
2016/06/02 15:53:17
Can we test receiving messages for `legacy` subscr
johnme
2016/06/07 14:16:42
Done
| |
| 1189 std::string script_result; | |
| 1190 | |
| 1191 // Resolves true if there was a subscription. | |
| 1192 std::string registration_id1; | |
| 1193 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(®istration_id1)); | |
| 1194 gcm_service_->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 1195 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 1196 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 1197 | |
| 1103 // Resolves false if there was no longer a subscription. | 1198 // Resolves false if there was no longer a subscription. |
| 1104 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1199 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1105 EXPECT_EQ("unsubscribe result: false", script_result); | 1200 EXPECT_EQ("unsubscribe result: false", script_result); |
| 1106 | 1201 |
| 1107 // Doesn't reject if there was a network error (deactivates subscription | 1202 // Doesn't reject if there was a network error (deactivates subscription |
| 1108 // locally anyway). | 1203 // locally anyway). |
| 1109 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */, false); | 1204 std::string registration_id2; |
| 1110 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); | 1205 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(®istration_id2)); |
| 1206 EXPECT_NE(registration_id1, registration_id2); | |
| 1207 gcm_service_->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); | |
| 1111 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1208 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1112 EXPECT_EQ("unsubscribe result: true", script_result); | 1209 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1113 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1210 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1114 EXPECT_EQ("false - not subscribed", script_result); | 1211 EXPECT_EQ("false - not subscribed", script_result); |
| 1115 | 1212 |
| 1116 // Doesn't reject if there were other push service errors (deactivates | 1213 // Doesn't reject if there were other push service errors (deactivates |
| 1117 // subscription locally anyway). | 1214 // subscription locally anyway). |
| 1118 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */, false); | 1215 std::string registration_id3; |
| 1119 gcm_service()->AddExpectedUnregisterResponse( | 1216 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(®istration_id3)); |
| 1217 EXPECT_NE(registration_id1, registration_id3); | |
| 1218 EXPECT_NE(registration_id2, registration_id3); | |
| 1219 gcm_service_->AddExpectedUnregisterResponse( | |
| 1120 gcm::GCMClient::INVALID_PARAMETER); | 1220 gcm::GCMClient::INVALID_PARAMETER); |
| 1121 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1221 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1122 EXPECT_EQ("unsubscribe result: true", script_result); | 1222 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1123 | 1223 |
| 1124 // Unsubscribing (with an existing reference to a PushSubscription), after | 1224 // Unsubscribing (with an existing reference to a PushSubscription), after |
| 1125 // unregistering the Service Worker, just means push subscription isn't found. | 1225 // unregistering the Service Worker, just means push subscription isn't found. |
| 1126 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */, false); | 1226 std::string registration_id4; |
| 1227 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(®istration_id4)); | |
| 1228 EXPECT_NE(registration_id1, registration_id4); | |
| 1229 EXPECT_NE(registration_id2, registration_id4); | |
| 1230 EXPECT_NE(registration_id3, registration_id4); | |
| 1127 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 1231 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 1128 ASSERT_EQ("service worker unregistration status: true", script_result); | 1232 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 1129 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1233 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1130 EXPECT_EQ("unsubscribe result: false", script_result); | 1234 EXPECT_EQ("unsubscribe result: false", script_result); |
| 1131 } | 1235 } |
| 1132 | 1236 |
| 1133 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1237 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1134 GlobalResetPushPermissionUnsubscribes) { | 1238 GlobalResetPushPermissionUnsubscribes) { |
| 1135 std::string script_result; | 1239 std::string script_result; |
| 1136 | 1240 |
| 1137 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1241 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1138 | 1242 |
| 1139 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1243 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1140 EXPECT_EQ("true - subscribed", script_result); | 1244 EXPECT_EQ("true - subscribed", script_result); |
| 1141 | 1245 |
| 1142 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1246 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1143 EXPECT_EQ("permission status - granted", script_result); | 1247 EXPECT_EQ("permission status - granted", script_result); |
| 1144 | 1248 |
| 1145 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1249 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1146 new content::MessageLoopRunner; | 1250 new content::MessageLoopRunner; |
| 1147 push_service()->SetContentSettingChangedCallbackForTesting( | 1251 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1159 EXPECT_EQ("permission status - prompt", script_result); | 1263 EXPECT_EQ("permission status - prompt", script_result); |
| 1160 | 1264 |
| 1161 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1265 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1162 EXPECT_EQ("false - not subscribed", script_result); | 1266 EXPECT_EQ("false - not subscribed", script_result); |
| 1163 } | 1267 } |
| 1164 | 1268 |
| 1165 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1269 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1166 LocalResetPushPermissionUnsubscribes) { | 1270 LocalResetPushPermissionUnsubscribes) { |
| 1167 std::string script_result; | 1271 std::string script_result; |
| 1168 | 1272 |
| 1169 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1273 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1170 | 1274 |
| 1171 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1275 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1172 EXPECT_EQ("true - subscribed", script_result); | 1276 EXPECT_EQ("true - subscribed", script_result); |
| 1173 | 1277 |
| 1174 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1278 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1175 EXPECT_EQ("permission status - granted", script_result); | 1279 EXPECT_EQ("permission status - granted", script_result); |
| 1176 | 1280 |
| 1177 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1281 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1178 new content::MessageLoopRunner; | 1282 new content::MessageLoopRunner; |
| 1179 push_service()->SetContentSettingChangedCallbackForTesting( | 1283 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1195 EXPECT_EQ("permission status - prompt", script_result); | 1299 EXPECT_EQ("permission status - prompt", script_result); |
| 1196 | 1300 |
| 1197 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1301 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1198 EXPECT_EQ("false - not subscribed", script_result); | 1302 EXPECT_EQ("false - not subscribed", script_result); |
| 1199 } | 1303 } |
| 1200 | 1304 |
| 1201 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1305 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1202 DenyPushPermissionUnsubscribes) { | 1306 DenyPushPermissionUnsubscribes) { |
| 1203 std::string script_result; | 1307 std::string script_result; |
| 1204 | 1308 |
| 1205 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1309 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1206 | 1310 |
| 1207 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1311 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1208 EXPECT_EQ("true - subscribed", script_result); | 1312 EXPECT_EQ("true - subscribed", script_result); |
| 1209 | 1313 |
| 1210 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1314 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1211 EXPECT_EQ("permission status - granted", script_result); | 1315 EXPECT_EQ("permission status - granted", script_result); |
| 1212 | 1316 |
| 1213 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1317 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1214 new content::MessageLoopRunner; | 1318 new content::MessageLoopRunner; |
| 1215 push_service()->SetContentSettingChangedCallbackForTesting( | 1319 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1227 EXPECT_EQ("permission status - denied", script_result); | 1331 EXPECT_EQ("permission status - denied", script_result); |
| 1228 | 1332 |
| 1229 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1333 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1230 EXPECT_EQ("false - not subscribed", script_result); | 1334 EXPECT_EQ("false - not subscribed", script_result); |
| 1231 } | 1335 } |
| 1232 | 1336 |
| 1233 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1337 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1234 GlobalResetNotificationsPermissionUnsubscribes) { | 1338 GlobalResetNotificationsPermissionUnsubscribes) { |
| 1235 std::string script_result; | 1339 std::string script_result; |
| 1236 | 1340 |
| 1237 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1341 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1238 | 1342 |
| 1239 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1343 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1240 EXPECT_EQ("true - subscribed", script_result); | 1344 EXPECT_EQ("true - subscribed", script_result); |
| 1241 | 1345 |
| 1242 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1346 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1243 EXPECT_EQ("permission status - granted", script_result); | 1347 EXPECT_EQ("permission status - granted", script_result); |
| 1244 | 1348 |
| 1245 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1349 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1246 new content::MessageLoopRunner; | 1350 new content::MessageLoopRunner; |
| 1247 push_service()->SetContentSettingChangedCallbackForTesting( | 1351 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1248 message_loop_runner->QuitClosure()); | 1352 message_loop_runner->QuitClosure()); |
| 1249 | 1353 |
| 1250 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1354 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1251 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1355 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1252 | 1356 |
| 1253 message_loop_runner->Run(); | 1357 message_loop_runner->Run(); |
| 1254 | 1358 |
| 1255 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1359 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1256 EXPECT_EQ("permission status - prompt", script_result); | 1360 EXPECT_EQ("permission status - prompt", script_result); |
| 1257 | 1361 |
| 1258 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1362 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1259 EXPECT_EQ("false - not subscribed", script_result); | 1363 EXPECT_EQ("false - not subscribed", script_result); |
| 1260 } | 1364 } |
| 1261 | 1365 |
| 1262 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1366 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1263 LocalResetNotificationsPermissionUnsubscribes) { | 1367 LocalResetNotificationsPermissionUnsubscribes) { |
| 1264 std::string script_result; | 1368 std::string script_result; |
| 1265 | 1369 |
| 1266 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1370 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1267 | 1371 |
| 1268 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1372 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1269 EXPECT_EQ("true - subscribed", script_result); | 1373 EXPECT_EQ("true - subscribed", script_result); |
| 1270 | 1374 |
| 1271 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1375 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1272 EXPECT_EQ("permission status - granted", script_result); | 1376 EXPECT_EQ("permission status - granted", script_result); |
| 1273 | 1377 |
| 1274 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1378 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1275 new content::MessageLoopRunner; | 1379 new content::MessageLoopRunner; |
| 1276 push_service()->SetContentSettingChangedCallbackForTesting( | 1380 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1288 EXPECT_EQ("permission status - prompt", script_result); | 1392 EXPECT_EQ("permission status - prompt", script_result); |
| 1289 | 1393 |
| 1290 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1394 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1291 EXPECT_EQ("false - not subscribed", script_result); | 1395 EXPECT_EQ("false - not subscribed", script_result); |
| 1292 } | 1396 } |
| 1293 | 1397 |
| 1294 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1398 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1295 DenyNotificationsPermissionUnsubscribes) { | 1399 DenyNotificationsPermissionUnsubscribes) { |
| 1296 std::string script_result; | 1400 std::string script_result; |
| 1297 | 1401 |
| 1298 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1402 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1299 | 1403 |
| 1300 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1404 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1301 EXPECT_EQ("true - subscribed", script_result); | 1405 EXPECT_EQ("true - subscribed", script_result); |
| 1302 | 1406 |
| 1303 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1407 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1304 EXPECT_EQ("permission status - granted", script_result); | 1408 EXPECT_EQ("permission status - granted", script_result); |
| 1305 | 1409 |
| 1306 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1410 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1307 new content::MessageLoopRunner; | 1411 new content::MessageLoopRunner; |
| 1308 push_service()->SetContentSettingChangedCallbackForTesting( | 1412 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1320 EXPECT_EQ("permission status - denied", script_result); | 1424 EXPECT_EQ("permission status - denied", script_result); |
| 1321 | 1425 |
| 1322 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1426 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1323 EXPECT_EQ("false - not subscribed", script_result); | 1427 EXPECT_EQ("false - not subscribed", script_result); |
| 1324 } | 1428 } |
| 1325 | 1429 |
| 1326 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1430 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1327 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { | 1431 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { |
| 1328 std::string script_result; | 1432 std::string script_result; |
| 1329 | 1433 |
| 1330 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1434 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1331 | 1435 |
| 1332 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1436 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1333 EXPECT_EQ("true - subscribed", script_result); | 1437 EXPECT_EQ("true - subscribed", script_result); |
| 1334 | 1438 |
| 1335 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1439 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1336 EXPECT_EQ("permission status - granted", script_result); | 1440 EXPECT_EQ("permission status - granted", script_result); |
| 1337 | 1441 |
| 1338 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1442 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1339 new content::MessageLoopRunner; | 1443 new content::MessageLoopRunner; |
| 1340 push_service()->SetContentSettingChangedCallbackForTesting( | 1444 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1360 } | 1464 } |
| 1361 | 1465 |
| 1362 // This test is testing some non-trivial content settings rules and make sure | 1466 // This test is testing some non-trivial content settings rules and make sure |
| 1363 // that they are respected with regards to automatic unsubscription. In other | 1467 // that they are respected with regards to automatic unsubscription. In other |
| 1364 // words, it checks that the push service does not end up unsubscribing origins | 1468 // words, it checks that the push service does not end up unsubscribing origins |
| 1365 // that have push permission with some non-common rules. | 1469 // that have push permission with some non-common rules. |
| 1366 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1470 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1367 AutomaticUnsubscriptionFollowsContentSettingRules) { | 1471 AutomaticUnsubscriptionFollowsContentSettingRules) { |
| 1368 std::string script_result; | 1472 std::string script_result; |
| 1369 | 1473 |
| 1370 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1474 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1371 | 1475 |
| 1372 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1476 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1373 EXPECT_EQ("true - subscribed", script_result); | 1477 EXPECT_EQ("true - subscribed", script_result); |
| 1374 | 1478 |
| 1375 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1479 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1376 EXPECT_EQ("permission status - granted", script_result); | 1480 EXPECT_EQ("permission status - granted", script_result); |
| 1377 | 1481 |
| 1378 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1482 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1379 new content::MessageLoopRunner; | 1483 new content::MessageLoopRunner; |
| 1380 push_service()->SetContentSettingChangedCallbackForTesting( | 1484 push_service()->SetContentSettingChangedCallbackForTesting( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1406 // The Push service should not unsubcribe |origin| because at no point it was | 1510 // The Push service should not unsubcribe |origin| because at no point it was |
| 1407 // left without permission to use Push. | 1511 // left without permission to use Push. |
| 1408 | 1512 |
| 1409 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1513 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1410 EXPECT_EQ("permission status - granted", script_result); | 1514 EXPECT_EQ("permission status - granted", script_result); |
| 1411 | 1515 |
| 1412 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1516 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1413 EXPECT_EQ("true - subscribed", script_result); | 1517 EXPECT_EQ("true - subscribed", script_result); |
| 1414 } | 1518 } |
| 1415 | 1519 |
| 1416 // Checks that automatically unsubscribing due to a revoked permission is | 1520 // Checks automatically unsubscribing due to a revoked permission after |
| 1417 // handled well if the sender ID needed to unsubscribe was already deleted. | 1521 // previously clearing site data. |
| 1418 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1522 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1419 ResetPushPermissionAfterClearingSiteData) { | 1523 ResetPushPermissionAfterClearingSiteData) { |
| 1420 std::string script_result; | 1524 std::string script_result; |
| 1421 | 1525 |
| 1422 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1526 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1423 | 1527 |
| 1424 PushMessagingAppIdentifier app_identifier = | 1528 PushMessagingAppIdentifier app_identifier = |
| 1425 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1529 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 1426 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
| 1427 PushMessagingAppIdentifier stored_app_identifier = | 1530 PushMessagingAppIdentifier stored_app_identifier = |
| 1428 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1531 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
| 1429 app_identifier.app_id()); | 1532 app_identifier.app_id()); |
| 1430 EXPECT_FALSE(stored_app_identifier.is_null()); | 1533 EXPECT_FALSE(stored_app_identifier.is_null()); |
| 1431 | 1534 |
| 1432 // Simulate a user clearing site data (including Service Workers, crucially). | 1535 // Simulate a user clearing site data (including Service Workers, crucially). |
| 1433 BrowsingDataRemover* remover = | 1536 BrowsingDataRemover* remover = |
| 1434 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowser()->profile()); | 1537 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowser()->profile()); |
| 1435 BrowsingDataRemoverCompletionObserver observer(remover); | 1538 BrowsingDataRemoverCompletionObserver observer(remover); |
| 1436 remover->Remove(BrowsingDataRemover::Unbounded(), | 1539 remover->Remove(BrowsingDataRemover::Unbounded(), |
| 1437 BrowsingDataRemover::REMOVE_SITE_DATA, | 1540 BrowsingDataRemover::REMOVE_SITE_DATA, |
| 1438 BrowsingDataHelper::UNPROTECTED_WEB); | 1541 BrowsingDataHelper::UNPROTECTED_WEB); |
| 1439 observer.BlockUntilCompletion(); | 1542 observer.BlockUntilCompletion(); |
| 1440 | 1543 |
| 1441 base::RunLoop run_loop; | 1544 base::RunLoop run_loop; |
| 1442 push_service()->SetContentSettingChangedCallbackForTesting( | 1545 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1443 run_loop.QuitClosure()); | 1546 run_loop.QuitClosure()); |
| 1444 | 1547 |
| 1445 // This shouldn't (asynchronously) cause a DCHECK. | 1548 // This shouldn't (asynchronously) cause a DCHECK. |
| 1446 // TODO(johnme): Get this test running on Android, which has a different | 1549 // TODO(johnme): Get this test running on Android with legacy GCM |
| 1447 // codepath due to sender_id being required for unsubscribing there. | 1550 // registrations, which have a different codepath due to sender_id being |
| 1551 // required for unsubscribing there. | |
| 1448 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1552 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1449 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1553 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1450 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1554 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1451 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 1555 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 1452 | 1556 |
| 1453 run_loop.Run(); | 1557 run_loop.Run(); |
| 1454 | 1558 |
| 1455 // |app_identifier| should no longer be stored in prefs. | 1559 // |app_identifier| should no longer be stored in prefs. |
| 1456 PushMessagingAppIdentifier stored_app_identifier2 = | 1560 PushMessagingAppIdentifier stored_app_identifier2 = |
| 1457 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1561 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
| 1458 app_identifier.app_id()); | 1562 app_identifier.app_id()); |
| 1459 EXPECT_TRUE(stored_app_identifier2.is_null()); | 1563 EXPECT_TRUE(stored_app_identifier2.is_null()); |
| 1460 } | 1564 } |
| 1461 | 1565 |
| 1462 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { | 1566 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { |
| 1463 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 1567 std::string token1; |
| 1568 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token1)); | |
| 1464 | 1569 |
| 1465 std::string first_public_key; | 1570 std::string first_public_key; |
| 1466 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); | 1571 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); |
| 1467 EXPECT_GE(first_public_key.size(), 32u); | 1572 EXPECT_GE(first_public_key.size(), 32u); |
| 1468 | 1573 |
| 1469 std::string script_result; | 1574 std::string script_result; |
| 1470 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 1471 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1575 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1472 EXPECT_EQ("unsubscribe result: true", script_result); | 1576 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1473 | 1577 |
| 1474 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 1578 std::string token2; |
| 1579 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token2)); | |
| 1580 EXPECT_NE(token1, token2); | |
| 1475 | 1581 |
| 1476 std::string second_public_key; | 1582 std::string second_public_key; |
| 1477 ASSERT_TRUE(RunScript("GetP256dh()", &second_public_key)); | 1583 ASSERT_TRUE(RunScript("GetP256dh()", &second_public_key)); |
| 1478 EXPECT_GE(second_public_key.size(), 32u); | 1584 EXPECT_GE(second_public_key.size(), 32u); |
| 1479 | 1585 |
| 1480 EXPECT_NE(first_public_key, second_public_key); | 1586 EXPECT_NE(first_public_key, second_public_key); |
| 1481 } | 1587 } |
| 1482 | 1588 |
| 1483 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { | 1589 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { |
| 1484 public: | 1590 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1516 #if BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1622 #if BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| 1517 // Push background mode is disabled by default. | 1623 // Push background mode is disabled by default. |
| 1518 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1624 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1519 BackgroundModeDisabledByDefault) { | 1625 BackgroundModeDisabledByDefault) { |
| 1520 // Initially background mode is inactive. | 1626 // Initially background mode is inactive. |
| 1521 BackgroundModeManager* background_mode_manager = | 1627 BackgroundModeManager* background_mode_manager = |
| 1522 g_browser_process->background_mode_manager(); | 1628 g_browser_process->background_mode_manager(); |
| 1523 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1629 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1524 | 1630 |
| 1525 // Once there is a push subscription background mode is still inactive. | 1631 // Once there is a push subscription background mode is still inactive. |
| 1526 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1632 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1527 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1633 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1528 | 1634 |
| 1529 // After dropping the last subscription it is still inactive. | 1635 // After dropping the last subscription it is still inactive. |
| 1530 std::string script_result; | 1636 std::string script_result; |
| 1531 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 1532 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1637 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1533 EXPECT_EQ("unsubscribe result: true", script_result); | 1638 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1534 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1639 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1535 } | 1640 } |
| 1536 | 1641 |
| 1537 class PushMessagingBackgroundModeEnabledBrowserTest | 1642 class PushMessagingBackgroundModeEnabledBrowserTest |
| 1538 : public PushMessagingBrowserTest { | 1643 : public PushMessagingBrowserTest { |
| 1539 public: | 1644 public: |
| 1540 ~PushMessagingBackgroundModeEnabledBrowserTest() override {} | 1645 ~PushMessagingBackgroundModeEnabledBrowserTest() override {} |
| 1541 | 1646 |
| 1542 // PushMessagingBrowserTest: | 1647 // PushMessagingBrowserTest: |
| 1543 void SetUpCommandLine(base::CommandLine* command_line) override { | 1648 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1544 command_line->AppendSwitch(switches::kEnablePushApiBackgroundMode); | 1649 command_line->AppendSwitch(switches::kEnablePushApiBackgroundMode); |
| 1545 PushMessagingBrowserTest::SetUpCommandLine(command_line); | 1650 PushMessagingBrowserTest::SetUpCommandLine(command_line); |
| 1546 } | 1651 } |
| 1547 }; | 1652 }; |
| 1548 | 1653 |
| 1549 // In this test the command line enables push background mode. | 1654 // In this test the command line enables push background mode. |
| 1550 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeEnabledBrowserTest, | 1655 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeEnabledBrowserTest, |
| 1551 BackgroundModeEnabledWithCommandLine) { | 1656 BackgroundModeEnabledWithCommandLine) { |
| 1552 // Initially background mode is inactive. | 1657 // Initially background mode is inactive. |
| 1553 BackgroundModeManager* background_mode_manager = | 1658 BackgroundModeManager* background_mode_manager = |
| 1554 g_browser_process->background_mode_manager(); | 1659 g_browser_process->background_mode_manager(); |
| 1555 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1660 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1556 | 1661 |
| 1557 // Once there is a push subscription background mode is active. | 1662 // Once there is a push subscription background mode is active. |
| 1558 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1663 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1559 ASSERT_TRUE(background_mode_manager->IsBackgroundModeActive()); | 1664 ASSERT_TRUE(background_mode_manager->IsBackgroundModeActive()); |
| 1560 | 1665 |
| 1561 // Dropping the last subscription deactivates background mode. | 1666 // Dropping the last subscription deactivates background mode. |
| 1562 std::string script_result; | 1667 std::string script_result; |
| 1563 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 1564 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1668 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1565 EXPECT_EQ("unsubscribe result: true", script_result); | 1669 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1566 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1670 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1567 } | 1671 } |
| 1568 | 1672 |
| 1569 class PushMessagingBackgroundModeDisabledBrowserTest | 1673 class PushMessagingBackgroundModeDisabledBrowserTest |
| 1570 : public PushMessagingBrowserTest { | 1674 : public PushMessagingBrowserTest { |
| 1571 public: | 1675 public: |
| 1572 ~PushMessagingBackgroundModeDisabledBrowserTest() override {} | 1676 ~PushMessagingBackgroundModeDisabledBrowserTest() override {} |
| 1573 | 1677 |
| 1574 // PushMessagingBrowserTest: | 1678 // PushMessagingBrowserTest: |
| 1575 void SetUpCommandLine(base::CommandLine* command_line) override { | 1679 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1576 command_line->AppendSwitch(switches::kDisablePushApiBackgroundMode); | 1680 command_line->AppendSwitch(switches::kDisablePushApiBackgroundMode); |
| 1577 PushMessagingBrowserTest::SetUpCommandLine(command_line); | 1681 PushMessagingBrowserTest::SetUpCommandLine(command_line); |
| 1578 } | 1682 } |
| 1579 }; | 1683 }; |
| 1580 | 1684 |
| 1581 // In this test the command line disables push background mode. | 1685 // In this test the command line disables push background mode. |
| 1582 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeDisabledBrowserTest, | 1686 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeDisabledBrowserTest, |
| 1583 BackgroundModeDisabledWithCommandLine) { | 1687 BackgroundModeDisabledWithCommandLine) { |
| 1584 // Initially background mode is inactive. | 1688 // Initially background mode is inactive. |
| 1585 BackgroundModeManager* background_mode_manager = | 1689 BackgroundModeManager* background_mode_manager = |
| 1586 g_browser_process->background_mode_manager(); | 1690 g_browser_process->background_mode_manager(); |
| 1587 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1691 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1588 | 1692 |
| 1589 // Once there is a push subscription background mode is still inactive. | 1693 // Once there is a push subscription background mode is still inactive. |
| 1590 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1694 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1591 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1695 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1592 | 1696 |
| 1593 // After dropping the last subscription background mode is still inactive. | 1697 // After dropping the last subscription background mode is still inactive. |
| 1594 std::string script_result; | 1698 std::string script_result; |
| 1595 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
| 1596 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1699 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1597 EXPECT_EQ("unsubscribe result: true", script_result); | 1700 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1598 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1701 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1599 } | 1702 } |
| 1600 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1703 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |