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

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

Issue 2436393002: Disallow repeated PushManager.subscribes with different sender ids (Closed)
Patch Set: rebase and comments 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 ff360329ee5cf4bd9e30769775a143d8fa83fbf7..e44b83f548568050ac5b10d685cd6268c37d9a9b 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -814,6 +814,61 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_NE(push_service(), GetAppHandler());
}
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, ResubscribeWithMismatchedKey) {
+ 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 subscribe from the service worker with a key.
+ // This should succeed.
+ ASSERT_TRUE(
+ RunScript("workerSubscribePushWithNumericKey('11111')", &script_result));
awdf 2016/11/08 14:39:16 I actually forgot to reapply the javascript change
+ std::string token1;
+ ASSERT_NO_FATAL_FAILURE(
+ EndpointToToken(script_result, false /* standard_protocol */, &token1));
+
+ // Try to resubscribe with a different key - should fail.
+ ASSERT_TRUE(
+ RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
+ EXPECT_EQ(
+ "InvalidStateError - Registration failed - A subscription with "
+ "a different sender ID already exists",
+ script_result);
+
+ // Try to resubscribe with the original key - should succeed.
+ ASSERT_TRUE(
+ RunScript("workerSubscribePushWithNumericKey('11111')", &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());
+
+ // Resubscribe with a different key after unsubscribing.
+ // Should succeed, and we should get a new subscription token.
+ ASSERT_TRUE(
+ RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
+ std::string token3;
+ ASSERT_NO_FATAL_FAILURE(
+ EndpointToToken(script_result, false /* standard_protocol */, &token3));
+ EXPECT_NE(token1, token3);
+
+ 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