| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 EXPECT_NE(hosted1_host, extension1_host); | 218 EXPECT_NE(hosted1_host, extension1_host); |
| 219 | 219 |
| 220 // Web pages only share with each other. | 220 // Web pages only share with each other. |
| 221 EXPECT_EQ(web1_host, web2_host); | 221 EXPECT_EQ(web1_host, web2_host); |
| 222 EXPECT_NE(web1_host, extension1_host); | 222 EXPECT_NE(web1_host, extension1_host); |
| 223 | 223 |
| 224 // Extensions only share with each other. | 224 // Extensions only share with each other. |
| 225 EXPECT_EQ(extension1_host, extension2_host); | 225 EXPECT_EQ(extension1_host, extension2_host); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Test that unrelated browsing contexts cannot find each other's windows, |
| 229 // even when they end up using the same renderer process (e.g. because of |
| 230 // hitting a process limit). See also https://crbug.com/718489. |
| 231 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, ProcessReuseVsBrowsingInstance) { |
| 232 // Set max renderers to 1 to force reusing a renderer process between two |
| 233 // unrelated tabs. |
| 234 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
| 235 |
| 236 // Navigate 2 tabs to a web page (regular web pages can share renderers |
| 237 // among themselves without any restrictions, unlike extensions, apps, etc.). |
| 238 ASSERT_TRUE(embedded_test_server()->Start()); |
| 239 GURL url1(embedded_test_server()->GetURL("/title1.html")); |
| 240 GURL url2(embedded_test_server()->GetURL("/title2.html")); |
| 241 ui_test_utils::NavigateToURL(browser(), url1); |
| 242 ui_test_utils::NavigateToURLWithDisposition( |
| 243 browser(), url2, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 244 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 245 content::RenderFrameHost* tab1 = |
| 246 browser()->tab_strip_model()->GetWebContentsAt(0)->GetMainFrame(); |
| 247 content::RenderFrameHost* tab2 = |
| 248 browser()->tab_strip_model()->GetWebContentsAt(1)->GetMainFrame(); |
| 249 |
| 250 // Sanity-check test setup: 2 frames share a renderer process, but are not in |
| 251 // a related browsing instance. |
| 252 EXPECT_EQ(tab1->GetProcess(), tab2->GetProcess()); |
| 253 EXPECT_FALSE( |
| 254 tab1->GetSiteInstance()->IsRelatedSiteInstance(tab2->GetSiteInstance())); |
| 255 |
| 256 // Name the 2 frames. |
| 257 EXPECT_TRUE(content::ExecuteScript(tab1, "window.name = 'tab1';")); |
| 258 EXPECT_TRUE(content::ExecuteScript(tab2, "window.name = 'tab2';")); |
| 259 |
| 260 // Verify that |tab1| cannot find named frames belonging to |tab2| (i.e. that |
| 261 // window.open will end up creating a new tab rather than returning the old |
| 262 // |tab2| tab). |
| 263 content::WebContentsAddedObserver new_contents_observer; |
| 264 std::string location_of_opened_window; |
| 265 EXPECT_TRUE(ExecuteScriptAndExtractString(tab1, |
| 266 R"( var w = window.open('', 'tab2'); |
| 267 window.domAutomationController.send(w.location.href); )", |
| 268 &location_of_opened_window)); |
| 269 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); |
| 270 new_contents_observer.GetWebContents(); |
| 271 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
| 272 } |
| 273 |
| 228 // See | 274 // See |
| 229 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 230 #define MAYBE_ExtensionProcessBalancing DISABLED_ExtensionProcessBalancing | 276 #define MAYBE_ExtensionProcessBalancing DISABLED_ExtensionProcessBalancing |
| 231 #else | 277 #else |
| 232 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing | 278 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing |
| 233 #endif | 279 #endif |
| 234 // Test to verify that the policy of maximum share of extension processes is | 280 // Test to verify that the policy of maximum share of extension processes is |
| 235 // properly enforced. | 281 // properly enforced. |
| 236 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { | 282 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { |
| 237 // Set max renderers to 6 so we can expect 2 extension processes to be | 283 // Set max renderers to 6 so we can expect 2 extension processes to be |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 // the process is the same for all SiteInstances. This allows us to verify | 487 // the process is the same for all SiteInstances. This allows us to verify |
| 442 // that the site-to-process map for the extension hasn't been overwritten by | 488 // that the site-to-process map for the extension hasn't been overwritten by |
| 443 // the process of the |blocked_url|. | 489 // the process of the |blocked_url|. |
| 444 scoped_refptr<content::SiteInstance> new_site_instance = | 490 scoped_refptr<content::SiteInstance> new_site_instance = |
| 445 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), | 491 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), |
| 446 extension->GetResourceURL("")); | 492 extension->GetResourceURL("")); |
| 447 EXPECT_TRUE(new_site_instance->HasProcess()); | 493 EXPECT_TRUE(new_site_instance->HasProcess()); |
| 448 EXPECT_EQ(new_site_instance->GetProcess(), | 494 EXPECT_EQ(new_site_instance->GetProcess(), |
| 449 web_contents->GetSiteInstance()->GetProcess()); | 495 web_contents->GetSiteInstance()->GetProcess()); |
| 450 } | 496 } |
| OLD | NEW |