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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/barrier_closure.h" | 8 #include "base/barrier_closure.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_id), | 241 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_id), |
242 script_result); | 242 script_result); |
243 } | 243 } |
244 | 244 |
245 PushMessagingAppIdentifier | 245 PushMessagingAppIdentifier |
246 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 246 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
247 int64 service_worker_registration_id) { | 247 int64 service_worker_registration_id) { |
248 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 248 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
249 PushMessagingAppIdentifier app_identifier = PushMessagingAppIdentifier::Get( | 249 PushMessagingAppIdentifier app_identifier = PushMessagingAppIdentifier::Get( |
250 GetBrowser()->profile(), origin, service_worker_registration_id); | 250 GetBrowser()->profile(), origin, service_worker_registration_id); |
251 EXPECT_TRUE(app_identifier.IsValid()); | 251 EXPECT_FALSE(app_identifier.is_null()); |
252 return app_identifier; | 252 return app_identifier; |
253 } | 253 } |
254 | 254 |
255 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( | 255 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( |
256 const PushMessagingAppIdentifier& app_identifier, | 256 const PushMessagingAppIdentifier& app_identifier, |
257 const gcm::GCMClient::IncomingMessage& message) { | 257 const gcm::GCMClient::IncomingMessage& message) { |
258 base::RunLoop run_loop; | 258 base::RunLoop run_loop; |
259 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 259 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
260 push_service()->OnMessage(app_identifier.app_id(), message); | 260 push_service()->OnMessage(app_identifier.app_id(), message); |
261 run_loop.Run(); | 261 run_loop.Run(); |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 std::string script_result; | 1031 std::string script_result; |
1032 | 1032 |
1033 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1033 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
1034 | 1034 |
1035 PushMessagingAppIdentifier app_identifier = | 1035 PushMessagingAppIdentifier app_identifier = |
1036 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1036 GetAppIdentifierForServiceWorkerRegistration(0LL); |
1037 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 1037 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
1038 PushMessagingAppIdentifier stored_app_identifier = | 1038 PushMessagingAppIdentifier stored_app_identifier = |
1039 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), | 1039 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), |
1040 app_identifier.app_id()); | 1040 app_identifier.app_id()); |
1041 EXPECT_TRUE(stored_app_identifier.IsValid()); | 1041 EXPECT_FALSE(stored_app_identifier.is_null()); |
1042 | 1042 |
1043 // Simulate a user clearing site data (including Service Workers, crucially). | 1043 // Simulate a user clearing site data (including Service Workers, crucially). |
1044 BrowsingDataRemover* remover = | 1044 BrowsingDataRemover* remover = |
1045 BrowsingDataRemover::CreateForUnboundedRange(GetBrowser()->profile()); | 1045 BrowsingDataRemover::CreateForUnboundedRange(GetBrowser()->profile()); |
1046 BrowsingDataRemoverCompletionObserver observer(remover); | 1046 BrowsingDataRemoverCompletionObserver observer(remover); |
1047 remover->Remove(BrowsingDataRemover::REMOVE_SITE_DATA, | 1047 remover->Remove(BrowsingDataRemover::REMOVE_SITE_DATA, |
1048 BrowsingDataHelper::UNPROTECTED_WEB); | 1048 BrowsingDataHelper::UNPROTECTED_WEB); |
1049 observer.BlockUntilCompletion(); | 1049 observer.BlockUntilCompletion(); |
1050 // BrowsingDataRemover deletes itself. | 1050 // BrowsingDataRemover deletes itself. |
1051 | 1051 |
1052 base::RunLoop run_loop; | 1052 base::RunLoop run_loop; |
1053 push_service()->SetContentSettingChangedCallbackForTesting( | 1053 push_service()->SetContentSettingChangedCallbackForTesting( |
1054 run_loop.QuitClosure()); | 1054 run_loop.QuitClosure()); |
1055 | 1055 |
1056 // This shouldn't (asynchronously) cause a DCHECK. | 1056 // This shouldn't (asynchronously) cause a DCHECK. |
1057 // TODO(johnme): Get this test running on Android, which has a different | 1057 // TODO(johnme): Get this test running on Android, which has a different |
1058 // codepath due to sender_id being required for unsubscribing there. | 1058 // codepath due to sender_id being required for unsubscribing there. |
1059 GetBrowser()->profile()->GetHostContentSettingsMap()-> | 1059 GetBrowser()->profile()->GetHostContentSettingsMap()-> |
1060 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 1060 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
1061 | 1061 |
1062 run_loop.Run(); | 1062 run_loop.Run(); |
1063 | 1063 |
1064 // |app_identifier| should no longer be stored in prefs. | 1064 // |app_identifier| should no longer be stored in prefs. |
1065 PushMessagingAppIdentifier stored_app_identifier2 = | 1065 PushMessagingAppIdentifier stored_app_identifier2 = |
1066 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), | 1066 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), |
1067 app_identifier.app_id()); | 1067 app_identifier.app_id()); |
1068 EXPECT_FALSE(stored_app_identifier2.IsValid()); | 1068 EXPECT_TRUE(stored_app_identifier2.is_null()); |
1069 } | 1069 } |
1070 | 1070 |
1071 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { | 1071 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { |
1072 public: | 1072 public: |
1073 ~PushMessagingIncognitoBrowserTest() override {} | 1073 ~PushMessagingIncognitoBrowserTest() override {} |
1074 | 1074 |
1075 // PushMessagingBrowserTest: | 1075 // PushMessagingBrowserTest: |
1076 void SetUpOnMainThread() override { | 1076 void SetUpOnMainThread() override { |
1077 incognito_browser_ = CreateIncognitoBrowser(); | 1077 incognito_browser_ = CreateIncognitoBrowser(); |
1078 PushMessagingBrowserTest::SetUpOnMainThread(); | 1078 PushMessagingBrowserTest::SetUpOnMainThread(); |
(...skipping 13 matching lines...) Expand all Loading... |
1092 std::string script_result; | 1092 std::string script_result; |
1093 | 1093 |
1094 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1094 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
1095 ASSERT_EQ("ok - service worker registered", script_result); | 1095 ASSERT_EQ("ok - service worker registered", script_result); |
1096 | 1096 |
1097 // In Incognito mode the promise returned by getSubscription should not hang, | 1097 // In Incognito mode the promise returned by getSubscription should not hang, |
1098 // it should just fulfill with null. | 1098 // it should just fulfill with null. |
1099 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1099 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1100 ASSERT_EQ("false - not subscribed", script_result); | 1100 ASSERT_EQ("false - not subscribed", script_result); |
1101 } | 1101 } |
OLD | NEW |