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

Side by Side Diff: chrome/browser/extensions/service_worker_apitest.cc

Issue 1390943003: Bypass ServiceWorker when the request originates from isolated world. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add browser test Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "base/bind_helpers.h" 5 #include "base/bind_helpers.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
11 #include "components/version_info/version_info.h" 12 #include "components/version_info/version_info.h"
12 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/page_type.h" 16 #include "content/public/common/page_type.h"
16 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
17 #include "extensions/browser/extension_host.h" 18 #include "extensions/browser/extension_host.h"
18 #include "extensions/browser/process_manager.h" 19 #include "extensions/browser/process_manager.h"
19 #include "extensions/test/background_page_watcher.h" 20 #include "extensions/test/background_page_watcher.h"
20 #include "extensions/test/extension_test_message_listener.h" 21 #include "extensions/test/extension_test_message_listener.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
21 23
22 namespace extensions { 24 namespace extensions {
23 25
24 namespace { 26 namespace {
25 27
26 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that 28 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that
27 // registration is expected to succeed. 29 // registration is expected to succeed.
28 std::string* const kExpectSuccess = nullptr; 30 std::string* const kExpectSuccess = nullptr;
29 31
30 void DoNothingWithBool(bool b) {} 32 void DoNothingWithBool(bool b) {}
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 332
331 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, 333 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
332 GetBackgroundClientFailsWithNoBackgroundPage) { 334 GetBackgroundClientFailsWithNoBackgroundPage) {
333 // This extension doesn't have a background page, only a tab at page.html. 335 // This extension doesn't have a background page, only a tab at page.html.
334 // The service worker it registers tries to call getBackgroundClient() and 336 // The service worker it registers tries to call getBackgroundClient() and
335 // should fail. 337 // should fail.
336 // Note that this also tests that service workers can be registered from tabs. 338 // Note that this also tests that service workers can be registered from tabs.
337 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); 339 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html"));
338 } 340 }
339 341
342 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
343 FetchFromContentScriptShouldNotGoToServiceWorkerOfPage) {
344 ASSERT_TRUE(StartEmbeddedTestServer());
345 GURL page_url = embedded_test_server()->GetURL(
346 "/extensions/api_test/service_worker/content_script_fetch/"
347 "controlled_page/index.html");
348 content::WebContents* tab =
349 browser()->tab_strip_model()->GetActiveWebContents();
350 ui_test_utils::NavigateToURL(browser(), page_url);
351 content::WaitForLoadStop(tab);
352
353 std::string value;
354 ASSERT_TRUE(
355 content::ExecuteScriptAndExtractString(tab, "register();", &value));
356 EXPECT_EQ("SW controlled", value);
357
358 ASSERT_TRUE(RunExtensionTest("service_worker/content_script_fetch"))
359 << message_;
360 }
361
340 } // namespace extensions 362 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698