Chromium Code Reviews| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 } else { | 344 } else { |
| 344 // TODO(lukasza): https://crbug.com/718516: Process policy is not | 345 // TODO(lukasza): https://crbug.com/718516: Process policy is not |
| 345 // well-defined / settled wrt relationship between 1) hosted apps and 2) | 346 // well-defined / settled wrt relationship between 1) hosted apps and 2) |
| 346 // same-site web content outside of hosted app's extent. When this test was | 347 // same-site web content outside of hosted app's extent. When this test was |
| 347 // authored --site-per-process would put |app| in a separate renderer | 348 // authored --site-per-process would put |app| in a separate renderer |
| 348 // process from |diff_dir| and |same_site|, even though such process | 349 // process from |diff_dir| and |same_site|, even though such process |
| 349 // placement can be problematic (if |app| tries to synchronously script | 350 // placement can be problematic (if |app| tries to synchronously script |
| 350 // |diff_dir| and/or |same_site|). | 351 // |diff_dir| and/or |same_site|). |
| 351 } | 352 } |
| 352 } | 353 } |
| 354 | |
| 355 class HostedAppWithIsolatedOriginsTest : public HostedAppTest { | |
| 356 public: | |
| 357 HostedAppWithIsolatedOriginsTest() {} | |
| 358 ~HostedAppWithIsolatedOriginsTest() override {} | |
| 359 | |
| 360 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 361 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); | |
| 362 std::string origin_list = | |
| 363 embedded_test_server()->GetURL("isolated.foo.com", "/").spec(); | |
| 364 command_line->AppendSwitchASCII(switches::kIsolateOrigins, origin_list); | |
| 365 } | |
| 366 | |
| 367 void SetUpOnMainThread() override { | |
| 368 HostedAppTest::SetUpOnMainThread(); | |
| 369 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 370 embedded_test_server()->StartAcceptingConnections(); | |
| 371 } | |
| 372 | |
| 373 private: | |
| 374 DISALLOW_COPY_AND_ASSIGN(HostedAppWithIsolatedOriginsTest); | |
| 375 }; | |
| 376 | |
| 377 // Verify that when navigating to an isolated origin which is also part of | |
| 378 // a hosted app's web extent, the isolated origin takes precedence for | |
| 379 // SiteInstance determination and still ends up in a dedicated process. | |
| 380 IN_PROC_BROWSER_TEST_F(HostedAppWithIsolatedOriginsTest, | |
| 381 IsolatedOriginTakesPrecedence) { | |
| 382 // Launch a hosted app which covers an isolated origin in its web extent. | |
| 383 GURL url = embedded_test_server()->GetURL("app.foo.com", "/iframe.html"); | |
| 384 extensions::TestExtensionDir test_app_dir; | |
| 385 test_app_dir.WriteManifest(base::StringPrintf( | |
| 386 R"( { "name": "Hosted App vs IsolatedOrigins Test", | |
| 387 "version": "1", | |
| 388 "manifest_version": 2, | |
| 389 "app": { | |
| 390 "launch": { | |
| 391 "web_url": "%s" | |
| 392 }, | |
| 393 "urls": ["*://isolated.foo.com/"] | |
|
Charlie Reis
2017/05/19 00:10:18
Do we need to include app.foo.com in here as well?
alexmos
2017/05/24 00:19:56
Done. Reading the docs (https://developer.chrome.
| |
| 394 } | |
| 395 } )", | |
| 396 url.spec().c_str())); | |
| 397 SetupApp(test_app_dir.UnpackedPath(), false); | |
| 398 | |
| 399 content::WebContents* app_contents = | |
| 400 app_browser_->tab_strip_model()->GetActiveWebContents(); | |
| 401 content::WaitForLoadStop(app_contents); | |
| 402 | |
| 403 content::RenderFrameHost* app = app_contents->GetMainFrame(); | |
| 404 | |
| 405 // A subframe on an app for an isolated origin should be kicked out to its | |
| 406 // own process. | |
| 407 GURL isolated_url = | |
| 408 embedded_test_server()->GetURL("isolated.foo.com", "/title1.html"); | |
| 409 EXPECT_TRUE(NavigateIframeToURL(app_contents, "test", isolated_url)); | |
| 410 | |
| 411 content::RenderFrameHost* app_subframe = content::ChildFrameAt(app, 0); | |
| 412 EXPECT_EQ(isolated_url, app_subframe->GetLastCommittedURL()); | |
| 413 EXPECT_TRUE(app_subframe->IsCrossProcessSubframe()); | |
| 414 EXPECT_NE(app->GetSiteInstance(), app_subframe->GetSiteInstance()); | |
| 415 EXPECT_EQ(isolated_url.GetOrigin(), | |
| 416 app_subframe->GetSiteInstance()->GetSiteURL()); | |
| 417 | |
| 418 // Navigating a regular tab to an isolated origin which is also part of an | |
| 419 // app's web extent should use the isolated origin's SiteInstance and not the | |
| 420 // app's. | |
| 421 ui_test_utils::NavigateToURL(browser(), isolated_url); | |
| 422 content::WebContents* web_contents = | |
| 423 browser()->tab_strip_model()->GetActiveWebContents(); | |
|
Charlie Reis
2017/05/19 00:10:18
Oh, weird. I didn't realize at first that app_bro
| |
| 424 EXPECT_EQ(isolated_url.GetOrigin(), | |
| 425 web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL()); | |
| 426 EXPECT_NE(web_contents->GetMainFrame()->GetSiteInstance(), | |
| 427 app->GetSiteInstance()); | |
| 428 } | |
| OLD | NEW |