| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 8 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 { | 243 { |
| 244 // Double-check that main_contents has expected window.name set. | 244 // Double-check that main_contents has expected window.name set. |
| 245 // This is a sanity check of test setup; this is not a product test. | 245 // This is a sanity check of test setup; this is not a product test. |
| 246 std::string name_of_main_contents_window; | 246 std::string name_of_main_contents_window; |
| 247 EXPECT_TRUE(ExecuteScriptAndExtractString( | 247 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 248 main_contents, "window.domAutomationController.send(window.name)", | 248 main_contents, "window.domAutomationController.send(window.name)", |
| 249 &name_of_main_contents_window)); | 249 &name_of_main_contents_window)); |
| 250 EXPECT_EQ("main_contents", name_of_main_contents_window); | 250 EXPECT_EQ("main_contents", name_of_main_contents_window); |
| 251 | 251 |
| 252 // Verify that the new contents doesn't have a window.opener set. | 252 // Verify that the new contents doesn't have a window.opener set. |
| 253 bool window_opener_cast_to_bool; | 253 bool window_opener_cast_to_bool = true; |
| 254 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 254 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 255 new_contents, "window.domAutomationController.send(!!window.opener)", | 255 new_contents, "window.domAutomationController.send(!!window.opener)", |
| 256 &window_opener_cast_to_bool)); | 256 &window_opener_cast_to_bool)); |
| 257 EXPECT_FALSE(window_opener_cast_to_bool); | 257 EXPECT_FALSE(window_opener_cast_to_bool); |
| 258 | 258 |
| 259 // Verify that the new contents cannot find the old contents via | 259 // Verify that the new contents cannot find the old contents via |
| 260 // window.open. (i.e. window.open should open a new window, rather than | 260 // window.open. (i.e. window.open should open a new window, rather than |
| 261 // returning a reference to main_contents / old window). | 261 // returning a reference to main_contents / old window). |
| 262 std::string location_of_opened_window; | 262 std::string location_of_opened_window; |
| 263 EXPECT_TRUE(ExecuteScriptAndExtractString( | 263 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 264 new_contents, | 264 new_contents, |
| 265 "w = window.open('', 'main_contents');" | 265 "w = window.open('', 'main_contents');" |
| 266 "window.domAutomationController.send(w.location.href);", | 266 "window.domAutomationController.send(w.location.href);", |
| 267 &location_of_opened_window)); | 267 &location_of_opened_window)); |
| 268 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); | 268 EXPECT_EQ(url::kAboutBlankURL, location_of_opened_window); |
| 269 } | 269 } |
| 270 | 270 |
| 271 return new_contents; | 271 return new_contents; |
| 272 } | 272 } |
| 273 |
| 274 void TestCtrlClick(const char* id_of_anchor_to_click) { |
| 275 // Navigate to the test page. |
| 276 GURL main_url(embedded_test_server()->GetURL( |
| 277 "/frame_tree/anchor_to_same_site_location.html")); |
| 278 ui_test_utils::NavigateToURL(browser(), main_url); |
| 279 |
| 280 // Verify that there is only 1 active tab (with the right contents |
| 281 // committed). |
| 282 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 283 content::WebContents* main_contents = |
| 284 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 285 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); |
| 286 |
| 287 // Test what happens after ctrl-click. SimulateCtrlClick will verify |
| 288 // that |new_contents1| is in a separate process and browsing instance |
| 289 // from |main_contents|. |
| 290 content::WebContents* new_contents1 = |
| 291 SimulateCtrlClick(main_contents, id_of_anchor_to_click); |
| 292 |
| 293 // Test that each subsequent ctrl-click also gets a new process. |
| 294 content::WebContents* new_contents2 = |
| 295 SimulateCtrlClick(main_contents, id_of_anchor_to_click); |
| 296 EXPECT_NE(new_contents1->GetMainFrame()->GetProcess(), |
| 297 new_contents2->GetMainFrame()->GetProcess()); |
| 298 EXPECT_NE(new_contents1->GetMainFrame()->GetSiteInstance(), |
| 299 new_contents2->GetMainFrame()->GetSiteInstance()); |
| 300 EXPECT_FALSE(new_contents1->GetSiteInstance()->IsRelatedSiteInstance( |
| 301 new_contents2->GetSiteInstance())); |
| 302 } |
| 273 }; | 303 }; |
| 274 | 304 |
| 275 IN_PROC_BROWSER_TEST_F(CtrlClickShouldEndUpInNewProcessTest, NoTarget) { | 305 IN_PROC_BROWSER_TEST_F(CtrlClickShouldEndUpInNewProcessTest, NoTarget) { |
| 276 // Navigate to the test page. | 306 TestCtrlClick("test-anchor-no-target"); |
| 277 GURL main_url(embedded_test_server()->GetURL( | 307 } |
| 278 "/frame_tree/anchor_to_same_site_location.html")); | |
| 279 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 280 const char* kIdOfAnchorToClick = "test-anchor-no-target"; | |
| 281 | 308 |
| 282 // Verify that there is only 1 active tab (with the right contents committed). | 309 IN_PROC_BROWSER_TEST_F(CtrlClickShouldEndUpInNewProcessTest, BlankTarget) { |
| 283 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 310 TestCtrlClick("test-anchor-with-blank-target"); |
| 284 content::WebContents* main_contents = | 311 } |
| 285 browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 286 EXPECT_EQ(main_url, main_contents->GetLastCommittedURL()); | |
| 287 | 312 |
| 288 // Test what happens after ctrl-click. SimulateCtrlClick will verify | 313 IN_PROC_BROWSER_TEST_F(CtrlClickShouldEndUpInNewProcessTest, SubframeTarget) { |
| 289 // that |new_contents1| is in a separate process and browsing instance | 314 TestCtrlClick("test-anchor-with-subframe-target"); |
| 290 // from |main_contents|. | |
| 291 content::WebContents* new_contents1 = | |
| 292 SimulateCtrlClick(main_contents, kIdOfAnchorToClick); | |
| 293 | |
| 294 // Test that each subsequent ctrl-click also gets a new process. | |
| 295 content::WebContents* new_contents2 = | |
| 296 SimulateCtrlClick(main_contents, kIdOfAnchorToClick); | |
| 297 EXPECT_NE(new_contents1->GetMainFrame()->GetProcess(), | |
| 298 new_contents2->GetMainFrame()->GetProcess()); | |
| 299 EXPECT_NE(new_contents1->GetMainFrame()->GetSiteInstance(), | |
| 300 new_contents2->GetMainFrame()->GetSiteInstance()); | |
| 301 EXPECT_FALSE(new_contents1->GetSiteInstance()->IsRelatedSiteInstance( | |
| 302 new_contents2->GetSiteInstance())); | |
| 303 } | 315 } |
| 304 | 316 |
| 305 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { | 317 class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest { |
| 306 public: | 318 public: |
| 307 ChromeNavigationPortMappedBrowserTest() {} | 319 ChromeNavigationPortMappedBrowserTest() {} |
| 308 ~ChromeNavigationPortMappedBrowserTest() override {} | 320 ~ChromeNavigationPortMappedBrowserTest() override {} |
| 309 | 321 |
| 310 void SetUpCommandLine(base::CommandLine* command_line) override { | 322 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 311 ASSERT_TRUE(embedded_test_server()->Start()); | 323 ASSERT_TRUE(embedded_test_server()->Start()); |
| 312 | 324 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // Let the navigation finish. It should commit successfully. | 429 // Let the navigation finish. It should commit successfully. |
| 418 manager.WaitForNavigationFinished(); | 430 manager.WaitForNavigationFinished(); |
| 419 last_committed = web_contents->GetController().GetLastCommittedEntry(); | 431 last_committed = web_contents->GetController().GetLastCommittedEntry(); |
| 420 EXPECT_TRUE(last_committed); | 432 EXPECT_TRUE(last_committed); |
| 421 EXPECT_EQ(kURL2, last_committed->GetURL()); | 433 EXPECT_EQ(kURL2, last_committed->GetURL()); |
| 422 | 434 |
| 423 EXPECT_TRUE(navigation_observer.has_committed()); | 435 EXPECT_TRUE(navigation_observer.has_committed()); |
| 424 EXPECT_FALSE(navigation_observer.was_same_document()); | 436 EXPECT_FALSE(navigation_observer.was_same_document()); |
| 425 EXPECT_FALSE(navigation_observer.was_renderer_initiated()); | 437 EXPECT_FALSE(navigation_observer.was_renderer_initiated()); |
| 426 } | 438 } |
| OLD | NEW |