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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 7740028: Use the request's URL rather than the document's when deciding to swap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add assertions and fix test. Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/tests/browser_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 ASCIIToUTF16("w.close(); alert('bar');")); 332 ASCIIToUTF16("w.close(); alert('bar');"));
333 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 333 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
334 alert->native_dialog()->AcceptAppModalDialog(); 334 alert->native_dialog()->AcceptAppModalDialog();
335 335
336 alert = ui_test_utils::WaitForAppModalDialog(); 336 alert = ui_test_utils::WaitForAppModalDialog();
337 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)-> 337 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->
338 is_before_unload_dialog()); 338 is_before_unload_dialog());
339 alert->native_dialog()->AcceptAppModalDialog(); 339 alert->native_dialog()->AcceptAppModalDialog();
340 } 340 }
341 341
342 // Test that scripts can fork a new renderer process for a cross-site popup,
343 // based on http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab.
344 // The script must open a new tab, set its window.opener to null, and navigate
345 // it to a cross-site URL. It should also work for meta-refreshes.
346 // See http://crbug.com/93517.
347 IN_PROC_BROWSER_TEST_F(BrowserTest, NullOpenerRedirectForksProcess) {
348 CommandLine::ForCurrentProcess()->AppendSwitch(
349 switches::kDisablePopupBlocking);
350
351 // Create http and https servers for a cross-site transition.
352 ASSERT_TRUE(test_server()->Start());
353 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS,
354 FilePath(kDocRoot));
355 ASSERT_TRUE(https_test_server.Start());
356 GURL http_url(test_server()->GetURL("files/title1.html"));
357 GURL https_url(https_test_server.GetURL(""));
358
359 // Start with an http URL.
360 ui_test_utils::NavigateToURL(browser(), http_url);
361 TabContents* oldtab = browser()->GetSelectedTabContents();
362 RenderProcessHost* process = oldtab->render_view_host()->process();
363
364 // Now open a tab to a blank page, set its opener to null, and redirect it
365 // cross-site.
366 std::string redirect_popup = "w=window.open();";
367 redirect_popup += "w.opener=null;";
368 redirect_popup += "w.document.location=\"";
369 redirect_popup += https_url.spec();
370 redirect_popup += "\";";
371
372 ui_test_utils::WindowedNotificationObserver popup_observer(
373 content::NOTIFICATION_TAB_ADDED,
374 NotificationService::AllSources());
375 ui_test_utils::WindowedNotificationObserver nav_observer(
376 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
377 NotificationService::AllSources());
378 oldtab->render_view_host()->
379 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(redirect_popup));
380
381 // Wait for popup window to appear and finish navigating.
382 popup_observer.Wait();
383 ASSERT_EQ(2, browser()->tab_count());
384 TabContents* newtab = browser()->GetSelectedTabContents();
385 EXPECT_TRUE(newtab);
386 EXPECT_NE(oldtab, newtab);
387 nav_observer.Wait();
388 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry());
389 EXPECT_EQ(https_url.spec(),
390 newtab->controller().GetLastCommittedEntry()->url().spec());
391
392 // Popup window should not be in the opener's process.
393 RenderProcessHost* popup_process = newtab->render_view_host()->process();
394 EXPECT_NE(process, popup_process);
395
396 // Now open a tab to a blank page, set its opener to null, and use a
397 // meta-refresh to navigate it instead.
398 std::string refresh_popup = "w=window.open();";
399 refresh_popup += "w.opener=null;";
400 refresh_popup += "w.document.write(";
401 refresh_popup += "'<META HTTP-EQUIV=\"refresh\" content=\"0; url=";
402 refresh_popup += https_url.spec();
403 refresh_popup += "\">');w.document.close();";
404
405 ui_test_utils::WindowedNotificationObserver popup_observer2(
406 content::NOTIFICATION_TAB_ADDED,
407 NotificationService::AllSources());
408 ui_test_utils::WindowedNotificationObserver nav_observer2(
409 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
410 NotificationService::AllSources());
411 oldtab->render_view_host()->
412 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(refresh_popup));
413
414 // Wait for popup window to appear and finish navigating.
415 popup_observer2.Wait();
416 ASSERT_EQ(3, browser()->tab_count());
417 TabContents* newtab2 = browser()->GetSelectedTabContents();
418 EXPECT_TRUE(newtab2);
419 EXPECT_NE(oldtab, newtab2);
420 nav_observer2.Wait();
421 ASSERT_TRUE(newtab2->controller().GetLastCommittedEntry());
422 EXPECT_EQ(https_url.spec(),
423 newtab2->controller().GetLastCommittedEntry()->url().spec());
424
425 // This popup window should also not be in the opener's process.
426 RenderProcessHost* popup_process2 = newtab2->render_view_host()->process();
427 EXPECT_NE(process, popup_process2);
428 }
429
430 // Tests that other popup navigations that do not follow the steps at
431 // http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab will not
432 // fork a new renderer process.
433 IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) {
434 CommandLine::ForCurrentProcess()->AppendSwitch(
435 switches::kDisablePopupBlocking);
436
437 // Create http and https servers for a cross-site transition.
438 ASSERT_TRUE(test_server()->Start());
439 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS,
440 FilePath(kDocRoot));
441 ASSERT_TRUE(https_test_server.Start());
442 GURL http_url(test_server()->GetURL("files/title1.html"));
443 GURL https_url(https_test_server.GetURL(""));
444
445 // Start with an http URL.
446 ui_test_utils::NavigateToURL(browser(), http_url);
447 TabContents* oldtab = browser()->GetSelectedTabContents();
448 RenderProcessHost* process = oldtab->render_view_host()->process();
449
450 // Now open a tab to a blank page, set its opener to null, and redirect it
451 // cross-site.
452 std::string dont_fork_popup = "w=window.open();";
453 dont_fork_popup += "w.document.location=\"";
454 dont_fork_popup += https_url.spec();
455 dont_fork_popup += "\";";
456
457 ui_test_utils::WindowedNotificationObserver popup_observer(
458 content::NOTIFICATION_TAB_ADDED,
459 NotificationService::AllSources());
460 ui_test_utils::WindowedNotificationObserver nav_observer(
461 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
462 NotificationService::AllSources());
463 oldtab->render_view_host()->
464 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(dont_fork_popup));
465
466 // Wait for popup window to appear and finish navigating.
467 popup_observer.Wait();
468 ASSERT_EQ(2, browser()->tab_count());
469 TabContents* newtab = browser()->GetSelectedTabContents();
470 EXPECT_TRUE(newtab);
471 EXPECT_NE(oldtab, newtab);
472 nav_observer.Wait();
473 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry());
474 EXPECT_EQ(https_url.spec(),
475 newtab->controller().GetLastCommittedEntry()->url().spec());
476
477 // Popup window should still be in the opener's process.
478 RenderProcessHost* popup_process = newtab->render_view_host()->process();
479 EXPECT_EQ(process, popup_process);
480
481 // Same thing if the current tab tries to navigate itself.
482 std::string navigate_str = "document.location=\"";
483 navigate_str += https_url.spec();
484 navigate_str += "\";";
485
486 ui_test_utils::WindowedNotificationObserver nav_observer2(
487 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
488 NotificationService::AllSources());
489 oldtab->render_view_host()->
490 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(navigate_str));
491 nav_observer2.Wait();
492 ASSERT_TRUE(oldtab->controller().GetLastCommittedEntry());
493 EXPECT_EQ(https_url.spec(),
494 oldtab->controller().GetLastCommittedEntry()->url().spec());
495
496 // Original window should still be in the original process.
497 RenderProcessHost* new_process = newtab->render_view_host()->process();
498 EXPECT_EQ(process, new_process);
499 }
500
342 // Test that get_process_idle_time() returns reasonable values when compared 501 // Test that get_process_idle_time() returns reasonable values when compared
343 // with time deltas measured locally. 502 // with time deltas measured locally.
344 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { 503 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) {
345 base::TimeTicks start = base::TimeTicks::Now(); 504 base::TimeTicks start = base::TimeTicks::Now();
346 ui_test_utils::NavigateToURL(browser(), 505 ui_test_utils::NavigateToURL(browser(),
347 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 506 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
348 FilePath(kTitle1File))); 507 FilePath(kTitle1File)));
349 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); 508 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
350 for (; !it.IsAtEnd(); it.Advance()) { 509 for (; !it.IsAtEnd(); it.Advance()) {
351 base::TimeDelta renderer_td = 510 base::TimeDelta renderer_td =
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 1051
893 // The normal browser should now have four. 1052 // The normal browser should now have four.
894 EXPECT_EQ(4, browser()->tab_count()); 1053 EXPECT_EQ(4, browser()->tab_count());
895 1054
896 // Close the additional browsers. 1055 // Close the additional browsers.
897 popup_browser->CloseAllTabs(); 1056 popup_browser->CloseAllTabs();
898 app_browser->CloseAllTabs(); 1057 app_browser->CloseAllTabs();
899 app_popup_browser->CloseAllTabs(); 1058 app_popup_browser->CloseAllTabs();
900 } 1059 }
901 #endif 1060 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/tests/browser_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698