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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/push_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 std::string token3; 807 std::string token3;
808 ASSERT_NO_FATAL_FAILURE( 808 ASSERT_NO_FATAL_FAILURE(
809 EndpointToToken(script_result, false /* standard_protocol */, &token3)); 809 EndpointToToken(script_result, false /* standard_protocol */, &token3));
810 EXPECT_NE(token1, token3); 810 EXPECT_NE(token1, token3);
811 811
812 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 812 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
813 EXPECT_EQ("unsubscribe result: true", script_result); 813 EXPECT_EQ("unsubscribe result: true", script_result);
814 EXPECT_NE(push_service(), GetAppHandler()); 814 EXPECT_NE(push_service(), GetAppHandler());
815 } 815 }
816 816
817 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, ResubscribeWithMismatchedKey) {
818 std::string script_result;
819
820 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
821 ASSERT_EQ("ok - service worker registered", script_result);
822
823 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
824
825 LoadTestPage(); // Reload to become controlled.
826
827 ASSERT_TRUE(RunScript("isControlled()", &script_result));
828 ASSERT_EQ("true - is controlled", script_result);
829
830 // Run the subscribe from the service worker with a key.
831 // This should succeed.
832 ASSERT_TRUE(
833 RunScript("workerSubscribePushWithNumericKey('11111')", &script_result));
834 std::string token1;
835 ASSERT_NO_FATAL_FAILURE(
836 EndpointToToken(script_result, false /* standard_protocol */, &token1));
837
838 // Try to resubscribe with a different key - should fail.
839 ASSERT_TRUE(
840 RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
841 EXPECT_EQ(
842 "InvalidStateError - Registration failed - A subscription with a "
843 "different applicationServerKey (or gcm_sender_id) already exists; to "
844 "change the applicationServerKey, unsubscribe then resubscribe.",
845 script_result);
846
847 // Try to resubscribe with the original key - should succeed.
848 ASSERT_TRUE(
849 RunScript("workerSubscribePushWithNumericKey('11111')", &script_result));
850 std::string token2;
851 ASSERT_NO_FATAL_FAILURE(
852 EndpointToToken(script_result, false /* standard_protocol */, &token2));
853 EXPECT_EQ(token1, token2);
854
855 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
856 EXPECT_EQ("unsubscribe result: true", script_result);
857 EXPECT_NE(push_service(), GetAppHandler());
858
859 // Resubscribe with a different key after unsubscribing.
860 // Should succeed, and we should get a new subscription token.
861 ASSERT_TRUE(
862 RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
863 std::string token3;
864 ASSERT_NO_FATAL_FAILURE(
865 EndpointToToken(script_result, false /* standard_protocol */, &token3));
866 EXPECT_NE(token1, token3);
867
868 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
869 EXPECT_EQ("unsubscribe result: true", script_result);
870 EXPECT_NE(push_service(), GetAppHandler());
871 }
872
817 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { 873 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) {
818 std::string script_result; 874 std::string script_result;
819 875
820 // First, test that Service Worker registration IDs are assigned in order of 876 // First, test that Service Worker registration IDs are assigned in order of
821 // registering the Service Workers, and the (fake) push subscription ids are 877 // registering the Service Workers, and the (fake) push subscription ids are
822 // assigned in order of push subscription (even when these orders are 878 // assigned in order of push subscription (even when these orders are
823 // different). 879 // different).
824 880
825 std::string token1; 881 std::string token1;
826 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); 882 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1));
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 2133 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
2078 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2134 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
2079 2135
2080 // After dropping the last subscription background mode is still inactive. 2136 // After dropping the last subscription background mode is still inactive.
2081 std::string script_result; 2137 std::string script_result;
2082 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 2138 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
2083 EXPECT_EQ("unsubscribe result: true", script_result); 2139 EXPECT_EQ("unsubscribe result: true", script_result);
2084 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2140 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
2085 } 2141 }
2086 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 2142 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW
« 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