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

Unified Diff: chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc

Issue 2575523002: Prerender: Confirm ServiceWorkers are invoked for NoState Prefetch (Closed)
Patch Set: comments Created 3 years, 12 months 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
Index: chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc
diff --git a/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc b/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc
index 6c1d72ff9bc201bdcb292665c6110df47712c3d7..a00ec8ff25077e03eb676a81d7cdc2361a72c8ba 100644
--- a/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc
+++ b/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc
@@ -20,6 +20,8 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/service_worker_context.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/escape.h"
@@ -33,6 +35,15 @@ using prerender::test_utils::DestructionWaiter;
using prerender::test_utils::RequestCounter;
using prerender::test_utils::TestPrerender;
+namespace {
+
+void ClosureOnUiThread(const base::Closure& callback) {
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ callback);
+}
+
+} // namespace
+
namespace prerender {
// These URLs used for test resources must be relative with the exception of
@@ -49,6 +60,8 @@ const char kPrefetchResponseHeaderCSP[] =
"prerender/prefetch_response_csp.html";
const char kPrefetchScript[] = "prerender/prefetch.js";
const char kPrefetchScript2[] = "prerender/prefetch2.js";
+const char kServiceWorkerLoader[] = "prerender/service_worker.html";
+const char kServiceWorkerJavascript[] = "prerender/service_worker.js";
const char kPrefetchSubresourceRedirectPage[] =
"prerender/prefetch_subresource_redirect.html";
@@ -514,4 +527,36 @@ IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, IssuesIdlePriorityRequests) {
script_counter.WaitForCount(1);
}
+// Checks that a registered ServiceWorker (SW) without a renderer intercepts a
+// prefetch request.
+IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ServiceWorkerIntercept) {
+ // Register and launch a SW.
+ RequestCounter sw_counter;
+ CountRequestFor(kServiceWorkerJavascript, &sw_counter);
+ ui_test_utils::NavigateToURL(
+ current_browser(),
+ src_server()->GetURL(MakeAbsolute(kServiceWorkerLoader)));
+ sw_counter.WaitForCount(1);
horo 2017/01/05 05:33:58 You have to wait the service worker to be activate
mattcary 2017/01/05 14:30:43 Thanks! That seems much more reliable than just wa
+
+ // Stop the SW renderer process.
+ base::RunLoop run_loop;
+ content::StoragePartition* storage_partation =
+ content::BrowserContext::GetStoragePartitionForSite(
+ GetActiveWebContents()->GetBrowserContext(),
+ src_server()->GetURL(MakeAbsolute(kPrefetchPng)));
+ storage_partation->GetServiceWorkerContext()
+ ->StopAllServiceWorkersForOriginWithCallback(
+ src_server()->GetURL("/"),
+ base::Bind(&ClosureOnUiThread, run_loop.QuitClosure()));
+ run_loop.Run();
+
+ // The SW intercepts kPrefetchPage and replaces it with a body that contains
+ // an <img> tage for kPrefetchPng. This verifies that the SW ran correctly by
+ // observing the fetch of the image.
+ RequestCounter image_counter;
+ CountRequestFor(kPrefetchPng, &image_counter);
+ PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED);
+ image_counter.WaitForCount(1);
+}
+
} // namespace prerender
« no previous file with comments | « no previous file | chrome/test/data/prerender/service_worker.html » ('j') | content/public/browser/service_worker_context.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698