Chromium Code Reviews| Index: chrome/browser/push_messaging/push_messaging_browsertest.cc |
| diff --git a/chrome/browser/push_messaging/push_messaging_browsertest.cc b/chrome/browser/push_messaging/push_messaging_browsertest.cc |
| index be24d16c81710dae50c09d718e458cec36df6df2..74526621568a5be678b1e08d7330f50fb67eaa4e 100644 |
| --- a/chrome/browser/push_messaging/push_messaging_browsertest.cc |
| +++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc |
| @@ -187,6 +187,8 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| void LoadTestPage() { LoadTestPage(GetTestURL()); } |
| + void LoadTestPageWithoutManifest() { LoadTestPage(GetNoManifestTestURL()); } |
| + |
| bool RunScript(const std::string& script, std::string* result) { |
| return RunScript(script, result, nullptr); |
| } |
| @@ -271,6 +273,10 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| protected: |
| virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
| + virtual std::string GetNoManifestTestURL() { |
| + return "/push_messaging/test_no_manifest.html"; |
| + } |
| + |
| virtual Browser* GetBrowser() const { return browser(); } |
| gcm::FakeGCMProfileService* gcm_service_; |
| @@ -524,23 +530,68 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { |
| "AbortError - Registration failed - missing applicationServerKey, and " |
| "gcm_sender_id not found in manifest", |
| script_result); |
| - // Now run the subscribe from the service worker with a key. This |
| - // should succeed, and write the key to the datastore. |
| + |
| + // Now run the subscribe with a key. This should succeed. |
| ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); |
| - std::string token1; |
| ASSERT_NO_FATAL_FAILURE( |
| - EndpointToToken(script_result, true /* standard_protocol */, &token1)); |
| + EndpointToToken(script_result, true /* standard_protocol */)); |
| ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| EXPECT_EQ("unsubscribe result: true", script_result); |
| EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| + ResubscribeWithoutKeyAfterSubscribingWithKeyInManifest) { |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| + |
| + ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| + |
| + LoadTestPage(); // Reload to become controlled. |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("true - is controlled", script_result); |
| + |
| + // Run the subscription from the document without a key, this will trigger |
| + // the code to read sender id from the manifest and will write it to the |
| + // datastore. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + std::string token1; |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token1)); |
| + |
| + ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| + ASSERT_EQ("manifest removed", script_result); |
| + |
| + // Try to resubscribe from the document without a key or manifest. |
| + // This should fail. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and manifest empty or missing", |
| + script_result); |
| // Now run the subscribe from the service worker without a key. |
| - // In this case, the key will be read from the datastore. |
| + // In this case, the sender id should be read from the datastore. |
| ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| std::string token2; |
| ASSERT_NO_FATAL_FAILURE( |
| - EndpointToToken(script_result, true /* standard_protocol */, &token2)); |
| + EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| + EXPECT_EQ(token1, token2); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| + |
| + // After unsubscribing, subscribe again from the worker with no key. |
| + // The sender id should again be read from the datastore, so the |
| + // subcribe should succeed, and we should get a new subscription token. |
| + ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
|
johnme
2016/11/07 18:11:59
Nit: seems more consistent to call this token3 (di
awdf
2016/11/07 19:13:23
Done.
|
| EXPECT_NE(token1, token2); |
| ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| @@ -548,8 +599,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { |
| EXPECT_NE(push_service(), GetAppHandler()); |
| } |
| -IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| - SubscribeWorkerUsingManifest) { |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeFailureWithoutKeyAfterSubscribingFromDocumentWithP256Key) { |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -557,37 +609,186 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| - LoadTestPage(); // Reload to become controlled. |
| + LoadTestPageWithoutManifest(); // Reload to become controlled. |
| ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| ASSERT_EQ("true - is controlled", script_result); |
| - // Try to subscribe from a worker without a key. This should fail. |
| + // Run the subscription from the document with a key. |
| + ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); |
| + |
| + // Try to resubscribe from the document without a key - should fail. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and manifest empty or missing", |
| + script_result); |
| + |
| + // Now try to resubscribe from the service worker without a key. |
| + // This should also fail as the original key was not numeric. |
| + ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and gcm_sender_id not found in manifest", |
| + script_result); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeFailureWithoutKeyAfterSubscribingFromWorkerWithP256Key) { |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| + |
| + ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| + |
| + LoadTestPageWithoutManifest(); // Reload to become controlled. |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("true - is controlled", script_result); |
| + |
| + // Run the subscribe from the service worker with a key. |
| + // This should succeed. |
| + ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, true /* standard_protocol */)); |
| + |
| + // Try to resubscribe from the document without a key - should fail. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and manifest empty or missing", |
| + script_result); |
| + |
| + // Now try to resubscribe from the service worker without a key. |
| + // This should also fail as the original key was not numeric. |
| ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| EXPECT_EQ( |
| "AbortError - Registration failed - missing applicationServerKey, and " |
| "gcm_sender_id not found in manifest", |
| script_result); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| - // Run the subscription from the document without a key, this will trigger |
| - // the code to read sender id from the manifest and will write it to the |
| - // datastore. |
| - ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeFailureWithoutKeyAfterSubscribingFromDocumentWithNumber) { |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| + |
| + ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| + |
| + LoadTestPageWithoutManifest(); // Reload to become controlled. |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("true - is controlled", script_result); |
| + |
| + // Run the subscribe from the service worker with a key. |
|
johnme
2016/11/07 18:11:59
s/key/numeric key/ or similar
awdf
2016/11/07 19:13:22
Done. It should also say document not service work
|
| + // This should succeed. |
| + ASSERT_TRUE( |
| + RunScript("documentSubscribePushWithNumericKey()", &script_result)); |
| std::string token1; |
| ASSERT_NO_FATAL_FAILURE( |
| EndpointToToken(script_result, false /* standard_protocol */, &token1)); |
| + // Try to resubscribe from the document without a key - should fail. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and manifest empty or missing", |
| + script_result); |
| + |
| + // Now run the subscribe from the service worker without a key. |
| + // In this case, the sender id should be read from the datastore. |
| + // Note, we would rather this failed as we only really want to support |
| + // no-key subscribes after subscribing with a numeric gcm sender id in the |
| + // manifest, not a numeric applicationServerKey, but for code simplicity |
| + // this case is allowed. |
| + ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| + std::string token2; |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| + EXPECT_EQ(token1, token2); |
| + |
| ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| EXPECT_EQ("unsubscribe result: true", script_result); |
| EXPECT_NE(push_service(), GetAppHandler()); |
| + // After unsubscribing, subscribe again from the worker with no key. |
| + // The sender id should again be read from the datastore, so the |
| + // subcribe should succeed, and we should get a new subscription token. |
| + ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| + EXPECT_NE(token1, token2); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeFailureWithoutKeyAfterSubscribingFromWorkerWithNumber) { |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| + |
| + ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| + |
| + LoadTestPageWithoutManifest(); // Reload to become controlled. |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("true - is controlled", script_result); |
| + |
| + // Run the subscribe from the service worker with a key. |
|
johnme
2016/11/07 18:11:59
s/key/numeric key/ or similar
awdf
2016/11/07 19:13:22
Done.
|
| + // This should succeed. |
| + ASSERT_TRUE(RunScript("workerSubscribePushWithNumericKey()", &script_result)); |
| + std::string token1; |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token1)); |
| + |
| + // Try to resubscribe from the document without a key - should fail. |
| + ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| + EXPECT_EQ( |
| + "AbortError - Registration failed - missing applicationServerKey, " |
| + "and manifest empty or missing", |
| + script_result); |
| + |
| // Now run the subscribe from the service worker without a key. |
| - // In this case, the sender id will be read from the datastore. |
| + // In this case, the sender id should be read from the datastore. |
| + // Note, we would rather this failed as we only really want to support |
| + // no-key subscribes after subscribing with a numeric gcm sender id in the |
| + // manifest, not a numeric applicationServerKey, but for code simplicity |
| + // this case is allowed. |
| ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| std::string token2; |
| ASSERT_NO_FATAL_FAILURE( |
| EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| + EXPECT_EQ(token1, token2); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| + |
| + // After unsubscribing, subscribe again from the worker with no key. |
| + // The sender id should again be read from the datastore, so the |
| + // subcribe should succeed, and we should get a new subscription token. |
| + ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| EXPECT_NE(token1, token2); |
| ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |