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

Side by Side Diff: chrome/browser/chrome_service_worker_browsertest.cc

Issue 2053573002: Speculatively launch Service Workers on mouse/touch events. [5/5] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/evnets/events/ Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | content/child/runtime_features.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file tests that Service Workers (a Content feature) work in the Chromium 5 // This file tests that Service Workers (a Content feature) work in the Chromium
6 // embedder. 6 // embedder.
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/histogram_tester.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/service_worker_context.h" 27 #include "content/public/browser/service_worker_context.h"
27 #include "content/public/browser/storage_partition.h" 28 #include "content/public/browser/storage_partition.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/content_features.h"
31 #include "content/public/common/content_switches.h"
29 #include "content/public/test/browser_test_utils.h" 32 #include "content/public/test/browser_test_utils.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h" 33 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "ppapi/shared_impl/ppapi_switches.h" 34 #include "ppapi/shared_impl/ppapi_switches.h"
32 35
33 namespace { 36 namespace {
34 37
35 class ChromeServiceWorkerTest : public InProcessBrowserTest { 38 class ChromeServiceWorkerTest : public InProcessBrowserTest {
36 protected: 39 protected:
37 ChromeServiceWorkerTest() { 40 ChromeServiceWorkerTest() {
38 EXPECT_TRUE(service_worker_dir_.CreateUniqueTempDir()); 41 EXPECT_TRUE(service_worker_dir_.CreateUniqueTempDir());
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 EXPECT_EQ(GetRequestStringForPNACL(), 512 EXPECT_EQ(GetRequestStringForPNACL(),
510 ExecutePNACLUrlLoaderTest("OtherCredentials")); 513 ExecutePNACLUrlLoaderTest("OtherCredentials"));
511 } 514 }
512 515
513 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerFetchPPAPIPrivateTest, 516 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerFetchPPAPIPrivateTest,
514 OtherOriginCORSCredentials) { 517 OtherOriginCORSCredentials) {
515 EXPECT_EQ(GetRequestStringForPNACL(), 518 EXPECT_EQ(GetRequestStringForPNACL(),
516 ExecutePNACLUrlLoaderTest("OtherCORSCredentials")); 519 ExecutePNACLUrlLoaderTest("OtherCORSCredentials"));
517 } 520 }
518 521
522 class ServiceWorkerSpeculativeLaunchTest : public ChromeServiceWorkerTest {
523 protected:
524 ServiceWorkerSpeculativeLaunchTest() {}
525 ~ServiceWorkerSpeculativeLaunchTest() override {}
526
527 void SetUpCommandLine(base::CommandLine* command_line) override {
528 command_line->AppendSwitchASCII(
529 switches::kEnableFeatures,
530 features::kSpeculativeLaunchServiceWorker.name);
531 }
532
533 base::HistogramTester histogram_tester_;
534
535 private:
536 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerSpeculativeLaunchTest);
537 };
538
539 IN_PROC_BROWSER_TEST_F(ServiceWorkerSpeculativeLaunchTest, MouseDown) {
540 WriteFile(
541 FILE_PATH_LITERAL("sw.js"),
542 "self.onfetch = function(e) {"
543 " e.respondWith(new Response('<title>Done</title>',"
544 " {headers: {'Content-Type': 'text/html'}}));"
545 "};");
546 WriteFile(
547 FILE_PATH_LITERAL("test.html"),
548 "<script>"
549 "navigator.serviceWorker.register('./sw.js', {scope: './scope/'})"
550 " .then(function(reg) {"
551 " reg.addEventListener('updatefound', function() {"
552 " var worker = reg.installing;"
553 " worker.addEventListener('statechange', function() {"
554 " if (worker.state == 'activated')"
555 " document.title = 'READY';"
556 " });"
557 " });"
558 " });"
559 "</script>"
560 "<body style='margin:0; padding:0;'>"
561 "<a href='./scope/' style='position:fixed; width:1px; height:1px;'></a>"
562 "</body>");
563
564 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path());
565 ASSERT_TRUE(embedded_test_server()->Start());
566
567 content::ServiceWorkerContext* sw_context =
568 content::BrowserContext::GetDefaultStoragePartition(browser()->profile())
569 ->GetServiceWorkerContext();
570
571 const base::string16 expected_title1 = base::ASCIIToUTF16("READY");
572 content::TitleWatcher title_watcher1(
573 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1);
574 ui_test_utils::NavigateToURL(browser(),
575 embedded_test_server()->GetURL("/test.html"));
576 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
577
578 histogram_tester_.ExpectBucketCount("ServiceWorker.StartNewWorker.Status",
579 0 /* SERVICE_WORKER_OK */, 1);
580
581 sw_context->StopAllServiceWorkersForOrigin(
582 embedded_test_server()->base_url());
583
584 const base::string16 expected_title2 = base::ASCIIToUTF16("Done");
585 content::TitleWatcher title_watcher2(
586 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2);
587
588 histogram_tester_.ExpectTotalCount(
589 "ServiceWorker.StartWorker.StatusByPurpose_NAVIGATION_HINT_LINK_MOUSE_"
590 "DOWN",
591 0);
592 content::SimulateMouseClickAt(
593 browser()->tab_strip_model()->GetActiveWebContents(), 0,
594 blink::WebMouseEvent::ButtonLeft, gfx::Point(0, 0));
595 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
596
597 // The service worker must be started by a navigation hint.
598 histogram_tester_.ExpectBucketCount(
599 "ServiceWorker.StartWorker.StatusByPurpose_NAVIGATION_HINT_LINK_MOUSE_"
600 "DOWN",
601 0 /* SERVICE_WORKER_OK */, 1);
602 }
603
519 } // namespace 604 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | content/child/runtime_features.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698