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

Side by Side Diff: chrome/browser/extensions/service_worker_apitest.cc

Issue 1445603003: Extension SW - add test for ServiceWorkerRegistration.sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more foo Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind_helpers.h" 5 #include "base/bind_helpers.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "components/version_info/version_info.h" 11 #include "components/version_info/version_info.h"
12 #include "content/public/browser/navigation_controller.h" 12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h"
15 #include "content/public/common/page_type.h" 16 #include "content/public/common/page_type.h"
17 #include "content/public/test/background_sync_test_util.h"
16 #include "content/public/test/browser_test_utils.h" 18 #include "content/public/test/browser_test_utils.h"
17 #include "extensions/browser/extension_host.h" 19 #include "extensions/browser/extension_host.h"
18 #include "extensions/browser/process_manager.h" 20 #include "extensions/browser/process_manager.h"
19 #include "extensions/test/background_page_watcher.h" 21 #include "extensions/test/background_page_watcher.h"
20 #include "extensions/test/extension_test_message_listener.h" 22 #include "extensions/test/extension_test_message_listener.h"
21 23
24 using content::BackgroundSyncTestUtil;
25
22 namespace extensions { 26 namespace extensions {
23 27
24 namespace { 28 namespace {
25 29
26 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that 30 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that
27 // registration is expected to succeed. 31 // registration is expected to succeed.
28 std::string* const kExpectSuccess = nullptr; 32 std::string* const kExpectSuccess = nullptr;
29 33
30 void DoNothingWithBool(bool b) {} 34 void DoNothingWithBool(bool b) {}
31 35
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return ExtractInnerText(Navigate(url)); 110 return ExtractInnerText(Navigate(url));
107 } 111 }
108 112
109 private: 113 private:
110 // Sets the channel to "trunk" since service workers are restricted to trunk. 114 // Sets the channel to "trunk" since service workers are restricted to trunk.
111 ScopedCurrentChannel current_channel_; 115 ScopedCurrentChannel current_channel_;
112 116
113 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTest); 117 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTest);
114 }; 118 };
115 119
120 class ServiceWorkerBackgroundSyncTest : public ServiceWorkerTest {
121 public:
122 ServiceWorkerBackgroundSyncTest() {}
123 ~ServiceWorkerBackgroundSyncTest() override {}
124
125 void SetUpCommandLine(base::CommandLine* command_line) override {
126 // ServiceWorkerRegistration.sync requires experimental flag.
127 command_line->AppendSwitch(
128 switches::kEnableExperimentalWebPlatformFeatures);
129 ServiceWorkerTest::SetUpCommandLine(command_line);
130 }
131
132 void SetUp() override {
133 BackgroundSyncTestUtil::SetIgnoreNetworkChangeNotifier(true);
134 ServiceWorkerTest::SetUp();
135 }
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerBackgroundSyncTest);
139 };
140
116 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterSucceedsOnTrunk) { 141 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterSucceedsOnTrunk) {
117 StartTestFromBackgroundPage("register.js", kExpectSuccess); 142 StartTestFromBackgroundPage("register.js", kExpectSuccess);
118 } 143 }
119 144
120 // This feature is restricted to trunk, so on dev it should have existing 145 // This feature is restricted to trunk, so on dev it should have existing
121 // behavior - which is for it to fail. 146 // behavior - which is for it to fail.
122 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterFailsOnDev) { 147 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterFailsOnDev) {
123 ScopedCurrentChannel current_channel_override( 148 ScopedCurrentChannel current_channel_override(
124 version_info::Channel::DEV); 149 version_info::Channel::DEV);
125 std::string error; 150 std::string error;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // should fail. 360 // should fail.
336 // Note that this also tests that service workers can be registered from tabs. 361 // Note that this also tests that service workers can be registered from tabs.
337 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); 362 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html"));
338 } 363 }
339 364
340 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { 365 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) {
341 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", 366 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission",
342 "page.html")); 367 "page.html"));
343 } 368 }
344 369
370 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) {
371 const Extension* extension = LoadExtensionWithFlags(
372 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone);
373 ASSERT_TRUE(extension);
374 GURL extension_url = extension->url();
Devlin 2015/11/16 18:12:41 nit: Is this used?
lazyboy 2015/11/16 19:30:16 Fixed.
375 GURL url = extension->GetResourceURL("page.html");
Devlin 2015/11/16 18:12:41 I'd probably just inline this if it's only used on
lazyboy 2015/11/16 19:30:16 Done.
376 ui_test_utils::NavigateToURL(browser(), url);
377 content::WebContents* web_contents =
378 browser()->tab_strip_model()->GetActiveWebContents();
379
380 // Prevent firing by going offline.
381 BackgroundSyncTestUtil::SetOnline(web_contents, false);
382 std::string result;
383 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
384 web_contents, "window.runServiceWorker()", &result));
385 ASSERT_EQ("SERVICE_WORKER_READY", result);
386
387 ExtensionTestMessageListener sync_listener("SYNC: send-chats", false);
388 sync_listener.set_failure_message("FAIL");
389 // Resume firing by going online.
390 BackgroundSyncTestUtil::SetOnline(web_contents, true);
391 EXPECT_TRUE(sync_listener.WaitUntilSatisfied());
392 }
393
345 } // namespace extensions 394 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698