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

Unified Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 1851423003: Make Web Push use InstanceID tokens instead of GCM registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid4default
Patch Set: Fix GN/GYP Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/push_messaging/push_messaging_browsertest.cc
diff --git a/chrome/browser/push_messaging/push_messaging_browsertest.cc b/chrome/browser/push_messaging/push_messaging_browsertest.cc
index c89a414ab520a57e2acf52fc1463f303459a11b5..f16f26b90e408ba965f3e3db5f59fec5ca8a1e23 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -48,6 +48,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/window_open_disposition.h"
#if BUILDFLAG(ENABLE_BACKGROUND)
@@ -72,33 +73,11 @@ const char* getTestApplicationServerKey() {
return reinterpret_cast<const char*>(kApplicationServerKey);
}
-// Class to instantiate on the stack that is meant to be used with
-// FakeGCMProfileService. The ::Run() method follows the signature of
-// FakeGCMProfileService::UnregisterCallback.
-class UnregistrationCallback {
- public:
- UnregistrationCallback()
- : message_loop_runner_(new content::MessageLoopRunner) {}
-
- void Run(const std::string& app_id) {
- app_id_ = app_id;
- message_loop_runner_->Quit();
- }
-
- void WaitUntilSatisfied() { message_loop_runner_->Run(); }
-
- const std::string& app_id() { return app_id_; }
-
- private:
- scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
- std::string app_id_;
-};
-
} // namespace
class PushMessagingBrowserTest : public InProcessBrowserTest {
public:
- PushMessagingBrowserTest() : gcm_service_(nullptr) {}
+ PushMessagingBrowserTest() : gcm_driver_(nullptr) {}
~PushMessagingBrowserTest() override {}
// InProcessBrowserTest:
@@ -126,10 +105,10 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
// InProcessBrowserTest:
void SetUpOnMainThread() override {
- gcm_service_ = static_cast<gcm::FakeGCMProfileService*>(
+ gcm::GCMProfileService* gcm_service = static_cast<gcm::GCMProfileService*>(
gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build));
- gcm_service_->set_collect(true);
+ gcm_driver_ = gcm_service->driver();
push_service_ =
PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile());
@@ -176,8 +155,7 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
}
gcm::GCMAppHandler* GetAppHandler() {
- return gcm_service()->driver()->GetAppHandler(
- kPushMessagingAppIdentifierPrefix);
+ return gcm_driver_->GetAppHandler(kPushMessagingAppIdentifierPrefix);
}
PermissionBubbleManager* GetPermissionBubbleManager() {
@@ -188,13 +166,10 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
void RequestAndAcceptPermission();
void RequestAndDenyPermission();
- void TryToSubscribeSuccessfully(
- const std::string& expected_push_subscription_info,
- bool use_key = true);
+ // Returns the subscription token (not including kPushMessagingEndpoint).
+ std::string SubscribeSuccessfully(bool use_key = true);
- std::string GetEndpointForSubscriptionId(const std::string& subscription_id) {
- return std::string(kPushMessagingEndpoint) + "/" + subscription_id;
- }
+ std::string EndpointToToken(const std::string& endpoint);
PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration(
int64_t service_worker_registration_id);
@@ -205,8 +180,6 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
net::EmbeddedTestServer* https_server() const { return https_server_.get(); }
- gcm::FakeGCMProfileService* gcm_service() const { return gcm_service_; }
-
#if defined(ENABLE_NOTIFICATIONS)
// To be called when delivery of a push message has finished. The |run_loop|
// will be told to quit after |messages_required| messages were received.
@@ -238,7 +211,7 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
private:
scoped_ptr<net::EmbeddedTestServer> https_server_;
- gcm::FakeGCMProfileService* gcm_service_;
+ gcm::GCMDriver* gcm_driver_;
PushMessagingServiceImpl* push_service_;
#if defined(ENABLE_NOTIFICATIONS)
@@ -271,9 +244,7 @@ void PushMessagingBrowserTest::RequestAndDenyPermission() {
EXPECT_EQ("permission status - denied", script_result);
}
-void PushMessagingBrowserTest::TryToSubscribeSuccessfully(
- const std::string& expected_push_subscription_info,
- bool use_key) {
+std::string PushMessagingBrowserTest::SubscribeSuccessfully(bool use_key) {
std::string script_result;
EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result));
@@ -282,17 +253,23 @@ void PushMessagingBrowserTest::TryToSubscribeSuccessfully(
RequestAndAcceptPermission();
if (use_key) {
- ASSERT_TRUE(RunScript("removeManifest()", &script_result));
- ASSERT_EQ("manifest removed", script_result);
+ EXPECT_TRUE(RunScript("removeManifest()", &script_result));
+ EXPECT_EQ("manifest removed", script_result);
EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result));
} else {
// Test backwards compatibility with old ID based subscriptions.
EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
}
+ return EndpointToToken(script_result);
+}
- EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info),
- script_result);
+std::string PushMessagingBrowserTest::EndpointToToken(
+ const std::string& endpoint) {
+ std::string endpoint_prefix = std::string(kPushMessagingEndpoint) + "/";
Peter Beverloo 2016/04/11 15:47:56 We cannot rely on kPushMessagingEndpoint anymore.
johnme 2016/04/21 10:58:37 Done.
+ EXPECT_THAT(endpoint, ::testing::StartsWith(endpoint_prefix));
+ EXPECT_GT(endpoint.length(), endpoint_prefix.length());
+ return endpoint.substr(endpoint_prefix.length());
}
PushMessagingAppIdentifier
@@ -317,23 +294,16 @@ void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled(
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
SubscribeWithoutKeySuccessNotificationsGranted) {
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false);
-
- PushMessagingAppIdentifier app_identifier =
- GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
+ // Both of these methods EXPECT that they succeed.
+ SubscribeSuccessfully(false /* use_key */);
+ GetAppIdentifierForServiceWorkerRegistration(0LL);
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
SubscribeSuccessNotificationsGranted) {
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
- PushMessagingAppIdentifier app_identifier =
- GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
+ // Both of these methods EXPECT that they succeed.
+ SubscribeSuccessfully();
+ GetAppIdentifierForServiceWorkerRegistration(0LL);
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
@@ -346,13 +316,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
GetPermissionBubbleManager()->set_auto_response_for_test(
PermissionBubbleManager::ACCEPT_ALL);
ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
-
- PushMessagingAppIdentifier app_identifier =
- GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
+ // Both of these methods EXPECT that they succeed.
+ EndpointToToken(script_result);
+ GetAppIdentifierForServiceWorkerRegistration(0LL);
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) {
@@ -452,7 +418,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) {
// Now run the subscribe from the service worker with a key. This
// should succeed, and write the key to the datastore.
ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
+ std::string token1 = EndpointToToken(script_result);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -461,7 +427,8 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) {
// Now run the subscribe from the service worker without a key.
// In this case, the key will be read from the datastore.
ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result);
+ std::string token2 = EndpointToToken(script_result);
+ EXPECT_NE(token1, token2);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -492,7 +459,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) {
// the code to read sender id from the manifest and will write it to the
// datastore.
ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
+ std::string token1 = EndpointToToken(script_result);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -501,7 +468,8 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) {
// Now run the subscribe from the service worker without a key.
// In this case, the sender id will be read from the datastore.
ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result);
+ std::string token2 = EndpointToToken(script_result);
+ EXPECT_NE(token1, token2);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -522,10 +490,8 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) {
// assigned in order of push subscription (even when these orders are
// different).
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
- PushMessagingAppIdentifier sw0_identifier =
- GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(sw0_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token1 = SubscribeSuccessfully();
+ GetAppIdentifierForServiceWorkerRegistration(0LL);
LoadTestPage("/push_messaging/subscope1/test.html");
ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
@@ -539,16 +505,15 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) {
// navigator.serviceWorker.ready is going to be resolved with the parent
// Service Worker which still controls the page.
LoadTestPage("/push_messaging/subscope2/test.html");
- TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
- PushMessagingAppIdentifier sw2_identifier =
- GetAppIdentifierForServiceWorkerRegistration(2LL);
- EXPECT_EQ(sw2_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token2 = SubscribeSuccessfully();
+ EXPECT_NE(token1, token2);
+ GetAppIdentifierForServiceWorkerRegistration(2LL);
LoadTestPage("/push_messaging/subscope1/test.html");
- TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */);
- PushMessagingAppIdentifier sw1_identifier =
- GetAppIdentifierForServiceWorkerRegistration(1LL);
- EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token3 = SubscribeSuccessfully();
+ EXPECT_NE(token1, token3);
+ EXPECT_NE(token2, token3);
+ GetAppIdentifierForServiceWorkerRegistration(1LL);
// Now test that the Service Worker registration IDs and push subscription IDs
// generated above were persisted to SW storage, by checking that they are
@@ -559,16 +524,16 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) {
// so we wouldn't be able to load the test pages with the same origin.
LoadTestPage("/push_messaging/subscope1/test.html");
- TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */);
- EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token4 = SubscribeSuccessfully();
+ EXPECT_EQ(token3, token4);
LoadTestPage("/push_messaging/subscope2/test.html");
- TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
- EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token5 = SubscribeSuccessfully();
+ EXPECT_EQ(token2, token5);
LoadTestPage();
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
- EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id());
+ std::string token6 = SubscribeSuccessfully();
+ EXPECT_EQ(token1, token6);
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) {
@@ -578,7 +543,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) {
ASSERT_NO_FATAL_FAILURE(RestartPushService());
EXPECT_NE(push_service(), GetAppHandler());
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
Peter Beverloo 2016/04/11 15:47:56 It seems to me that this very much is something we
johnme 2016/04/21 10:58:37 Done (and generally cleaned this up elsewhere too)
EXPECT_EQ(push_service(), GetAppHandler());
ASSERT_NO_FATAL_FAILURE(RestartPushService());
@@ -586,7 +551,6 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) {
// Unsubscribe.
std::string script_result;
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -598,13 +562,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) {
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -626,13 +586,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) {
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -654,13 +610,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) {
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -674,20 +626,29 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) {
ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result));
ASSERT_EQ("service worker unregistration status: true", script_result);
- // When the push service will receive it next message, given that there is no
- // SW available, it should unregister |app_identifier.app_id()|.
- UnregistrationCallback callback;
- gcm_service()->SetUnregisterCallback(
- base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback)));
+ // Unregistering the service worker doesn't yet unsubscribe from push (though
+ // it should), and FindByServiceWorker doesn't require a live SW.
+ GURL origin = https_server()->GetURL("/").GetOrigin();
+ PushMessagingAppIdentifier app_identifier2 =
+ PushMessagingAppIdentifier::FindByServiceWorker(
+ GetBrowser()->profile(),
+ origin, 0LL /* service_worker_registration_id */);
+ EXPECT_FALSE(app_identifier2.is_null());
+ EXPECT_EQ(app_identifier.app_id(), app_identifier2.app_id());
gcm::IncomingMessage message;
message.sender_id = std::string(getTestApplicationServerKey());
message.raw_data = "testdata";
message.decrypted = true;
- push_service()->OnMessage(app_identifier.app_id(), message);
+ SendMessageAndWaitUntilHandled(app_identifier, message);
- callback.WaitUntilSatisfied();
- EXPECT_EQ(app_identifier.app_id(), callback.app_id());
+ // Now the push service has received a message and failed to find its service
+ // worker, it should have automatically unsubscribed app_identifier.app_id().
+ PushMessagingAppIdentifier app_identifier3 =
+ PushMessagingAppIdentifier::FindByServiceWorker(
+ GetBrowser()->profile(),
+ origin, 0LL /* service_worker_registration_id */);
+ EXPECT_TRUE(app_identifier3.is_null());
// No push data should have been received.
ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
@@ -699,13 +660,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
PushEventEnforcesUserVisibleNotification) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -807,13 +764,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
PushEventEnforcesUserVisibleNotificationAfterQueue) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -861,13 +814,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
content::WebContents* web_contents =
GetBrowser()->tab_strip_model()->GetActiveWebContents();
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
-
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
- EXPECT_EQ(getTestApplicationServerKey(),
- gcm_service()->last_registered_sender_ids()[0]);
ASSERT_TRUE(RunScript("isControlled()", &script_result));
ASSERT_EQ("false - is not controlled", script_result);
@@ -921,7 +870,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) {
RequestAndAcceptPermission();
ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
- EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
+ EndpointToToken(script_result); // EXPECTs that the conversion succeeds.
ASSERT_TRUE(RunScript("permissionState()", &script_result));
EXPECT_EQ("permission status - granted", script_result);
@@ -950,8 +899,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) {
EXPECT_EQ("ok - service worker registered", script_result);
// Resolves true if there was a subscription.
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false);
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
+ std::string token1 = SubscribeSuccessfully(false /* use_key */);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
@@ -961,8 +909,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) {
// Doesn't reject if there was a network error (deactivates subscription
// locally anyway).
- TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */, false);
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR);
+ std::string token2 = SubscribeSuccessfully(false /* use_key */);
+ EXPECT_NE(token1, token2);
+ // TODO(johnme): AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
@@ -970,15 +919,20 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) {
// Doesn't reject if there were other push service errors (deactivates
// subscription locally anyway).
- TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */, false);
- gcm_service()->AddExpectedUnregisterResponse(
- gcm::GCMClient::INVALID_PARAMETER);
+ std::string token3 = SubscribeSuccessfully(false /* use_key */);
+ EXPECT_NE(token1, token3);
+ EXPECT_NE(token2, token3);
+ // TODO(johnme): AddExpectedUnregisterResponse(
+ // gcm::GCMClient::INVALID_PARAMETER);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
// Unsubscribing (with an existing reference to a PushSubscription), after
// unregistering the Service Worker, just means push subscription isn't found.
- TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */, false);
+ std::string token4 = SubscribeSuccessfully(false /* use_key */);
+ EXPECT_NE(token1, token4);
+ EXPECT_NE(token2, token4);
+ EXPECT_NE(token3, token4);
ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result));
ASSERT_EQ("service worker unregistration status: true", script_result);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
@@ -989,7 +943,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
GlobalResetPushPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1021,7 +975,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
LocalResetPushPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1057,7 +1011,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
DenyPushPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1089,7 +1043,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
GlobalResetNotificationsPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1118,7 +1072,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
LocalResetNotificationsPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1150,7 +1104,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
DenyNotificationsPermissionUnsubscribes) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1182,7 +1136,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
GrantAlreadyGrantedPermissionDoesNotUnsubscribe) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1222,7 +1176,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
AutomaticUnsubscriptionFollowsContentSettingRules) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
EXPECT_EQ("true - subscribed", script_result);
@@ -1269,17 +1223,16 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
EXPECT_EQ("true - subscribed", script_result);
}
-// Checks that automatically unsubscribing due to a revoked permission is
-// handled well if the sender ID needed to unsubscribe was already deleted.
+// Checks automatically unsubscribing due to a revoked permission after
+// previously clearing site data.
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
ResetPushPermissionAfterClearingSiteData) {
std::string script_result;
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
PushMessagingAppIdentifier app_identifier =
GetAppIdentifierForServiceWorkerRegistration(0LL);
- EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
PushMessagingAppIdentifier stored_app_identifier =
PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
app_identifier.app_id());
@@ -1316,18 +1269,18 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) {
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false);
+ std::string token1 = SubscribeSuccessfully(false /* use_key */);
std::string first_public_key;
ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key));
EXPECT_GE(first_public_key.size(), 32u);
std::string script_result;
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
- TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
+ std::string token2 = SubscribeSuccessfully();
+ EXPECT_NE(token1, token2);
std::string second_public_key;
ASSERT_TRUE(RunScript("GetP256dh()", &second_public_key));
@@ -1379,12 +1332,11 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
// Once there is a push subscription background mode is still inactive.
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
// After dropping the last subscription it is still inactive.
std::string script_result;
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
@@ -1411,12 +1363,11 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeEnabledBrowserTest,
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
// Once there is a push subscription background mode is active.
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_TRUE(background_mode_manager->IsBackgroundModeActive());
// Dropping the last subscription deactivates background mode.
std::string script_result;
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
@@ -1443,12 +1394,11 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeDisabledBrowserTest,
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
// Once there is a push subscription background mode is still inactive.
- TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
+ SubscribeSuccessfully();
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
// After dropping the last subscription background mode is still inactive.
std::string script_result;
- gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
EXPECT_EQ("unsubscribe result: true", script_result);
ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());

Powered by Google App Engine
This is Rietveld 408576698