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..1d01fe1f1685143da260cdfb1a14c4c149f4d453 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_; |
| @@ -595,6 +601,198 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 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 sender id should be read from the datastore. |
| + 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()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithP256Key) { |
| + 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 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 a gcm_sender_id. |
|
harkness
2016/11/02 18:48:12
Maybe call it a numeric string, since we're not re
awdf
2016/11/03 14:10:11
Done.
|
| + 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, |
| + ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithP256Key) { |
| + 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 a gcm_sender_id. |
| + 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, |
| + ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithNumber) { |
| + 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("documentSubscribePushWithNumber()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* 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); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + PushMessagingBrowserTest, |
| + ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithNumber) { |
| + 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("documentSubscribePushWithNumber()", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* 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); |
| + |
| + ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| + EXPECT_EQ("unsubscribe result: true", script_result); |
| + EXPECT_NE(push_service(), GetAppHandler()); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { |
| std::string script_result; |