Chromium Code Reviews| Index: chrome/browser/extensions/service_worker_apitest.cc |
| diff --git a/chrome/browser/extensions/service_worker_apitest.cc b/chrome/browser/extensions/service_worker_apitest.cc |
| index b1018d8c447bc438492006a67f62da02ef7e9eb7..75768747620c37b079d43836240077a3ebf6a8f1 100644 |
| --- a/chrome/browser/extensions/service_worker_apitest.cc |
| +++ b/chrome/browser/extensions/service_worker_apitest.cc |
| @@ -12,13 +12,17 @@ |
| #include "content/public/browser/navigation_controller.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/common/content_switches.h" |
| #include "content/public/common/page_type.h" |
| +#include "content/public/test/background_sync_test_util.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "extensions/browser/extension_host.h" |
| #include "extensions/browser/process_manager.h" |
| #include "extensions/test/background_page_watcher.h" |
| #include "extensions/test/extension_test_message_listener.h" |
| +using content::BackgroundSyncTestUtil; |
| + |
| namespace extensions { |
| namespace { |
| @@ -113,6 +117,27 @@ class ServiceWorkerTest : public ExtensionApiTest { |
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTest); |
| }; |
| +class ServiceWorkerBackgroundSyncTest : public ServiceWorkerTest { |
| + public: |
| + ServiceWorkerBackgroundSyncTest() {} |
| + ~ServiceWorkerBackgroundSyncTest() override {} |
| + |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + // ServiceWorkerRegistration.sync requires experimental flag. |
| + command_line->AppendSwitch( |
| + switches::kEnableExperimentalWebPlatformFeatures); |
| + ServiceWorkerTest::SetUpCommandLine(command_line); |
| + } |
| + |
| + void SetUp() override { |
| + BackgroundSyncTestUtil::SetIgnoreNetworkChangeNotifier(true); |
| + ServiceWorkerTest::SetUp(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ServiceWorkerBackgroundSyncTest); |
| +}; |
| + |
| IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterSucceedsOnTrunk) { |
| StartTestFromBackgroundPage("register.js", kExpectSuccess); |
| } |
| @@ -342,4 +367,28 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { |
| "page.html")); |
| } |
| +IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { |
| + const Extension* extension = LoadExtensionWithFlags( |
| + test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); |
| + ASSERT_TRUE(extension); |
| + GURL extension_url = extension->url(); |
|
Devlin
2015/11/16 18:12:41
nit: Is this used?
lazyboy
2015/11/16 19:30:16
Fixed.
|
| + 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.
|
| + ui_test_utils::NavigateToURL(browser(), url); |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + |
| + // Prevent firing by going offline. |
| + BackgroundSyncTestUtil::SetOnline(web_contents, false); |
| + std::string result; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| + web_contents, "window.runServiceWorker()", &result)); |
| + ASSERT_EQ("SERVICE_WORKER_READY", result); |
| + |
| + ExtensionTestMessageListener sync_listener("SYNC: send-chats", false); |
| + sync_listener.set_failure_message("FAIL"); |
| + // Resume firing by going online. |
| + BackgroundSyncTestUtil::SetOnline(web_contents, true); |
| + EXPECT_TRUE(sync_listener.WaitUntilSatisfied()); |
| +} |
| + |
| } // namespace extensions |