Commit 1066e17a authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[Extensions SW] Fix and enable a fetch related test.

This CL enables ServiceWorkerTest.
FetchFromContentScriptShouldNotGoToServiceWorkerOfPage

The test expects fetch to "./sw_controlled_check" to be handled
by its registered worker. But this test initiates the fetch
a bit earlier than expected, specifically in failure/flaky cases.
This CL ensures that the page is being controlled by the service
worker before initiating the fetch from index.html. It does so
by waiting for oncontrollerchange event to occur.

Bug: 1014222
Change-Id: Ib235a6a80957b6f8c22ca5e167e1d37a86cc1850
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208027
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770384}
parent 9c75220c
...@@ -1528,9 +1528,8 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { ...@@ -1528,9 +1528,8 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) {
EXPECT_TRUE(sync_listener.WaitUntilSatisfied()); EXPECT_TRUE(sync_listener.WaitUntilSatisfied());
} }
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
ServiceWorkerTest, FetchFromContentScriptShouldNotGoToServiceWorkerOfPage) {
DISABLED_FetchFromContentScriptShouldNotGoToServiceWorkerOfPage) {
ASSERT_TRUE(StartEmbeddedTestServer()); ASSERT_TRUE(StartEmbeddedTestServer());
GURL page_url = embedded_test_server()->GetURL( GURL page_url = embedded_test_server()->GetURL(
"/extensions/api_test/service_worker/content_script_fetch/" "/extensions/api_test/service_worker/content_script_fetch/"
......
...@@ -20,6 +20,21 @@ function register() { ...@@ -20,6 +20,21 @@ function register() {
registration.active.postMessage({port: channel.port2}, [channel.port2]); registration.active.postMessage({port: channel.port2}, [channel.port2]);
return saw_message; return saw_message;
}) })
.then(function() {
// Wait for service worker to control us.
return new Promise(function(resolve, reject) {
if (navigator.serviceWorker.controller) {
resolve();
return;
}
navigator.serviceWorker.oncontrollerchange = function(e) {
if (navigator.serviceWorker.controller) {
resolve();
return;
}
};
});
})
.then(function() { return fetch('./sw_controlled_check'); }) .then(function() { return fetch('./sw_controlled_check'); })
.then(function(res) { return res.text(); }) .then(function(res) { return res.text(); })
.then(function(txt) { window.domAutomationController.send(txt); }) .then(function(txt) { window.domAutomationController.send(txt); })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment