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

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

Issue 2436393002: Disallow repeated PushManager.subscribes with different sender ids (Closed)
Patch Set: Make error message more informative 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
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/push_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1efd1a38214daecd24f67ba080833570b7bd6189 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -814,6 +814,62 @@ 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));
+ 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 applicationServerKey (or gcm_sender_id) already exists; to "
+ "change the applicationServerKey, unsubscribe then resubscribe.",
+ 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;
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/push_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698