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

Side by Side Diff: chrome/browser/chrome_navigation_browsertest.cc

Issue 2680353005: WebContents created via ctrl-click should be in a new process (target=_blank). (Closed)
Patch Set: Rebasing... Created 3 years, 8 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 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 browser()->tab_strip_model()->GetWebContentsAt( 375 browser()->tab_strip_model()->GetWebContentsAt(
364 browser()->tab_strip_model()->count() - 1); 376 browser()->tab_strip_model()->count() - 1);
365 WaitForLoadStop(new_web_contents); 377 WaitForLoadStop(new_web_contents);
366 378
367 // If the test is unsuccessful, the return value from GetLastCommittedURL 379 // If the test is unsuccessful, the return value from GetLastCommittedURL
368 // will be the virtual URL for the created NavigationEntry. 380 // will be the virtual URL for the created NavigationEntry.
369 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme 381 // Note: Before the bug was fixed, the URL was the new_tab_url with a scheme
370 // prepended and one less ":" character after the host. 382 // prepended and one less ":" character after the host.
371 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL()); 383 EXPECT_EQ(GURL(), new_web_contents->GetLastCommittedURL());
372 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698