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

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: Re-rebase on base patch 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
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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); 789 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
790 ASSERT_NO_FATAL_FAILURE( 790 ASSERT_NO_FATAL_FAILURE(
791 EndpointToToken(script_result, false /* standard_protocol */, &token2)); 791 EndpointToToken(script_result, false /* standard_protocol */, &token2));
792 EXPECT_NE(token1, token2); 792 EXPECT_NE(token1, token2);
793 793
794 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 794 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
795 EXPECT_EQ("unsubscribe result: true", script_result); 795 EXPECT_EQ("unsubscribe result: true", script_result);
796 EXPECT_NE(push_service(), GetAppHandler()); 796 EXPECT_NE(push_service(), GetAppHandler());
797 } 797 }
798 798
799 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, ResubscribeWithMismatchedKey) {
800 std::string script_result;
801
802 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
803 ASSERT_EQ("ok - service worker registered", script_result);
804
805 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
806
807 LoadTestPage(); // Reload to become controlled.
808
809 ASSERT_TRUE(RunScript("isControlled()", &script_result));
810 ASSERT_EQ("true - is controlled", script_result);
811
812 // Run the subscribe from the service worker with a key.
813 // This should succeed.
814 ASSERT_TRUE(
815 RunScript("workerSubscribePushWithNumericKey('11111')", &script_result));
816 std::string token1;
817 ASSERT_NO_FATAL_FAILURE(
818 EndpointToToken(script_result, false /* standard_protocol */, &token1));
819
820 // Try to resubscribe with a different key - should fail.
821 ASSERT_TRUE(
822 RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
823 EXPECT_EQ(
824 "InvalidStateError - Registration failed - A subscription with "
825 "a different sender ID already exists",
826 script_result);
827
828 // Try to resubscribe with the original key - should succeed.
829 ASSERT_TRUE(
830 RunScript("workerSubscribePushWithNumericKey('11111')", &script_result));
831 std::string token2;
832 ASSERT_NO_FATAL_FAILURE(
833 EndpointToToken(script_result, false /* standard_protocol */, &token2));
834 EXPECT_EQ(token1, token2);
835
836 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
837 EXPECT_EQ("unsubscribe result: true", script_result);
838 EXPECT_NE(push_service(), GetAppHandler());
839
840 // Resubscribe with a different key after unsubscribing. Should succeed.
841 ASSERT_TRUE(
842 RunScript("workerSubscribePushWithNumericKey('22222')", &script_result));
843 ASSERT_NO_FATAL_FAILURE(
844 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.
845
846 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
847 EXPECT_EQ("unsubscribe result: true", script_result);
848 EXPECT_NE(push_service(), GetAppHandler());
849 }
850
799 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { 851 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) {
800 std::string script_result; 852 std::string script_result;
801 853
802 // First, test that Service Worker registration IDs are assigned in order of 854 // First, test that Service Worker registration IDs are assigned in order of
803 // registering the Service Workers, and the (fake) push subscription ids are 855 // registering the Service Workers, and the (fake) push subscription ids are
804 // assigned in order of push subscription (even when these orders are 856 // assigned in order of push subscription (even when these orders are
805 // different). 857 // different).
806 858
807 std::string token1; 859 std::string token1;
808 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); 860 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1));
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 2111 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
2060 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2112 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
2061 2113
2062 // After dropping the last subscription background mode is still inactive. 2114 // After dropping the last subscription background mode is still inactive.
2063 std::string script_result; 2115 std::string script_result;
2064 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 2116 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
2065 EXPECT_EQ("unsubscribe result: true", script_result); 2117 EXPECT_EQ("unsubscribe result: true", script_result);
2066 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2118 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
2067 } 2119 }
2068 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 2120 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698