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

Unified 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: move background_sync_test_util to content namespace 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/service_worker/sync/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a4786927c2e4d4b7960c05f10270aaa5f9322f8e 100644
--- a/chrome/browser/extensions/service_worker_apitest.cc
+++ b/chrome/browser/extensions/service_worker_apitest.cc
@@ -12,7 +12,9 @@
#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"
@@ -113,6 +115,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 {
+ content::background_sync_test_util::SetIgnoreNetworkChangeNotifier(true);
+ ServiceWorkerTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerBackgroundSyncTest);
+};
+
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterSucceedsOnTrunk) {
StartTestFromBackgroundPage("register.js", kExpectSuccess);
}
@@ -342,4 +365,30 @@ 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);
+ ui_test_utils::NavigateToURL(browser(),
+ extension->GetResourceURL("page.html"));
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ // Prevent firing by going offline.
+ content::background_sync_test_util::SetOnline(web_contents, false);
+
+ ExtensionTestMessageListener sync_listener("SYNC: send-chats", false);
+ sync_listener.set_failure_message("FAIL");
+
+ std::string result;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractString(
+ web_contents, "window.runServiceWorker()", &result));
+ ASSERT_EQ("SERVICE_WORKER_READY", result);
+
+ EXPECT_FALSE(sync_listener.was_satisfied());
+ // Resume firing by going online.
+ content::background_sync_test_util::SetOnline(web_contents, true);
+ EXPECT_TRUE(sync_listener.WaitUntilSatisfied());
+}
+
} // namespace extensions
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/service_worker/sync/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698