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

Unified Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 2473263003: Set "Service-Worker-Navigation-Preload" header (Closed)
Patch Set: incorporated falken's comment Created 4 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 | content/browser/service_worker/service_worker_fetch_dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_browsertest.cc
diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc
index 2504b081d2f95759616ee82585ecfa9ab3449225..560e3b51d2b45b593306fbf4fcd283cd1f832b6c 100644
--- a/content/browser/service_worker/service_worker_browsertest.cc
+++ b/content/browser/service_worker/service_worker_browsertest.cc
@@ -1416,9 +1416,24 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
}
protected:
+ static const std::string kNavigationPreloadHeaderName;
+ static const std::string kEnableNavigationPreloadScript;
+ static const std::string kPreloadResponseTestScript;
+
+ static bool HasNavigationPreloadHeader(
+ const net::test_server::HttpRequest& request) {
+ return request.headers.find(kNavigationPreloadHeaderName) !=
+ request.headers.end();
+ }
+
+ static std::string GetNavigationPreloadHeader(
+ const net::test_server::HttpRequest& request) {
+ DCHECK(HasNavigationPreloadHeader(request));
+ return request.headers.find(kNavigationPreloadHeaderName)->second;
+ }
+
void SetupForNavigationPreloadTest(const GURL& scope,
- const GURL& worker_url,
- bool enable_navigation_preload) {
+ const GURL& worker_url) {
scoped_refptr<WorkerActivatedObserver> observer =
new WorkerActivatedObserver(wrapper());
observer->Init();
@@ -1426,10 +1441,6 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
scope, worker_url,
base::Bind(&ExpectResultAndRun, true, base::Bind(&base::DoNothing)));
observer->Wait();
- if (enable_navigation_preload) {
- RunOnIOThread(base::Bind(&self::EnableNavigationPreloadOnIO,
- base::Unretained(this), scope));
- }
embedded_test_server()->RegisterRequestMonitor(
base::Bind(&self::MonitorRequestHandler, base::Unretained(this)));
@@ -1458,12 +1469,10 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
}
int GetRequestCount(const std::string& relative_url) const {
- int count = 0;
- for (const auto& request : request_log_) {
- if (request == relative_url)
- ++count;
- }
- return count;
+ const auto& it = request_log_.find(relative_url);
+ if (it == request_log_.end())
+ return 0;
+ return it->second.size();
}
std::string GetTextContent() {
@@ -1476,7 +1485,8 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
return text_content;
}
- static const char kPreloadResponseTestScript[];
+ std::map<std::string, std::vector<net::test_server::HttpRequest>>
+ request_log_;
private:
class CustomResponse : public net::test_server::HttpResponse {
@@ -1496,23 +1506,6 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
DISALLOW_COPY_AND_ASSIGN(CustomResponse);
};
- void EnableNavigationPreloadOnIO(const GURL& scope,
- const base::Closure& continuation) {
- wrapper()->FindReadyRegistrationForDocument(
- scope, base::Bind(&self::DidFindRegistrationForEnableNavigationPreload,
- base::Unretained(this), continuation));
- }
-
- void DidFindRegistrationForEnableNavigationPreload(
- const base::Closure& continuation,
- ServiceWorkerStatusCode status,
- scoped_refptr<ServiceWorkerRegistration> registration) {
- EXPECT_EQ(SERVICE_WORKER_OK, status);
- ASSERT_TRUE(registration->active_version());
- registration->EnableNavigationPreload(true);
- continuation.Run();
- }
-
std::unique_ptr<net::test_server::HttpResponse> StaticRequestHandler(
const std::string& relative_url,
const std::string& content,
@@ -1558,72 +1551,81 @@ class ServiceWorkerNavigationPreloadTest : public ServiceWorkerBrowserTest {
}
void MonitorRequestHandler(const net::test_server::HttpRequest& request) {
- request_log_.push_back(request.relative_url);
+ request_log_[request.relative_url].push_back(request);
}
-
- std::vector<std::string> request_log_;
};
-const char ServiceWorkerNavigationPreloadTest::kPreloadResponseTestScript[] =
- "var preload_resolve;\n"
- "var preload_promise = new Promise(r => { preload_resolve = r; });\n"
- "self.addEventListener('fetch', event => {\n"
- " event.waitUntil(event.preloadResponse.then(\n"
- " r => {\n"
- " if (!r) {\n"
- " preload_resolve(\n"
- " {result: 'RESOLVED', info: 'Resolved with ' + r + '.'});\n"
- " return;\n"
- " }\n"
- " var info = {};\n"
- " info.type = r.type;\n"
- " info.url = r.url;\n"
- " info.status = r.status;\n"
- " info.ok = r.ok;\n"
- " info.statusText = r.statusText;\n"
- " info.headers = [];\n"
- " r.headers.forEach((v, n) => { info.headers.push([n,v]); });\n"
- " preload_resolve({result: 'RESOLVED',\n"
- " info: JSON.stringify(info)}); },\n"
- " e => { preload_resolve({result: 'REJECTED',\n"
- " info: e.toString()}); }));\n"
- " event.respondWith(\n"
- " new Response(\n"
- " '<title>WAITING</title><script>\\n' +\n"
- " 'var channel = new MessageChannel();\\n' +\n"
- " 'channel.port1.onmessage = e => {\\n' +\n"
- " ' var div = document.createElement(\\'div\\');\\n' +\n"
- " ' div.appendChild(' +\n"
- " ' document.createTextNode(e.data.info));\\n' +\n"
- " ' document.body.appendChild(div);\\n' +\n"
- " ' document.title = e.data.result;\\n' +\n"
- " ' };\\n' +\n"
- " 'navigator.serviceWorker.controller.postMessage(\\n' +\n"
- " ' {}, [channel.port2]);\\n' +\n"
- " '</script>',"
- " {headers: [['content-type', 'text/html']]}));\n"
- " });\n"
- "self.addEventListener('message', event => {\n"
- " event.waitUntil(\n"
- " preload_promise.then(\n"
- " result => event.ports[0].postMessage(result)));\n"
- " });";
+const std::string
+ ServiceWorkerNavigationPreloadTest::kNavigationPreloadHeaderName(
+ "Service-Worker-Navigation-Preload");
+
+const std::string
+ ServiceWorkerNavigationPreloadTest::kEnableNavigationPreloadScript(
+ "self.addEventListener('install', event => {\n"
+ " event.waitUntil(self.registration.navigationPreload.enable());\n"
+ " });\n");
+
+const std::string
+ ServiceWorkerNavigationPreloadTest::kPreloadResponseTestScript =
+ "var preload_resolve;\n"
+ "var preload_promise = new Promise(r => { preload_resolve = r; });\n"
+ "self.addEventListener('fetch', event => {\n"
+ " event.waitUntil(event.preloadResponse.then(\n"
+ " r => {\n"
+ " if (!r) {\n"
+ " preload_resolve(\n"
+ " {result: 'RESOLVED', \n"
+ " info: 'Resolved with ' + r + '.'});\n"
+ " return;\n"
+ " }\n"
+ " var info = {};\n"
+ " info.type = r.type;\n"
+ " info.url = r.url;\n"
+ " info.status = r.status;\n"
+ " info.ok = r.ok;\n"
+ " info.statusText = r.statusText;\n"
+ " info.headers = [];\n"
+ " r.headers.forEach(\n"
+ " (v, n) => { info.headers.push([n,v]); });\n"
+ " preload_resolve({result: 'RESOLVED',\n"
+ " info: JSON.stringify(info)}); },\n"
+ " e => { preload_resolve({result: 'REJECTED',\n"
+ " info: e.toString()}); }));\n"
+ " event.respondWith(\n"
+ " new Response(\n"
+ " '<title>WAITING</title><script>\\n' +\n"
+ " 'navigator.serviceWorker.onmessage = e => {\\n' +\n"
+ " ' var div = document.createElement(\\'div\\');\\n' +\n"
+ " ' div.appendChild(' +\n"
+ " ' document.createTextNode(e.data.info));\\n' +\n"
+ " ' document.body.appendChild(div);\\n' +\n"
+ " ' document.title = e.data.result;\\n' +\n"
+ " ' };\\n' +\n"
+ " 'navigator.serviceWorker.controller.postMessage(\\n' +\n"
+ " ' null);\\n' +\n"
+ " '</script>',"
+ " {headers: [['content-type', 'text/html']]}));\n"
+ " });\n"
+ "self.addEventListener('message', event => {\n"
+ " event.waitUntil(\n"
+ " preload_promise.then(\n"
+ " result => event.source.postMessage(result)));\n"
+ " });";
IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, NetworkFallback) {
const char kPageUrl[] = "/service_worker/navigation_preload.html";
const char kWorkerUrl[] = "/service_worker/navigation_preload.js";
const char kPage[] = "<title>PASS</title>Hello world.";
- const char kScript[] =
- "self.addEventListener('fetch', event => {\n"
- " // Do nothing.\n"
- " });";
+ const std::string kScript = kEnableNavigationPreloadScript +
+ "self.addEventListener('fetch', event => {\n"
+ " // Do nothing.\n"
+ " });";
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
RegisterStaticFile(kPageUrl, kPage, "text/html");
RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("PASS");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1633,9 +1635,93 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, NetworkFallback) {
// The page request must be sent twice. Once for navigation preload, and once
// for fallback since respondWith wasn't used.
- EXPECT_EQ(2, GetRequestCount(kPageUrl));
- // TODO(horo): Check "Service-Worker-Navigation-Preload" header.
- // See: https://github.com/w3c/ServiceWorker/issues/920#issuecomment-251150270
+ ASSERT_EQ(2, GetRequestCount(kPageUrl));
+ ASSERT_TRUE(HasNavigationPreloadHeader(request_log_[kPageUrl][0]));
+ EXPECT_EQ("true", GetNavigationPreloadHeader(request_log_[kPageUrl][0]));
+ EXPECT_FALSE(HasNavigationPreloadHeader(request_log_[kPageUrl][1]));
+}
+
+IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, SetHeaderValue) {
+ const std::string kPageUrl = "/service_worker/navigation_preload.html";
+ const std::string kWorkerUrl = "/service_worker/navigation_preload.js";
+ const std::string kPage = "<title>FROM_SERVER</title>";
+ const std::string kScript =
+ "function createResponse(title, body) {\n"
+ " return new Response('<title>' + title + '</title>' + body,\n"
+ " {headers: [['content-type', 'text/html']]})\n"
+ "}\n"
+ "self.addEventListener('fetch', event => {\n"
+ " if (event.request.url.indexOf('?enable') != -1) {\n"
+ " event.respondWith(\n"
+ " self.registration.navigationPreload.enable()\n"
+ " .then(_ => event.preloadResponse)\n"
+ " .then(res => createResponse('ENABLED', res)));\n"
+ " } else if (event.request.url.indexOf('?change') != -1) {\n"
+ " event.respondWith(\n"
+ " self.registration.navigationPreload.setHeaderValue('Hello')\n"
+ " .then(_ => event.preloadResponse)\n"
+ " .then(res => createResponse('CHANGED', res)));\n"
+ " } else if (event.request.url.indexOf('?disable') != -1) {\n"
+ " event.respondWith(\n"
+ " self.registration.navigationPreload.disable()\n"
+ " .then(_ => event.preloadResponse)\n"
+ " .then(res => createResponse('DISABLED', res)));\n"
+ " } else if (event.request.url.indexOf('?test') != -1) {\n"
+ " event.respondWith(event.preloadResponse.then(res =>\n"
+ " createResponse('TEST', res)));\n"
+ " }\n"
+ " });";
+ const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
+ const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
+ RegisterStaticFile(kPageUrl, kPage, "text/html");
+ RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
+
+ SetupForNavigationPreloadTest(page_url, worker_url);
+
+ const std::string kPageUrl1 = kPageUrl + "?enable";
+ const base::string16 title1 = base::ASCIIToUTF16("ENABLED");
+ TitleWatcher title_watcher1(shell()->web_contents(), title1);
+ title_watcher1.AlsoWaitForTitle(base::ASCIIToUTF16("FROM_SERVER"));
+ NavigateToURL(shell(), embedded_test_server()->GetURL(kPageUrl1));
+ EXPECT_EQ(title1, title_watcher1.WaitAndGetTitle());
+ // When the navigation started, the navigation preload was not enabled yet.
+ EXPECT_EQ("null", GetTextContent());
+ ASSERT_EQ(0, GetRequestCount(kPageUrl1));
+
+ const std::string kPageUrl2 = kPageUrl + "?change";
+ const base::string16 title2 = base::ASCIIToUTF16("CHANGED");
+ TitleWatcher title_watcher2(shell()->web_contents(), title2);
+ title_watcher2.AlsoWaitForTitle(base::ASCIIToUTF16("FROM_SERVER"));
+ NavigateToURL(shell(), embedded_test_server()->GetURL(kPageUrl2));
+ EXPECT_EQ(title2, title_watcher2.WaitAndGetTitle());
+ // When the navigation started, the navigation preload was enabled, but the
+ // header was not changed yet.
+ EXPECT_EQ("[object Response]", GetTextContent());
+ ASSERT_EQ(1, GetRequestCount(kPageUrl2));
+ ASSERT_TRUE(HasNavigationPreloadHeader(request_log_[kPageUrl2][0]));
+ EXPECT_EQ("true", GetNavigationPreloadHeader(request_log_[kPageUrl2][0]));
+
+ const std::string kPageUrl3 = kPageUrl + "?disable";
+ const base::string16 title3 = base::ASCIIToUTF16("DISABLED");
+ TitleWatcher title_watcher3(shell()->web_contents(), title3);
+ title_watcher3.AlsoWaitForTitle(base::ASCIIToUTF16("FROM_SERVER"));
+ NavigateToURL(shell(), embedded_test_server()->GetURL(kPageUrl3));
+ EXPECT_EQ(title3, title_watcher3.WaitAndGetTitle());
+ // When the navigation started, the navigation preload was not disabled yet.
+ EXPECT_EQ("[object Response]", GetTextContent());
+ ASSERT_EQ(1, GetRequestCount(kPageUrl3));
+ ASSERT_TRUE(HasNavigationPreloadHeader(request_log_[kPageUrl3][0]));
+ EXPECT_EQ("Hello", GetNavigationPreloadHeader(request_log_[kPageUrl3][0]));
+
+ const std::string kPageUrl4 = kPageUrl + "?test";
+ const base::string16 title4 = base::ASCIIToUTF16("TEST");
+ TitleWatcher title_watcher4(shell()->web_contents(), title4);
+ title_watcher4.AlsoWaitForTitle(base::ASCIIToUTF16("FROM_SERVER"));
+ NavigateToURL(shell(), embedded_test_server()->GetURL(kPageUrl4));
+ EXPECT_EQ(title4, title_watcher4.WaitAndGetTitle());
+ // When the navigation started, the navigation preload must be disabled.
+ EXPECT_EQ("null", GetTextContent());
+ ASSERT_EQ(0, GetRequestCount(kPageUrl4));
}
IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
@@ -1643,7 +1729,8 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
const char kPageUrl[] = "/service_worker/navigation_preload.html";
const char kWorkerUrl[] = "/service_worker/navigation_preload.js";
const char kPage[] = "<title>PASS</title>Hello world.";
- const char kScript[] =
+ const std::string kScript =
+ kEnableNavigationPreloadScript +
"self.addEventListener('fetch', event => {\n"
" if (!event.preloadResponse) {\n"
" event.respondWith(\n"
@@ -1658,8 +1745,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
RegisterStaticFile(kPageUrl, kPage, "text/html");
RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("PASS");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1670,16 +1756,17 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
// The page request must be sent only once, since the worker responded with
// the navigation preload response
- EXPECT_EQ(1, GetRequestCount(kPageUrl));
- // TODO(horo): Check "Service-Worker-Navigation-Preload" header.
- // See: https://github.com/w3c/ServiceWorker/issues/920#issuecomment-251150270
+ ASSERT_EQ(1, GetRequestCount(kPageUrl));
+ EXPECT_EQ("true",
+ request_log_[kPageUrl][0].headers[kNavigationPreloadHeaderName]);
}
IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, GetResponseText) {
const char kPageUrl[] = "/service_worker/navigation_preload.html";
const char kWorkerUrl[] = "/service_worker/navigation_preload.js";
const char kPage[] = "<title>PASS</title>Hello world.";
- const char kScript[] =
+ const std::string kScript =
+ kEnableNavigationPreloadScript +
"self.addEventListener('fetch', event => {\n"
" event.respondWith(\n"
" event.preloadResponse\n"
@@ -1694,8 +1781,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, GetResponseText) {
RegisterStaticFile(kPageUrl, kPage, "text/html");
RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("PASS");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1716,7 +1802,8 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
// In this script, event.preloadResponse is not guarded by event.waitUntil.
// So the preload request should be canceled, when the fetch event handler
// has been executed.
- const char kScript[] =
+ const std::string kScript =
+ kEnableNavigationPreloadScript +
"var preload_resolve;\n"
"var preload_promise = new Promise(r => { preload_resolve = r; });\n"
"self.addEventListener('fetch', event => {\n"
@@ -1728,8 +1815,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
" event.respondWith(\n"
" new Response(\n"
" '<title>WAITING</title><script>\\n' +\n"
- " 'var channel = new MessageChannel();\\n' +\n"
- " 'channel.port1.onmessage = e => {\\n' +\n"
+ " 'navigator.serviceWorker.onmessage = e => {\\n' +\n"
" ' var div = document.createElement(\\'div\\');\\n' +\n"
" ' div.appendChild(' +\n"
" ' document.createTextNode(e.data.info));\\n' +\n"
@@ -1737,22 +1823,21 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
" ' document.title = e.data.result;\\n' +\n"
" ' };\\n' +\n"
" 'navigator.serviceWorker.controller.postMessage(\\n' +\n"
- " ' {}, [channel.port2]);\\n' +\n"
+ " ' null);\\n' +\n"
" '</script>',"
" {headers: [['content-type', 'text/html']]}));\n"
" });\n"
"self.addEventListener('message', event => {\n"
" event.waitUntil(\n"
" preload_promise.then(\n"
- " result => event.ports[0].postMessage(result)));\n"
+ " result => event.source.postMessage(result)));\n"
" });";
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
RegisterStaticFile(kPageUrl, kPage, "text/html");
RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("REJECTED");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1772,10 +1857,11 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, NetworkError) {
const char kWorkerUrl[] = "/service_worker/navigation_preload.js";
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
- RegisterStaticFile(kWorkerUrl, kPreloadResponseTestScript, "text/javascript");
+ RegisterStaticFile(
+ kWorkerUrl, kEnableNavigationPreloadScript + kPreloadResponseTestScript,
+ "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
@@ -1796,10 +1882,11 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
RegisterStaticFile(kPageUrl, kPage, "text/html");
- RegisterStaticFile(kWorkerUrl, kPreloadResponseTestScript, "text/javascript");
+ RegisterStaticFile(
+ kWorkerUrl, kEnableNavigationPreloadScript + kPreloadResponseTestScript,
+ "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("RESOLVED");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1834,8 +1921,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, NotEnabled) {
RegisterStaticFile(kPageUrl, kPage, "text/html");
RegisterStaticFile(kWorkerUrl, kPreloadResponseTestScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- false /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("RESOLVED");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1868,10 +1954,11 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
RegisterCustomResponse(kPageUrl, kPageResponse);
- RegisterStaticFile(kWorkerUrl, kPreloadResponseTestScript, "text/javascript");
+ RegisterStaticFile(
+ kWorkerUrl, kEnableNavigationPreloadScript + kPreloadResponseTestScript,
+ "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("RESOLVED");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1916,11 +2003,12 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest, RejectRedirects) {
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
RegisterCustomResponse(kPageUrl, kPageResponse);
- RegisterStaticFile(kWorkerUrl, kPreloadResponseTestScript, "text/javascript");
+ RegisterStaticFile(
+ kWorkerUrl, kEnableNavigationPreloadScript + kPreloadResponseTestScript,
+ "text/javascript");
RegisterStaticFile(kRedirectedPageUrl, kRedirectedPage, "text/html");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("REJECTED");
TitleWatcher title_watcher(shell()->web_contents(), title);
@@ -1948,7 +2036,8 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
const char kPage[] =
"<title></title>\n"
"<script>document.title = document.location.search;</script>";
- const char kScript[] =
+ const std::string kScript =
+ kEnableNavigationPreloadScript +
"self.addEventListener('fetch', event => {\n"
" if (event.request.url.indexOf('navigation_preload.html') == -1)\n"
" return; // For in scope redirection.\n"
@@ -1967,8 +2056,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
RegisterKeepSearchRedirect(kInScopeRedirectPageUrl, page_url.spec());
SetupForNavigationPreloadTest(
- embedded_test_server()->GetURL("/service_worker/"), worker_url,
- true /* enable_navigation_preload */);
+ embedded_test_server()->GetURL("/service_worker/"), worker_url);
const GURL redirect_page_url =
embedded_test_server()->GetURL(kRedirectPageUrl).Resolve("?1");
@@ -2014,10 +2102,10 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
const char kPageUrl[] = "/service_worker/navigation_preload.html";
const char kWorkerUrl[] = "/service_worker/navigation_preload.js";
const char kPage[] = "<title>PASS</title>Hello world.";
- const char kScript[] =
- "self.addEventListener('fetch', event => {\n"
- " event.respondWith(event.preloadResponse);\n"
- " });";
+ const std::string kScript = kEnableNavigationPreloadScript +
+ "self.addEventListener('fetch', event => {\n"
+ " event.respondWith(event.preloadResponse);\n"
+ " });";
const GURL page_url = embedded_test_server()->GetURL(kPageUrl);
const GURL worker_url = embedded_test_server()->GetURL(kWorkerUrl);
@@ -2025,8 +2113,7 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerNavigationPreloadTest,
RegisterStaticFile(kPageUrl, kPage, "");
RegisterStaticFile(kWorkerUrl, kScript, "text/javascript");
- SetupForNavigationPreloadTest(page_url, worker_url,
- true /* enable_navigation_preload */);
+ SetupForNavigationPreloadTest(page_url, worker_url);
const base::string16 title = base::ASCIIToUTF16("PASS");
TitleWatcher title_watcher(shell()->web_contents(), title);
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_fetch_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698