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

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

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed rebase added duplicate code Created 4 years, 9 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 2543d79dd4824a2ae26f2cd7165fd98a6125ee35..75a1ec0fdb1bfcba9abd78e484e33a32b7172c46 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -101,7 +101,7 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
}
void SetUpCommandLine(base::CommandLine* command_line) override {
- // Enable experiemntal features for subscription restrictions.
+ // Enable experimental features for subscription restrictions.
command_line->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
InProcessBrowserTest::SetUpCommandLine(command_line);
@@ -395,8 +395,6 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) {
script_result);
}
-// TODO(johnme): Test subscribing from a worker - see https://crbug.com/437298.
-
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions,
RegisterFailureEmptyPushSubscriptionOptions) {
std::string script_result;
@@ -411,6 +409,52 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions,
script_result);
}
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, WorkerSubscribeSuccessful) {
Michael van Ouwerkerk 2016/03/22 11:31:37 Not all attempts in this test are successful. Mayb
harkness 2016/03/24 16:56:23 Done.
+ std::string script_result;
+
+ ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
+ ASSERT_EQ("ok - service worker registered", script_result);
+
+ RequestAndAcceptPermission();
+
+ LoadTestPage(); // Reload to become controlled.
+
+ ASSERT_TRUE(RunScript("isControlled()", &script_result));
+ ASSERT_EQ("true - is controlled", script_result);
+
+ // Try to subscribe from a worker without a key. This should fail.
+ ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
+ EXPECT_EQ(
+ "AbortError - Registration failed - gcm_sender_id not found in manifest",
+ script_result);
+
+ // Run the subscription from the document without a key, this will
+ // trigger the code to read the manifest.
+ ASSERT_TRUE(RunScript("subscribePushWithoutKey()", &script_result));
Michael van Ouwerkerk 2016/03/22 11:31:37 For clarity it might help to rename subscribePushW
harkness 2016/03/24 16:56:23 Done.
+ EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
+
+ ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
+ EXPECT_EQ("unsubscribe result: true", script_result);
+ EXPECT_NE(push_service(), GetAppHandler());
+
+ // Now run the subscribe from the service worker without a key.
+ // In this case, the key will be read from the datastore.
Michael van Ouwerkerk 2016/03/22 11:31:37 I think no application server key has been provide
harkness 2016/03/24 16:56:23 Good point! In fact, this was hiding an actual cod
+ ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
+ EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result);
+
+ ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
+ EXPECT_EQ("unsubscribe result: true", script_result);
+ EXPECT_NE(push_service(), GetAppHandler());
+
+ // Now run the subscribe from the service worker with a key.
+ ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
+ EXPECT_EQ(GetEndpointForSubscriptionId("1-2"), script_result);
+
+ ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
+ EXPECT_EQ("unsubscribe result: true", script_result);
+ EXPECT_NE(push_service(), GetAppHandler());
+}
+
// Disabled on Windows and Linux due to flakiness (http://crbug.com/554003).
#if defined(OS_WIN) || defined(OS_LINUX)
#define MAYBE_SubscribePersisted DISABLED_SubscribePersisted
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/push_test.js » ('j') | chrome/test/data/push_messaging/push_test.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698