Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 EXPECT_EQ(https_url.spec(), | |
|
Paweł Hajdan Jr.
2011/08/25 23:36:30
Do you remember earlier crash you encountered here
| |
| 389 newtab->controller().GetLastCommittedEntry()->url().spec()); | |
| 390 | |
| 391 // Popup window should not be in the opener's process. | |
| 392 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | |
| 393 EXPECT_NE(process, popup_process); | |
| 394 | |
| 395 // Now open a tab to a blank page, set its opener to null, and use a | |
| 396 // meta-refresh to navigate it instead. | |
| 397 std::string refresh_popup = "w=window.open();"; | |
| 398 refresh_popup += "w.opener=null;"; | |
| 399 refresh_popup += "w.document.write("; | |
| 400 refresh_popup += "'<META HTTP-EQUIV=\"refresh\" content=\"0; url="; | |
| 401 refresh_popup += https_url.spec(); | |
| 402 refresh_popup += "\">');w.document.close();"; | |
| 403 | |
| 404 ui_test_utils::WindowedNotificationObserver popup_observer2( | |
| 405 content::NOTIFICATION_TAB_ADDED, | |
| 406 NotificationService::AllSources()); | |
| 407 ui_test_utils::WindowedNotificationObserver nav_observer2( | |
| 408 content::NOTIFICATION_LOAD_STOP, | |
| 409 NotificationService::AllSources()); | |
| 410 oldtab->render_view_host()-> | |
| 411 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(refresh_popup)); | |
| 412 | |
| 413 // Wait for popup window to appear and finish navigating. | |
| 414 popup_observer2.Wait(); | |
| 415 ASSERT_EQ(3, browser()->tab_count()); | |
| 416 TabContents* newtab2 = browser()->GetSelectedTabContents(); | |
| 417 EXPECT_TRUE(newtab2); | |
| 418 EXPECT_NE(oldtab, newtab2); | |
| 419 nav_observer2.Wait(); | |
| 420 EXPECT_EQ(https_url.spec(), | |
| 421 newtab2->controller().GetLastCommittedEntry()->url().spec()); | |
| 422 | |
| 423 // This popup window should also not be in the opener's process. | |
| 424 RenderProcessHost* popup_process2 = newtab2->render_view_host()->process(); | |
| 425 EXPECT_NE(process, popup_process2); | |
| 426 } | |
| 427 | |
| 428 // Tests that other popup navigations that do not follow the steps at | |
| 429 // http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab will not | |
| 430 // fork a new renderer process. | |
| 431 IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { | |
| 432 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 433 switches::kDisablePopupBlocking); | |
| 434 | |
| 435 // Create http and https servers for a cross-site transition. | |
| 436 ASSERT_TRUE(test_server()->Start()); | |
| 437 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, | |
| 438 FilePath(kDocRoot)); | |
| 439 ASSERT_TRUE(https_test_server.Start()); | |
| 440 GURL http_url(test_server()->GetURL("files/title1.html")); | |
| 441 GURL https_url(https_test_server.GetURL("")); | |
| 442 | |
| 443 // Start with an http URL. | |
| 444 ui_test_utils::NavigateToURL(browser(), http_url); | |
| 445 TabContents* oldtab = browser()->GetSelectedTabContents(); | |
| 446 RenderProcessHost* process = oldtab->render_view_host()->process(); | |
| 447 | |
| 448 // Now open a tab to a blank page, set its opener to null, and redirect it | |
| 449 // cross-site. | |
| 450 std::string dont_fork_popup = "w=window.open();"; | |
| 451 dont_fork_popup += "w.document.location=\""; | |
| 452 dont_fork_popup += https_url.spec(); | |
| 453 dont_fork_popup += "\";"; | |
| 454 | |
| 455 ui_test_utils::WindowedNotificationObserver popup_observer( | |
| 456 content::NOTIFICATION_TAB_ADDED, | |
| 457 NotificationService::AllSources()); | |
| 458 ui_test_utils::WindowedNotificationObserver nav_observer( | |
| 459 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 460 NotificationService::AllSources()); | |
| 461 oldtab->render_view_host()-> | |
| 462 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(dont_fork_popup)); | |
| 463 | |
| 464 // Wait for popup window to appear and finish navigating. | |
| 465 popup_observer.Wait(); | |
| 466 ASSERT_EQ(2, browser()->tab_count()); | |
| 467 TabContents* newtab = browser()->GetSelectedTabContents(); | |
| 468 EXPECT_TRUE(newtab); | |
| 469 EXPECT_NE(oldtab, newtab); | |
| 470 nav_observer.Wait(); | |
| 471 EXPECT_EQ(https_url.spec(), | |
| 472 newtab->controller().GetLastCommittedEntry()->url().spec()); | |
| 473 | |
| 474 // Popup window should still be in the opener's process. | |
| 475 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | |
| 476 EXPECT_EQ(process, popup_process); | |
| 477 | |
| 478 // Same thing if the current tab tries to navigate itself. | |
| 479 std::string navigate_str = "document.location=\""; | |
| 480 navigate_str += https_url.spec(); | |
| 481 navigate_str += "\";"; | |
| 482 | |
| 483 ui_test_utils::WindowedNotificationObserver nav_observer2( | |
| 484 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 485 NotificationService::AllSources()); | |
| 486 oldtab->render_view_host()-> | |
| 487 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(navigate_str)); | |
| 488 nav_observer2.Wait(); | |
| 489 EXPECT_EQ(https_url.spec(), | |
| 490 oldtab->controller().GetLastCommittedEntry()->url().spec()); | |
| 491 | |
| 492 // Original window should still be in the original process. | |
| 493 RenderProcessHost* new_process = newtab->render_view_host()->process(); | |
| 494 EXPECT_EQ(process, new_process); | |
| 495 } | |
| 496 | |
| 342 // Test that get_process_idle_time() returns reasonable values when compared | 497 // Test that get_process_idle_time() returns reasonable values when compared |
| 343 // with time deltas measured locally. | 498 // with time deltas measured locally. |
| 344 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { | 499 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { |
| 345 base::TimeTicks start = base::TimeTicks::Now(); | 500 base::TimeTicks start = base::TimeTicks::Now(); |
| 346 ui_test_utils::NavigateToURL(browser(), | 501 ui_test_utils::NavigateToURL(browser(), |
| 347 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 502 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 348 FilePath(kTitle1File))); | 503 FilePath(kTitle1File))); |
| 349 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 504 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| 350 for (; !it.IsAtEnd(); it.Advance()) { | 505 for (; !it.IsAtEnd(); it.Advance()) { |
| 351 base::TimeDelta renderer_td = | 506 base::TimeDelta renderer_td = |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 1047 |
| 893 // The normal browser should now have four. | 1048 // The normal browser should now have four. |
| 894 EXPECT_EQ(4, browser()->tab_count()); | 1049 EXPECT_EQ(4, browser()->tab_count()); |
| 895 | 1050 |
| 896 // Close the additional browsers. | 1051 // Close the additional browsers. |
| 897 popup_browser->CloseAllTabs(); | 1052 popup_browser->CloseAllTabs(); |
| 898 app_browser->CloseAllTabs(); | 1053 app_browser->CloseAllTabs(); |
| 899 app_popup_browser->CloseAllTabs(); | 1054 app_popup_browser->CloseAllTabs(); |
| 900 } | 1055 } |
| 901 #endif | 1056 #endif |
| OLD | NEW |