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

Unified Diff: chrome/browser/chrome_service_worker_browsertest.cc

Issue 2778173002: Revert of "Speculatively launch Service Workers on mouse/touch events." (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/flag_descriptions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_service_worker_browsertest.cc
diff --git a/chrome/browser/chrome_service_worker_browsertest.cc b/chrome/browser/chrome_service_worker_browsertest.cc
index 660b816de158d3f8cb633e04373f573b7ccf4862..d0c862ba36cd39e184a60df57cb2ddbd69678dad 100644
--- a/chrome/browser/chrome_service_worker_browsertest.cc
+++ b/chrome/browser/chrome_service_worker_browsertest.cc
@@ -12,7 +12,6 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
@@ -30,8 +29,6 @@
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/common/content_features.h"
-#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ppapi/shared_impl/ppapi_switches.h"
@@ -607,109 +604,4 @@ IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerFetchPPAPIPrivateTest,
ExecutePNACLUrlLoaderTest("OtherCORSCredentials"));
}
-class ServiceWorkerSpeculativeLaunchTest : public ChromeServiceWorkerTest {
- protected:
- static const std::string kNavigationHintLinkMouseDownMetricName;
-
- ServiceWorkerSpeculativeLaunchTest() {}
- ~ServiceWorkerSpeculativeLaunchTest() override {}
-
- void SetUpCommandLine(base::CommandLine* command_line) override {
- command_line->AppendSwitchASCII(
- switches::kEnableFeatures,
- features::kSpeculativeLaunchServiceWorker.name);
- }
-
- void WriteTestHtmlFile() {
- WriteFile(
- FILE_PATH_LITERAL("test.html"),
- "<script>"
- "navigator.serviceWorker.register('./sw.js', {scope: './scope.html'})"
- " .then(function(reg) {"
- " reg.addEventListener('updatefound', function() {"
- " var worker = reg.installing;"
- " worker.addEventListener('statechange', function() {"
- " if (worker.state == 'activated')"
- " document.title = 'READY';"
- " });"
- " });"
- " });"
- "</script>"
- "<body style='margin:0; padding:0;'>"
- "<a href='./scope.html' "
- "style='position:fixed; width:1px; height:1px;'></a>"
- "</body>");
- }
-
- void RunNavigationHintTest() {
- embedded_test_server()->ServeFilesFromDirectory(
- service_worker_dir_.GetPath());
- ASSERT_TRUE(embedded_test_server()->Start());
-
- content::ServiceWorkerContext* sw_context =
- content::BrowserContext::GetDefaultStoragePartition(
- browser()->profile())
- ->GetServiceWorkerContext();
-
- const base::string16 expected_title1 = base::ASCIIToUTF16("READY");
- content::TitleWatcher title_watcher1(
- browser()->tab_strip_model()->GetActiveWebContents(), expected_title1);
- ui_test_utils::NavigateToURL(browser(),
- embedded_test_server()->GetURL("/test.html"));
- EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
-
- histogram_tester_.ExpectBucketCount("ServiceWorker.StartNewWorker.Status",
- 0 /* SERVICE_WORKER_OK */, 1);
-
- sw_context->StopAllServiceWorkersForOrigin(
- embedded_test_server()->base_url());
-
- const base::string16 expected_title2 = base::ASCIIToUTF16("Done");
- content::TitleWatcher title_watcher2(
- browser()->tab_strip_model()->GetActiveWebContents(), expected_title2);
-
- histogram_tester_.ExpectTotalCount(kNavigationHintLinkMouseDownMetricName,
- 0);
- content::SimulateMouseClickAt(
- browser()->tab_strip_model()->GetActiveWebContents(), 0,
- blink::WebMouseEvent::Button::Left, gfx::Point(0, 0));
- EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
- }
-
- base::HistogramTester histogram_tester_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ServiceWorkerSpeculativeLaunchTest);
-};
-
-// static
-const std::string
- ServiceWorkerSpeculativeLaunchTest::kNavigationHintLinkMouseDownMetricName =
- "ServiceWorker.StartWorker.StatusByPurpose_"
- "NAVIGATION_HINT_LINK_MOUSE_DOWN";
-
-IN_PROC_BROWSER_TEST_F(ServiceWorkerSpeculativeLaunchTest, MouseDown) {
- WriteFile(
- FILE_PATH_LITERAL("sw.js"),
- "self.onfetch = function(e) {"
- " e.respondWith(new Response('<title>Done</title>',"
- " {headers: {'Content-Type': 'text/html'}}));"
- "};");
- WriteTestHtmlFile();
- RunNavigationHintTest();
- // The service worker must be started by a navigation hint.
- histogram_tester_.ExpectBucketCount(kNavigationHintLinkMouseDownMetricName,
- 0 /* SERVICE_WORKER_OK */, 1);
-}
-
-IN_PROC_BROWSER_TEST_F(ServiceWorkerSpeculativeLaunchTest,
- NoFetchEventHandler) {
- WriteFile(FILE_PATH_LITERAL("sw.js"), "// no fetch event handler.");
- WriteFile(FILE_PATH_LITERAL("scope.html"), "<title>Done</title>");
- WriteTestHtmlFile();
- RunNavigationHintTest();
- // The service worker must NOT be started by a navigation hint.
- histogram_tester_.ExpectTotalCount(kNavigationHintLinkMouseDownMetricName, 0);
-}
-
} // namespace
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/flag_descriptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698