Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Unified Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 2469293002: Handle push resubscribes with no sender info (avoids DCHECK) (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ecd8ad663d7182acee91e3a5161c3bc28fa3552f 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,24 +530,12 @@ 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.
- ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
- std::string token1;
- ASSERT_NO_FATAL_FAILURE(
- EndpointToToken(script_result, true /* standard_protocol */, &token1));
-
- ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
- EXPECT_EQ("unsubscribe result: true", script_result);
- EXPECT_NE(push_service(), GetAppHandler());
- // Now run the subscribe from the service worker without a key.
- // In this case, the key will be read from the datastore.
- ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
- std::string token2;
+ // Now run the subscribe from the service worker with a key.
johnme 2016/11/04 17:43:36 Nit: I know you didn't write this sentence, but it
awdf 2016/11/07 16:54:30 Done.
+ // This should succeed.
+ ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
ASSERT_NO_FATAL_FAILURE(
- EndpointToToken(script_result, true /* standard_protocol */, &token2));
- EXPECT_NE(token1, token2);
+ EndpointToToken(script_result, true /* standard_protocol */));
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -595,6 +589,200 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
EXPECT_NE(push_service(), GetAppHandler());
}
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ ResubscribeWithoutKeyAfterSubscribingWithKeyInManifest) {
johnme 2016/11/04 17:43:37 Nit: These test names could probably be shortened
awdf 2016/11/07 16:54:30 Very good point that WithoutKeyFailure can be pars
johnme 2016/11/07 18:11:59 Since each of these tests is testing three things
awdf 2016/11/07 19:13:22 Done.
+ 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);
johnme 2016/11/04 17:43:37 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 Done.
+
+ 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 numeric.
+ ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
+ EXPECT_EQ(
+ "AbortError - Registration failed - missing applicationServerKey, "
+ "and gcm_sender_id not found in manifest",
+ script_result);
johnme 2016/11/04 17:43:37 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 I don't think that would be successful actually, d
johnme 2016/11/07 18:11:59 Sorry yes, I mean unsubscribe then check that it s
awdf 2016/11/07 19:13:22 Done.
+
+ 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 numeric.
+ ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
+ EXPECT_EQ(
+ "AbortError - Registration failed - missing applicationServerKey, and "
+ "gcm_sender_id not found in manifest",
+ script_result);
johnme 2016/11/04 17:43:36 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 Same here, shouldn't it fail again?
johnme 2016/11/07 18:11:59 Yup, I also meant unsubscribe then check that it s
awdf 2016/11/07 19:13:22 Done.
+
+ 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("documentSubscribePushWithNumericKey()", &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);
johnme 2016/11/04 17:43:37 Now subscribe successfully from a worker without k
awdf 2016/11/07 16:54:30 and here..
johnme 2016/11/07 18:11:59 No, these do indeed succeed. And I see that you ch
awdf 2016/11/07 19:13:22 Acknowledged.
+
+ 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("documentSubscribePushWithNumericKey()", &script_result));
johnme 2016/11/04 17:43:37 s/document/worker/, based on test name
awdf 2016/11/07 16:54:30 Done.
+ 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);
johnme 2016/11/04 17:43:37 Now subscribe successfully from a worker without k
awdf 2016/11/07 16:54:30 ..
johnme 2016/11/07 18:11:59 Ditto I see that you check they succeed :)
+
+ 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;

Powered by Google App Engine
This is Rietveld 408576698