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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 1141613003: Push API: Include origin in generated app_ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ident_test
Patch Set: Add test for reading old values from prefs Created 5 years, 7 months 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 <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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); 240 EXPECT_TRUE(RunScript("subscribePush()", &script_result));
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 =
250 GetBrowser()->profile(), origin, service_worker_registration_id); 250 PushMessagingAppIdentifier::FindByServiceWorker(
251 GetBrowser()->profile(), origin, service_worker_registration_id);
251 EXPECT_FALSE(app_identifier.is_null()); 252 EXPECT_FALSE(app_identifier.is_null());
252 return app_identifier; 253 return app_identifier;
253 } 254 }
254 255
255 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( 256 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled(
256 const PushMessagingAppIdentifier& app_identifier, 257 const PushMessagingAppIdentifier& app_identifier,
257 const gcm::GCMClient::IncomingMessage& message) { 258 const gcm::GCMClient::IncomingMessage& message) {
258 base::RunLoop run_loop; 259 base::RunLoop run_loop;
259 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); 260 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure());
260 push_service()->OnMessage(app_identifier.app_id(), message); 261 push_service()->OnMessage(app_identifier.app_id(), message);
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 1030 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
1030 ResetPushPermissionAfterClearingSiteData) { 1031 ResetPushPermissionAfterClearingSiteData) {
1031 std::string script_result; 1032 std::string script_result;
1032 1033
1033 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 1034 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
1034 1035
1035 PushMessagingAppIdentifier app_identifier = 1036 PushMessagingAppIdentifier app_identifier =
1036 GetAppIdentifierForServiceWorkerRegistration(0LL); 1037 GetAppIdentifierForServiceWorkerRegistration(0LL);
1037 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 1038 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
1038 PushMessagingAppIdentifier stored_app_identifier = 1039 PushMessagingAppIdentifier stored_app_identifier =
1039 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), 1040 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
1040 app_identifier.app_id()); 1041 app_identifier.app_id());
1041 EXPECT_FALSE(stored_app_identifier.is_null()); 1042 EXPECT_FALSE(stored_app_identifier.is_null());
1042 1043
1043 // Simulate a user clearing site data (including Service Workers, crucially). 1044 // Simulate a user clearing site data (including Service Workers, crucially).
1044 BrowsingDataRemover* remover = 1045 BrowsingDataRemover* remover =
1045 BrowsingDataRemover::CreateForUnboundedRange(GetBrowser()->profile()); 1046 BrowsingDataRemover::CreateForUnboundedRange(GetBrowser()->profile());
1046 BrowsingDataRemoverCompletionObserver observer(remover); 1047 BrowsingDataRemoverCompletionObserver observer(remover);
1047 remover->Remove(BrowsingDataRemover::REMOVE_SITE_DATA, 1048 remover->Remove(BrowsingDataRemover::REMOVE_SITE_DATA,
1048 BrowsingDataHelper::UNPROTECTED_WEB); 1049 BrowsingDataHelper::UNPROTECTED_WEB);
1049 observer.BlockUntilCompletion(); 1050 observer.BlockUntilCompletion();
1050 // BrowsingDataRemover deletes itself. 1051 // BrowsingDataRemover deletes itself.
1051 1052
1052 base::RunLoop run_loop; 1053 base::RunLoop run_loop;
1053 push_service()->SetContentSettingChangedCallbackForTesting( 1054 push_service()->SetContentSettingChangedCallbackForTesting(
1054 run_loop.QuitClosure()); 1055 run_loop.QuitClosure());
1055 1056
1056 // This shouldn't (asynchronously) cause a DCHECK. 1057 // This shouldn't (asynchronously) cause a DCHECK.
1057 // TODO(johnme): Get this test running on Android, which has a different 1058 // TODO(johnme): Get this test running on Android, which has a different
1058 // codepath due to sender_id being required for unsubscribing there. 1059 // codepath due to sender_id being required for unsubscribing there.
1059 GetBrowser()->profile()->GetHostContentSettingsMap()-> 1060 GetBrowser()->profile()->GetHostContentSettingsMap()->
1060 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 1061 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
1061 1062
1062 run_loop.Run(); 1063 run_loop.Run();
1063 1064
1064 // |app_identifier| should no longer be stored in prefs. 1065 // |app_identifier| should no longer be stored in prefs.
1065 PushMessagingAppIdentifier stored_app_identifier2 = 1066 PushMessagingAppIdentifier stored_app_identifier2 =
1066 PushMessagingAppIdentifier::Get(GetBrowser()->profile(), 1067 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
1067 app_identifier.app_id()); 1068 app_identifier.app_id());
1068 EXPECT_TRUE(stored_app_identifier2.is_null()); 1069 EXPECT_TRUE(stored_app_identifier2.is_null());
1069 } 1070 }
1070 1071
1071 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { 1072 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest {
1072 public: 1073 public:
1073 ~PushMessagingIncognitoBrowserTest() override {} 1074 ~PushMessagingIncognitoBrowserTest() override {}
1074 1075
1075 // PushMessagingBrowserTest: 1076 // PushMessagingBrowserTest:
1076 void SetUpOnMainThread() override { 1077 void SetUpOnMainThread() override {
1077 incognito_browser_ = CreateIncognitoBrowser(); 1078 incognito_browser_ = CreateIncognitoBrowser();
(...skipping 14 matching lines...) Expand all
1092 std::string script_result; 1093 std::string script_result;
1093 1094
1094 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 1095 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
1095 ASSERT_EQ("ok - service worker registered", script_result); 1096 ASSERT_EQ("ok - service worker registered", script_result);
1096 1097
1097 // In Incognito mode the promise returned by getSubscription should not hang, 1098 // In Incognito mode the promise returned by getSubscription should not hang,
1098 // it should just fulfill with null. 1099 // it should just fulfill with null.
1099 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); 1100 ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
1100 ASSERT_EQ("false - not subscribed", script_result); 1101 ASSERT_EQ("false - not subscribed", script_result);
1101 } 1102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698