OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/test/scoped_feature_list.h" | 10 #include "base/test/scoped_feature_list.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_util.h" | 13 #include "chrome/browser/extensions/extension_util.h" |
14 #include "chrome/browser/extensions/test_extension_dir.h" | 14 #include "chrome/browser/extensions/test_extension_dir.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
16 #include "chrome/browser/ui/extensions/app_launch_params.h" | 16 #include "chrome/browser/ui/extensions/app_launch_params.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" | 18 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/content_features.h" | 24 #include "content/public/common/content_features.h" |
| 25 #include "content/public/common/content_switches.h" |
25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
27 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
29 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
30 #include "extensions/common/extension_set.h" | 31 #include "extensions/common/extension_set.h" |
31 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
32 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
33 | 34 |
34 #if defined(OS_MACOSX) | 35 #if defined(OS_MACOSX) |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } else { | 394 } else { |
394 // TODO(lukasza): https://crbug.com/718516: Process policy is not | 395 // TODO(lukasza): https://crbug.com/718516: Process policy is not |
395 // well-defined / settled wrt relationship between 1) hosted apps and 2) | 396 // well-defined / settled wrt relationship between 1) hosted apps and 2) |
396 // same-site web content outside of hosted app's extent. When this test was | 397 // same-site web content outside of hosted app's extent. When this test was |
397 // authored --site-per-process would put |app| in a separate renderer | 398 // authored --site-per-process would put |app| in a separate renderer |
398 // process from |diff_dir| and |same_site|, even though such process | 399 // process from |diff_dir| and |same_site|, even though such process |
399 // placement can be problematic (if |app| tries to synchronously script | 400 // placement can be problematic (if |app| tries to synchronously script |
400 // |diff_dir| and/or |same_site|). | 401 // |diff_dir| and/or |same_site|). |
401 } | 402 } |
402 } | 403 } |
| 404 |
| 405 class HostedAppWithIsolatedOriginsTest : public HostedAppTest { |
| 406 public: |
| 407 HostedAppWithIsolatedOriginsTest() {} |
| 408 ~HostedAppWithIsolatedOriginsTest() override {} |
| 409 |
| 410 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 411 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| 412 std::string origin_list = |
| 413 embedded_test_server()->GetURL("isolated.foo.com", "/").spec(); |
| 414 command_line->AppendSwitchASCII(switches::kIsolateOrigins, origin_list); |
| 415 } |
| 416 |
| 417 void SetUpOnMainThread() override { |
| 418 HostedAppTest::SetUpOnMainThread(); |
| 419 host_resolver()->AddRule("*", "127.0.0.1"); |
| 420 embedded_test_server()->StartAcceptingConnections(); |
| 421 } |
| 422 |
| 423 private: |
| 424 DISALLOW_COPY_AND_ASSIGN(HostedAppWithIsolatedOriginsTest); |
| 425 }; |
| 426 |
| 427 // Verify that when navigating to an isolated origin which is also part of |
| 428 // a hosted app's web extent, the isolated origin takes precedence for |
| 429 // SiteInstance determination and still ends up in a dedicated process. |
| 430 IN_PROC_BROWSER_TEST_F(HostedAppWithIsolatedOriginsTest, |
| 431 IsolatedOriginTakesPrecedence) { |
| 432 // Launch a hosted app which covers an isolated origin in its web extent. |
| 433 GURL url = embedded_test_server()->GetURL("app.foo.com", "/iframe.html"); |
| 434 extensions::TestExtensionDir test_app_dir; |
| 435 test_app_dir.WriteManifest(base::StringPrintf( |
| 436 R"( { "name": "Hosted App vs IsolatedOrigins Test", |
| 437 "version": "1", |
| 438 "manifest_version": 2, |
| 439 "app": { |
| 440 "launch": { |
| 441 "web_url": "%s" |
| 442 }, |
| 443 "urls": ["*://app.foo.com", "*://isolated.foo.com/"] |
| 444 } |
| 445 } )", |
| 446 url.spec().c_str())); |
| 447 SetupApp(test_app_dir.UnpackedPath(), false); |
| 448 |
| 449 content::WebContents* app_contents = |
| 450 app_browser_->tab_strip_model()->GetActiveWebContents(); |
| 451 content::WaitForLoadStop(app_contents); |
| 452 |
| 453 content::RenderFrameHost* app = app_contents->GetMainFrame(); |
| 454 |
| 455 // A subframe on an app for an isolated origin should be kicked out to its |
| 456 // own process. |
| 457 GURL isolated_url = |
| 458 embedded_test_server()->GetURL("isolated.foo.com", "/title1.html"); |
| 459 EXPECT_TRUE(NavigateIframeToURL(app_contents, "test", isolated_url)); |
| 460 |
| 461 content::RenderFrameHost* app_subframe = content::ChildFrameAt(app, 0); |
| 462 EXPECT_EQ(isolated_url, app_subframe->GetLastCommittedURL()); |
| 463 EXPECT_TRUE(app_subframe->IsCrossProcessSubframe()); |
| 464 EXPECT_NE(app->GetSiteInstance(), app_subframe->GetSiteInstance()); |
| 465 EXPECT_EQ(isolated_url.GetOrigin(), |
| 466 app_subframe->GetSiteInstance()->GetSiteURL()); |
| 467 |
| 468 // Navigating a regular tab to an isolated origin which is also part of an |
| 469 // app's web extent should use the isolated origin's SiteInstance and not the |
| 470 // app's. |
| 471 ui_test_utils::NavigateToURL(browser(), isolated_url); |
| 472 content::WebContents* web_contents = |
| 473 browser()->tab_strip_model()->GetActiveWebContents(); |
| 474 EXPECT_EQ(isolated_url.GetOrigin(), |
| 475 web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL()); |
| 476 EXPECT_NE(web_contents->GetMainFrame()->GetSiteInstance(), |
| 477 app->GetSiteInstance()); |
| 478 } |
OLD | NEW |