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 74526621568a5be678b1e08d7330f50fb67eaa4e..3e09a246ba1182c074a28014265463bfc6afdb82 100644 |
| --- a/chrome/browser/push_messaging/push_messaging_browsertest.cc |
| +++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc |
| @@ -796,6 +796,58 @@ 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 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. |
| + ASSERT_TRUE( |
| + RunScript("workerSubscribePushWithNumericKey('22222')", &script_result)); |
| + ASSERT_NO_FATAL_FAILURE( |
| + EndpointToToken(script_result, false /* standard_protocol */)); |
|
harkness
2016/11/08 11:56:59
If you're going to parse the endpoint, you should
awdf
2016/11/08 13:21:05
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, SubscribePersisted) { |
| std::string script_result; |