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 oldtab->render_view_host()-> | |
| 372 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(redirect_popup)); | |
| 373 | |
| 374 // Wait for popup window to appear and finish navigating. | |
| 375 if (browser()->tab_count() < 2) | |
| 376 ui_test_utils::WaitForNewTab(browser()); | |
|
Paweł Hajdan Jr.
2011/08/25 18:34:56
This is suspicious. Could you use a windowed obser
Charlie Reis
2011/08/25 18:44:45
Sure. I haven't seen windowed observers before--
Charlie Reis
2011/08/25 22:07:31
Done.
Charlie Reis
2011/08/25 22:18:48
Got a merge conflict in ui_test_utils.h. Looks li
| |
| 377 ASSERT_EQ(2, browser()->tab_count()); | |
| 378 TabContents* newtab = browser()->GetSelectedTabContents(); | |
| 379 EXPECT_TRUE(newtab); | |
| 380 EXPECT_NE(oldtab, newtab); | |
| 381 if (!newtab->controller().GetLastCommittedEntry() || | |
| 382 newtab->controller().GetLastCommittedEntry()->url() != https_url) | |
| 383 ui_test_utils::WaitForNavigation(&newtab->controller()); | |
|
Paweł Hajdan Jr.
2011/08/25 18:34:56
Don't use it. It's inherently flaky. Windowed obse
Charlie Reis
2011/08/25 22:07:31
Done.
| |
| 384 | |
| 385 // Popup window should not be in the opener's process. | |
| 386 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | |
| 387 EXPECT_NE(process, popup_process); | |
| 388 | |
| 389 // Now open a tab to a blank page, set its opener to null, and use a | |
| 390 // meta-refresh to navigate it instead. | |
| 391 std::string refresh_popup = "w=window.open();"; | |
| 392 refresh_popup += "w.opener=null;"; | |
| 393 refresh_popup += "w.document.write("; | |
| 394 refresh_popup += "'<META HTTP-EQUIV=\"refresh\" content=\"0; url="; | |
| 395 refresh_popup += https_url.spec(); | |
| 396 refresh_popup += "\">');w.document.close();"; | |
| 397 oldtab->render_view_host()-> | |
| 398 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(refresh_popup)); | |
| 399 | |
| 400 // Wait for popup window to appear and finish navigating. | |
| 401 if (browser()->tab_count() < 3) | |
| 402 ui_test_utils::WaitForNewTab(browser()); | |
| 403 ASSERT_EQ(3, browser()->tab_count()); | |
| 404 TabContents* newtab2 = browser()->GetSelectedTabContents(); | |
| 405 EXPECT_TRUE(newtab2); | |
| 406 EXPECT_NE(oldtab, newtab2); | |
| 407 if (!newtab2->controller().GetLastCommittedEntry() || | |
| 408 newtab2->controller().GetLastCommittedEntry()->url() != https_url) | |
| 409 ui_test_utils::WaitForNavigation(&newtab2->controller()); | |
| 410 | |
| 411 // This popup window should also not be in the opener's process. | |
| 412 RenderProcessHost* popup_process2 = newtab2->render_view_host()->process(); | |
| 413 EXPECT_NE(process, popup_process2); | |
| 414 } | |
| 415 | |
| 416 // Tests that other popup navigations that do not follow the steps at | |
| 417 // http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab will not | |
| 418 // fork a new renderer process. | |
| 419 IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { | |
| 420 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 421 switches::kDisablePopupBlocking); | |
| 422 | |
| 423 // Create http and https servers for a cross-site transition. | |
| 424 ASSERT_TRUE(test_server()->Start()); | |
| 425 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, | |
| 426 FilePath(kDocRoot)); | |
| 427 ASSERT_TRUE(https_test_server.Start()); | |
| 428 GURL http_url(test_server()->GetURL("files/title1.html")); | |
| 429 GURL https_url(https_test_server.GetURL("")); | |
| 430 | |
| 431 // Start with an http URL. | |
| 432 ui_test_utils::NavigateToURL(browser(), http_url); | |
| 433 TabContents* oldtab = browser()->GetSelectedTabContents(); | |
| 434 RenderProcessHost* process = oldtab->render_view_host()->process(); | |
| 435 | |
| 436 // Now open a tab to a blank page, set its opener to null, and redirect it | |
| 437 // cross-site. | |
| 438 std::string dont_fork_popup = "w=window.open();"; | |
| 439 dont_fork_popup += "w.document.location=\""; | |
| 440 dont_fork_popup += https_url.spec(); | |
| 441 dont_fork_popup += "\";"; | |
| 442 oldtab->render_view_host()-> | |
| 443 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(dont_fork_popup)); | |
| 444 | |
| 445 // Wait for popup window to appear and finish navigating. | |
| 446 if (browser()->tab_count() < 2) | |
| 447 ui_test_utils::WaitForNewTab(browser()); | |
| 448 ASSERT_EQ(2, browser()->tab_count()); | |
| 449 TabContents* newtab = browser()->GetSelectedTabContents(); | |
| 450 EXPECT_TRUE(newtab); | |
| 451 EXPECT_NE(oldtab, newtab); | |
| 452 if (!newtab->controller().GetLastCommittedEntry() || | |
| 453 newtab->controller().GetLastCommittedEntry()->url() != https_url) | |
| 454 ui_test_utils::WaitForNavigation(&newtab->controller()); | |
| 455 | |
| 456 // Popup window should still be in the opener's process. | |
| 457 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | |
| 458 EXPECT_EQ(process, popup_process); | |
| 459 | |
| 460 // Same thing if the current tab tries to navigate itself. | |
| 461 std::string navigate_str = "document.location=\""; | |
| 462 navigate_str += https_url.spec(); | |
| 463 navigate_str += "\";"; | |
| 464 oldtab->render_view_host()-> | |
| 465 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(navigate_str)); | |
| 466 if (!oldtab->controller().GetLastCommittedEntry() || | |
| 467 oldtab->controller().GetLastCommittedEntry()->url() != https_url) | |
| 468 ui_test_utils::WaitForNavigation(&oldtab->controller()); | |
| 469 | |
| 470 // Original window should still be in the original process. | |
| 471 RenderProcessHost* new_process = newtab->render_view_host()->process(); | |
| 472 EXPECT_EQ(process, new_process); | |
| 473 } | |
| 474 | |
| 342 // Test that get_process_idle_time() returns reasonable values when compared | 475 // Test that get_process_idle_time() returns reasonable values when compared |
| 343 // with time deltas measured locally. | 476 // with time deltas measured locally. |
| 344 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { | 477 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { |
| 345 base::TimeTicks start = base::TimeTicks::Now(); | 478 base::TimeTicks start = base::TimeTicks::Now(); |
| 346 ui_test_utils::NavigateToURL(browser(), | 479 ui_test_utils::NavigateToURL(browser(), |
| 347 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 480 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 348 FilePath(kTitle1File))); | 481 FilePath(kTitle1File))); |
| 349 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 482 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| 350 for (; !it.IsAtEnd(); it.Advance()) { | 483 for (; !it.IsAtEnd(); it.Advance()) { |
| 351 base::TimeDelta renderer_td = | 484 base::TimeDelta renderer_td = |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 | 995 |
| 863 // The normal browser should now have four. | 996 // The normal browser should now have four. |
| 864 EXPECT_EQ(4, browser()->tab_count()); | 997 EXPECT_EQ(4, browser()->tab_count()); |
| 865 | 998 |
| 866 // Close the additional browsers. | 999 // Close the additional browsers. |
| 867 popup_browser->CloseAllTabs(); | 1000 popup_browser->CloseAllTabs(); |
| 868 app_browser->CloseAllTabs(); | 1001 app_browser->CloseAllTabs(); |
| 869 app_popup_browser->CloseAllTabs(); | 1002 app_popup_browser->CloseAllTabs(); |
| 870 } | 1003 } |
| 871 #endif | 1004 #endif |
| OLD | NEW |