Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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)); | |
|
awdf
2016/11/08 14:39:16
I actually forgot to reapply the javascript change
| |
| 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 " | |
| 843 "a different sender ID already exists", | |
| 844 script_result); | |
| 845 | |
| 846 // Try to resubscribe with the original key - should succeed. | |
| 847 ASSERT_TRUE( | |
| 848 RunScript("workerSubscribePushWithNumericKey('11111')", &script_result)); | |
| 849 std::string token2; | |
| 850 ASSERT_NO_FATAL_FAILURE( | |
| 851 EndpointToToken(script_result, false /* standard_protocol */, &token2)); | |
| 852 EXPECT_EQ(token1, token2); | |
| 853 | |
| 854 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 855 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 856 EXPECT_NE(push_service(), GetAppHandler()); | |
| 857 | |
| 858 // Resubscribe with a different key after unsubscribing. | |
| 859 // Should succeed, and we should get a new subscription token. | |
| 860 ASSERT_TRUE( | |
| 861 RunScript("workerSubscribePushWithNumericKey('22222')", &script_result)); | |
| 862 std::string token3; | |
| 863 ASSERT_NO_FATAL_FAILURE( | |
| 864 EndpointToToken(script_result, false /* standard_protocol */, &token3)); | |
| 865 EXPECT_NE(token1, token3); | |
| 866 | |
| 867 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 868 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 869 EXPECT_NE(push_service(), GetAppHandler()); | |
| 870 } | |
| 871 | |
| 817 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { | 872 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { |
| 818 std::string script_result; | 873 std::string script_result; |
| 819 | 874 |
| 820 // First, test that Service Worker registration IDs are assigned in order of | 875 // First, test that Service Worker registration IDs are assigned in order of |
| 821 // registering the Service Workers, and the (fake) push subscription ids are | 876 // registering the Service Workers, and the (fake) push subscription ids are |
| 822 // assigned in order of push subscription (even when these orders are | 877 // assigned in order of push subscription (even when these orders are |
| 823 // different). | 878 // different). |
| 824 | 879 |
| 825 std::string token1; | 880 std::string token1; |
| 826 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); | 881 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2077 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); | 2132 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 2078 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 2133 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 2079 | 2134 |
| 2080 // After dropping the last subscription background mode is still inactive. | 2135 // After dropping the last subscription background mode is still inactive. |
| 2081 std::string script_result; | 2136 std::string script_result; |
| 2082 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 2137 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 2083 EXPECT_EQ("unsubscribe result: true", script_result); | 2138 EXPECT_EQ("unsubscribe result: true", script_result); |
| 2084 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 2139 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 2085 } | 2140 } |
| 2086 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 2141 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |