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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 1443663003: Implement the 'noopener' link relation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browsertest Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 shell()->web_contents(), 225 shell()->web_contents(),
226 "window.domAutomationController.send(clickNoRefTargetBlankLink());", 226 "window.domAutomationController.send(clickNoRefTargetBlankLink());",
227 &success)); 227 &success));
228 EXPECT_TRUE(success); 228 EXPECT_TRUE(success);
229 229
230 // Wait for the window to open. 230 // Wait for the window to open.
231 Shell* new_shell = new_shell_observer.GetShell(); 231 Shell* new_shell = new_shell_observer.GetShell();
232 232
233 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); 233 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
234 234
235 // Check that `window.opener` is not set.
236 success = false;
237 EXPECT_TRUE(ExecuteScriptAndExtractBool(
238 new_shell->web_contents(),
239 "window.domAutomationController.send(window.opener == null);", &success));
240 EXPECT_TRUE(success);
241
235 // Wait for the cross-site transition in the new tab to finish. 242 // Wait for the cross-site transition in the new tab to finish.
236 WaitForLoadStop(new_shell->web_contents()); 243 WaitForLoadStop(new_shell->web_contents());
237 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 244 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
238 new_shell->web_contents()); 245 new_shell->web_contents());
239 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> 246 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()->
240 pending_render_view_host()); 247 pending_render_view_host());
241 248
242 // Should have a new SiteInstance. 249 // Should have a new SiteInstance.
243 scoped_refptr<SiteInstance> noref_blank_site_instance( 250 scoped_refptr<SiteInstance> noref_blank_site_instance(
244 new_shell->web_contents()->GetSiteInstance()); 251 new_shell->web_contents()->GetSiteInstance());
245 EXPECT_NE(orig_site_instance, noref_blank_site_instance); 252 EXPECT_NE(orig_site_instance, noref_blank_site_instance);
246 } 253 }
247 254
255 // Same as above, but for 'noopener'
256 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
257 SwapProcessWithRelNopenerAndTargetBlank) {
258 StartEmbeddedServer();
259
260 NavigateToPageWithLinks(shell());
261
262 // Get the original SiteInstance for later comparison.
263 scoped_refptr<SiteInstance> orig_site_instance(
264 shell()->web_contents()->GetSiteInstance());
265 EXPECT_TRUE(orig_site_instance.get() != NULL);
266
267 // Test clicking a rel=noreferrer + target=blank link.
268 ShellAddedObserver new_shell_observer;
269 bool success = false;
270 EXPECT_TRUE(ExecuteScriptAndExtractBool(
271 shell()->web_contents(),
272 "window.domAutomationController.send(clickNoOpenerTargetBlankLink());",
273 &success));
274 EXPECT_TRUE(success);
275
276 // Wait for the window to open.
277 Shell* new_shell = new_shell_observer.GetShell();
278
279 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
280
281 // Check that `window.opener` is not set.
282 success = false;
283 EXPECT_TRUE(ExecuteScriptAndExtractBool(
284 new_shell->web_contents(),
285 "window.domAutomationController.send(window.opener == null);", &success));
286 EXPECT_TRUE(success);
287
288 // Wait for the cross-site transition in the new tab to finish.
289 WaitForLoadStop(new_shell->web_contents());
290 WebContentsImpl* web_contents =
291 static_cast<WebContentsImpl*>(new_shell->web_contents());
292 EXPECT_FALSE(
293 web_contents->GetRenderManagerForTesting()->pending_render_view_host());
294
295 // Should have a new SiteInstance.
296 scoped_refptr<SiteInstance> noopener_blank_site_instance(
297 new_shell->web_contents()->GetSiteInstance());
298 EXPECT_NE(orig_site_instance, noopener_blank_site_instance);
299 }
300
248 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) 301 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance)
249 // for rel=noreferrer links in new windows, even to same site pages and named 302 // for rel=noreferrer links in new windows, even to same site pages and named
250 // targets. 303 // targets.
251 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, 304 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
252 SwapProcessWithSameSiteRelNoreferrer) { 305 SwapProcessWithSameSiteRelNoreferrer) {
253 StartEmbeddedServer(); 306 StartEmbeddedServer();
254 307
255 // Load a page with links that open in a new window. 308 // Load a page with links that open in a new window.
256 NavigateToPageWithLinks(shell()); 309 NavigateToPageWithLinks(shell());
257 310
(...skipping 10 matching lines...) Expand all
268 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", 321 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());",
269 &success)); 322 &success));
270 EXPECT_TRUE(success); 323 EXPECT_TRUE(success);
271 324
272 // Wait for the window to open. 325 // Wait for the window to open.
273 Shell* new_shell = new_shell_observer.GetShell(); 326 Shell* new_shell = new_shell_observer.GetShell();
274 327
275 // Opens in new window. 328 // Opens in new window.
276 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); 329 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
277 330
331 // Check that `window.opener` is not set.
332 success = false;
333 EXPECT_TRUE(ExecuteScriptAndExtractBool(
334 new_shell->web_contents(),
335 "window.domAutomationController.send(window.opener == null);", &success));
336 EXPECT_TRUE(success);
337
338 // Wait for the cross-site transition in the new tab to finish.
339 WaitForLoadStop(new_shell->web_contents());
340 WebContentsImpl* web_contents =
341 static_cast<WebContentsImpl*>(new_shell->web_contents());
342 EXPECT_FALSE(
343 web_contents->GetRenderManagerForTesting()->pending_render_view_host());
344
345 // Should have a new SiteInstance (in a new BrowsingInstance).
346 scoped_refptr<SiteInstance> noref_blank_site_instance(
347 new_shell->web_contents()->GetSiteInstance());
348 EXPECT_NE(orig_site_instance, noref_blank_site_instance);
349 }
350
351 // Same as above, but for 'noopener'
352 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
353 SwapProcessWithSameSiteRelNoopener) {
354 StartEmbeddedServer();
355
356 // Load a page with links that open in a new window.
357 NavigateToPageWithLinks(shell());
358
359 // Get the original SiteInstance for later comparison.
360 scoped_refptr<SiteInstance> orig_site_instance(
361 shell()->web_contents()->GetSiteInstance());
362 EXPECT_TRUE(orig_site_instance.get() != NULL);
363
364 // Test clicking a same-site rel=noopener + target=foo link.
365 ShellAddedObserver new_shell_observer;
366 bool success = false;
367 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(),
368 "window.domAutomationController.send("
369 "clickSameSiteNoOpenerTargetedLink())"
370 ";",
371 &success));
372 EXPECT_TRUE(success);
373
374 // Wait for the window to open.
375 Shell* new_shell = new_shell_observer.GetShell();
376
377 // Opens in new window.
378 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path());
379
380 // Check that `window.opener` is not set.
381 success = false;
382 EXPECT_TRUE(ExecuteScriptAndExtractBool(
383 new_shell->web_contents(),
384 "window.domAutomationController.send(window.opener == null);", &success));
385 EXPECT_TRUE(success);
386
278 // Wait for the cross-site transition in the new tab to finish. 387 // Wait for the cross-site transition in the new tab to finish.
279 WaitForLoadStop(new_shell->web_contents()); 388 WaitForLoadStop(new_shell->web_contents());
280 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 389 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
281 new_shell->web_contents()); 390 new_shell->web_contents());
282 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> 391 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()->
283 pending_render_view_host()); 392 pending_render_view_host());
284 393
285 // Should have a new SiteInstance (in a new BrowsingInstance). 394 // Should have a new SiteInstance (in a new BrowsingInstance).
286 scoped_refptr<SiteInstance> noref_blank_site_instance( 395 scoped_refptr<SiteInstance> noref_blank_site_instance(
287 new_shell->web_contents()->GetSiteInstance()); 396 new_shell->web_contents()->GetSiteInstance());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 449
341 // Get the original SiteInstance for later comparison. 450 // Get the original SiteInstance for later comparison.
342 scoped_refptr<SiteInstance> orig_site_instance( 451 scoped_refptr<SiteInstance> orig_site_instance(
343 shell()->web_contents()->GetSiteInstance()); 452 shell()->web_contents()->GetSiteInstance());
344 EXPECT_TRUE(orig_site_instance.get() != NULL); 453 EXPECT_TRUE(orig_site_instance.get() != NULL);
345 454
346 // Test clicking a rel=noreferrer link. 455 // Test clicking a rel=noreferrer link.
347 bool success = false; 456 bool success = false;
348 EXPECT_TRUE(ExecuteScriptAndExtractBool( 457 EXPECT_TRUE(ExecuteScriptAndExtractBool(
349 shell()->web_contents(), 458 shell()->web_contents(),
459 "window.domAutomationController.send(clickNoRefLink());", &success));
460 EXPECT_TRUE(success);
461
462 // Wait for the cross-site transition in the current tab to finish.
463 WaitForLoadStop(shell()->web_contents());
464
465 // Opens in same window.
466 EXPECT_EQ(1u, Shell::windows().size());
467 EXPECT_EQ("/title2.html",
468 shell()->web_contents()->GetLastCommittedURL().path());
469
470 // Should have the same SiteInstance unless we're in site-per-process mode.
471 scoped_refptr<SiteInstance> noref_site_instance(
472 shell()->web_contents()->GetSiteInstance());
473 if (AreAllSitesIsolatedForTesting())
474 EXPECT_NE(orig_site_instance, noref_site_instance);
475 else
476 EXPECT_EQ(orig_site_instance, noref_site_instance);
477 }
478
479 // Same as above, but for 'noopener'
480 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
481 DontSwapProcessWithOnlyRelNoOpener) {
482 StartEmbeddedServer();
483
484 // Load a page with links that open in a new window.
485 NavigateToPageWithLinks(shell());
486
487 // Get the original SiteInstance for later comparison.
488 scoped_refptr<SiteInstance> orig_site_instance(
489 shell()->web_contents()->GetSiteInstance());
490 EXPECT_TRUE(orig_site_instance.get() != NULL);
491
492 // Test clicking a rel=noreferrer link.
493 bool success = false;
494 EXPECT_TRUE(ExecuteScriptAndExtractBool(
495 shell()->web_contents(),
350 "window.domAutomationController.send(clickNoRefLink());", 496 "window.domAutomationController.send(clickNoRefLink());",
351 &success)); 497 &success));
352 EXPECT_TRUE(success); 498 EXPECT_TRUE(success);
353 499
354 // Wait for the cross-site transition in the current tab to finish. 500 // Wait for the cross-site transition in the current tab to finish.
355 WaitForLoadStop(shell()->web_contents()); 501 WaitForLoadStop(shell()->web_contents());
356 502
357 // Opens in same window. 503 // Opens in same window.
358 EXPECT_EQ(1u, Shell::windows().size()); 504 EXPECT_EQ(1u, Shell::windows().size());
359 EXPECT_EQ("/title2.html", 505 EXPECT_EQ("/title2.html",
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive()); 2354 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive());
2209 2355
2210 // Navigate the main tab to the site of the popup. This will cause the 2356 // Navigate the main tab to the site of the popup. This will cause the
2211 // RenderView for b.com in the main tab to be recreated. If the issue 2357 // RenderView for b.com in the main tab to be recreated. If the issue
2212 // is not fixed, this will result in process crash and failing test. 2358 // is not fixed, this will result in process crash and failing test.
2213 EXPECT_TRUE(NavigateToURL( 2359 EXPECT_TRUE(NavigateToURL(
2214 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); 2360 shell(), embedded_test_server()->GetURL("b.com", "/title3.html")));
2215 } 2361 }
2216 2362
2217 } // namespace content 2363 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/data/click-noreferrer-links.html » ('j') | third_party/WebKit/Source/core/html/HTMLAnchorElement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698