Chromium Code Reviews| 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 a14ad92b52bd494d7856eab917ba6c61e43d3f8b..0f98e188cbacfacfb2f7eaf94e49c03eeaeed363 100644 |
| --- a/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc |
| +++ b/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/command_line.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_split.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/task_scheduler/post_task.h" |
| #include "chrome/browser/history/history_service_factory.h" |
| #include "chrome/browser/history/history_test_utils.h" |
| @@ -20,6 +21,10 @@ |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/service_worker_context.h" |
| +#include "content/public/browser/storage_partition.h" |
|
falken
2017/01/10 13:47:42
I think lines 25-26 are no longer needed.
mattcary
2017/01/10 15:15:28
Done.
|
| +#include "content/public/common/result_codes.h" |
| #include "content/public/common/url_constants.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "net/base/escape.h" |
| @@ -49,6 +54,7 @@ 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 kPrefetchSubresourceRedirectPage[] = |
| "prerender/prefetch_subresource_redirect.html"; |
| @@ -536,4 +542,42 @@ IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, IssuesIdlePriorityRequests) { |
| script_counter.WaitForCount(1); |
| } |
| +// Checks that a registered ServiceWorker (SW) that is not currently running |
| +// will intercepts a prefetch request. |
| +IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ServiceWorkerIntercept) { |
| + // Register and launch a SW. |
| + base::string16 expected_title = base::ASCIIToUTF16("SW READY"); |
| + content::TitleWatcher title_watcher(GetActiveWebContents(), expected_title); |
| + ui_test_utils::NavigateToURL( |
| + current_browser(), |
| + src_server()->GetURL(MakeAbsolute(kServiceWorkerLoader))); |
| + EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| + |
| + // Stop any SW. |
|
falken
2017/01/10 13:47:42
Could be worth mentioning that we're killing the r
mattcary
2017/01/10 15:15:28
Done.
|
| + int host_count = 0; |
| + for (content::RenderProcessHost::iterator iter( |
| + content::RenderProcessHost::AllHostsIterator()); |
| + !iter.IsAtEnd(); iter.Advance()) { |
| + ++host_count; |
| + iter.GetCurrentValue()->Shutdown(content::RESULT_CODE_KILLED, |
| + true /* wait */); |
| + } |
| + // There should be at most one render_process_host, that created for the SW. |
| + EXPECT_EQ(1, host_count); |
| + |
| + // Open a new tab to replace the one closed with all the RenderProcessHosts. |
|
clamy
2017/01/10 14:42:53
Note: if all the processes in a tab have been kill
mattcary
2017/01/10 15:15:28
I would have thought that as well, but if I don't
|
| + ui_test_utils::NavigateToURLWithDisposition( |
| + current_browser(), GURL(url::kAboutBlankURL), |
| + WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| + |
| + // 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 |