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 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "chrome/browser/ui/browser_navigator.h" | 32 #include "chrome/browser/ui/browser_navigator.h" |
33 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | 34 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" |
35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/extensions/extension.h" | 38 #include "chrome/common/extensions/extension.h" |
39 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
40 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
41 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
42 #include "content/browser/renderer_host/render_process_host.h" | 42 #include "content/browser/renderer_host/render_process_host_impl.h" |
43 #include "content/browser/renderer_host/render_view_host.h" | 43 #include "content/browser/renderer_host/render_view_host.h" |
44 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
45 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
47 #include "content/public/common/page_transition_types.h" | 47 #include "content/public/common/page_transition_types.h" |
48 #include "content/public/common/url_constants.h" | 48 #include "content/public/common/url_constants.h" |
49 #include "grit/chromium_strings.h" | 49 #include "grit/chromium_strings.h" |
50 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
51 #include "net/base/mock_host_resolver.h" | 51 #include "net/base/mock_host_resolver.h" |
52 #include "net/test/test_server.h" | 52 #include "net/test/test_server.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 return UTF16ToWideHack( | 92 return UTF16ToWideHack( |
93 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, | 93 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, |
94 WideToUTF16Hack(page_title))); | 94 WideToUTF16Hack(page_title))); |
95 #endif | 95 #endif |
96 } | 96 } |
97 | 97 |
98 // Returns the number of active RenderProcessHosts. | 98 // Returns the number of active RenderProcessHosts. |
99 int CountRenderProcessHosts() { | 99 int CountRenderProcessHosts() { |
100 int result = 0; | 100 int result = 0; |
101 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 101 for (content::RenderProcessHost::iterator i( |
| 102 content::RenderProcessHost::AllHostsIterator()); |
102 !i.IsAtEnd(); i.Advance()) | 103 !i.IsAtEnd(); i.Advance()) |
103 ++result; | 104 ++result; |
104 return result; | 105 return result; |
105 } | 106 } |
106 | 107 |
107 class MockTabStripModelObserver : public TabStripModelObserver { | 108 class MockTabStripModelObserver : public TabStripModelObserver { |
108 public: | 109 public: |
109 MockTabStripModelObserver() : closing_count_(0) {} | 110 MockTabStripModelObserver() : closing_count_(0) {} |
110 | 111 |
111 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 112 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ASSERT_TRUE(test_server()->Start()); | 365 ASSERT_TRUE(test_server()->Start()); |
365 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, | 366 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, |
366 FilePath(kDocRoot)); | 367 FilePath(kDocRoot)); |
367 ASSERT_TRUE(https_test_server.Start()); | 368 ASSERT_TRUE(https_test_server.Start()); |
368 GURL http_url(test_server()->GetURL("files/title1.html")); | 369 GURL http_url(test_server()->GetURL("files/title1.html")); |
369 GURL https_url(https_test_server.GetURL("")); | 370 GURL https_url(https_test_server.GetURL("")); |
370 | 371 |
371 // Start with an http URL. | 372 // Start with an http URL. |
372 ui_test_utils::NavigateToURL(browser(), http_url); | 373 ui_test_utils::NavigateToURL(browser(), http_url); |
373 TabContents* oldtab = browser()->GetSelectedTabContents(); | 374 TabContents* oldtab = browser()->GetSelectedTabContents(); |
374 RenderProcessHost* process = oldtab->render_view_host()->process(); | 375 content::RenderProcessHost* process = oldtab->render_view_host()->process(); |
375 | 376 |
376 // Now open a tab to a blank page, set its opener to null, and redirect it | 377 // Now open a tab to a blank page, set its opener to null, and redirect it |
377 // cross-site. | 378 // cross-site. |
378 std::string redirect_popup = "w=window.open();"; | 379 std::string redirect_popup = "w=window.open();"; |
379 redirect_popup += "w.opener=null;"; | 380 redirect_popup += "w.opener=null;"; |
380 redirect_popup += "w.document.location=\""; | 381 redirect_popup += "w.document.location=\""; |
381 redirect_popup += https_url.spec(); | 382 redirect_popup += https_url.spec(); |
382 redirect_popup += "\";"; | 383 redirect_popup += "\";"; |
383 | 384 |
384 ui_test_utils::WindowedNotificationObserver popup_observer( | 385 ui_test_utils::WindowedNotificationObserver popup_observer( |
(...skipping 10 matching lines...) Expand all Loading... |
395 ASSERT_EQ(2, browser()->tab_count()); | 396 ASSERT_EQ(2, browser()->tab_count()); |
396 TabContents* newtab = browser()->GetSelectedTabContents(); | 397 TabContents* newtab = browser()->GetSelectedTabContents(); |
397 EXPECT_TRUE(newtab); | 398 EXPECT_TRUE(newtab); |
398 EXPECT_NE(oldtab, newtab); | 399 EXPECT_NE(oldtab, newtab); |
399 nav_observer.Wait(); | 400 nav_observer.Wait(); |
400 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry()); | 401 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry()); |
401 EXPECT_EQ(https_url.spec(), | 402 EXPECT_EQ(https_url.spec(), |
402 newtab->controller().GetLastCommittedEntry()->url().spec()); | 403 newtab->controller().GetLastCommittedEntry()->url().spec()); |
403 | 404 |
404 // Popup window should not be in the opener's process. | 405 // Popup window should not be in the opener's process. |
405 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | 406 content::RenderProcessHost* popup_process = |
| 407 newtab->render_view_host()->process(); |
406 EXPECT_NE(process, popup_process); | 408 EXPECT_NE(process, popup_process); |
407 | 409 |
408 // Now open a tab to a blank page, set its opener to null, and use a | 410 // Now open a tab to a blank page, set its opener to null, and use a |
409 // meta-refresh to navigate it instead. | 411 // meta-refresh to navigate it instead. |
410 std::string refresh_popup = "w=window.open();"; | 412 std::string refresh_popup = "w=window.open();"; |
411 refresh_popup += "w.opener=null;"; | 413 refresh_popup += "w.opener=null;"; |
412 refresh_popup += "w.document.write("; | 414 refresh_popup += "w.document.write("; |
413 refresh_popup += "'<META HTTP-EQUIV=\"refresh\" content=\"0; url="; | 415 refresh_popup += "'<META HTTP-EQUIV=\"refresh\" content=\"0; url="; |
414 refresh_popup += https_url.spec(); | 416 refresh_popup += https_url.spec(); |
415 refresh_popup += "\">');w.document.close();"; | 417 refresh_popup += "\">');w.document.close();"; |
(...skipping 12 matching lines...) Expand all Loading... |
428 ASSERT_EQ(3, browser()->tab_count()); | 430 ASSERT_EQ(3, browser()->tab_count()); |
429 TabContents* newtab2 = browser()->GetSelectedTabContents(); | 431 TabContents* newtab2 = browser()->GetSelectedTabContents(); |
430 EXPECT_TRUE(newtab2); | 432 EXPECT_TRUE(newtab2); |
431 EXPECT_NE(oldtab, newtab2); | 433 EXPECT_NE(oldtab, newtab2); |
432 nav_observer2.Wait(); | 434 nav_observer2.Wait(); |
433 ASSERT_TRUE(newtab2->controller().GetLastCommittedEntry()); | 435 ASSERT_TRUE(newtab2->controller().GetLastCommittedEntry()); |
434 EXPECT_EQ(https_url.spec(), | 436 EXPECT_EQ(https_url.spec(), |
435 newtab2->controller().GetLastCommittedEntry()->url().spec()); | 437 newtab2->controller().GetLastCommittedEntry()->url().spec()); |
436 | 438 |
437 // This popup window should also not be in the opener's process. | 439 // This popup window should also not be in the opener's process. |
438 RenderProcessHost* popup_process2 = newtab2->render_view_host()->process(); | 440 content::RenderProcessHost* popup_process2 = |
| 441 newtab2->render_view_host()->process(); |
439 EXPECT_NE(process, popup_process2); | 442 EXPECT_NE(process, popup_process2); |
440 } | 443 } |
441 | 444 |
442 // Tests that other popup navigations that do not follow the steps at | 445 // Tests that other popup navigations that do not follow the steps at |
443 // http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab will not | 446 // http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab will not |
444 // fork a new renderer process. | 447 // fork a new renderer process. |
445 IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { | 448 IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { |
446 CommandLine::ForCurrentProcess()->AppendSwitch( | 449 CommandLine::ForCurrentProcess()->AppendSwitch( |
447 switches::kDisablePopupBlocking); | 450 switches::kDisablePopupBlocking); |
448 | 451 |
449 // Create http and https servers for a cross-site transition. | 452 // Create http and https servers for a cross-site transition. |
450 ASSERT_TRUE(test_server()->Start()); | 453 ASSERT_TRUE(test_server()->Start()); |
451 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, | 454 net::TestServer https_test_server(net::TestServer::TYPE_HTTPS, |
452 FilePath(kDocRoot)); | 455 FilePath(kDocRoot)); |
453 ASSERT_TRUE(https_test_server.Start()); | 456 ASSERT_TRUE(https_test_server.Start()); |
454 GURL http_url(test_server()->GetURL("files/title1.html")); | 457 GURL http_url(test_server()->GetURL("files/title1.html")); |
455 GURL https_url(https_test_server.GetURL("")); | 458 GURL https_url(https_test_server.GetURL("")); |
456 | 459 |
457 // Start with an http URL. | 460 // Start with an http URL. |
458 ui_test_utils::NavigateToURL(browser(), http_url); | 461 ui_test_utils::NavigateToURL(browser(), http_url); |
459 TabContents* oldtab = browser()->GetSelectedTabContents(); | 462 TabContents* oldtab = browser()->GetSelectedTabContents(); |
460 RenderProcessHost* process = oldtab->render_view_host()->process(); | 463 content::RenderProcessHost* process = oldtab->render_view_host()->process(); |
461 | 464 |
462 // Now open a tab to a blank page, set its opener to null, and redirect it | 465 // Now open a tab to a blank page, set its opener to null, and redirect it |
463 // cross-site. | 466 // cross-site. |
464 std::string dont_fork_popup = "w=window.open();"; | 467 std::string dont_fork_popup = "w=window.open();"; |
465 dont_fork_popup += "w.document.location=\""; | 468 dont_fork_popup += "w.document.location=\""; |
466 dont_fork_popup += https_url.spec(); | 469 dont_fork_popup += https_url.spec(); |
467 dont_fork_popup += "\";"; | 470 dont_fork_popup += "\";"; |
468 | 471 |
469 ui_test_utils::WindowedNotificationObserver popup_observer( | 472 ui_test_utils::WindowedNotificationObserver popup_observer( |
470 content::NOTIFICATION_TAB_ADDED, | 473 content::NOTIFICATION_TAB_ADDED, |
471 content::NotificationService::AllSources()); | 474 content::NotificationService::AllSources()); |
472 ui_test_utils::WindowedNotificationObserver nav_observer( | 475 ui_test_utils::WindowedNotificationObserver nav_observer( |
473 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 476 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
474 content::NotificationService::AllSources()); | 477 content::NotificationService::AllSources()); |
475 oldtab->render_view_host()-> | 478 oldtab->render_view_host()-> |
476 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(dont_fork_popup)); | 479 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(dont_fork_popup)); |
477 | 480 |
478 // Wait for popup window to appear and finish navigating. | 481 // Wait for popup window to appear and finish navigating. |
479 popup_observer.Wait(); | 482 popup_observer.Wait(); |
480 ASSERT_EQ(2, browser()->tab_count()); | 483 ASSERT_EQ(2, browser()->tab_count()); |
481 TabContents* newtab = browser()->GetSelectedTabContents(); | 484 TabContents* newtab = browser()->GetSelectedTabContents(); |
482 EXPECT_TRUE(newtab); | 485 EXPECT_TRUE(newtab); |
483 EXPECT_NE(oldtab, newtab); | 486 EXPECT_NE(oldtab, newtab); |
484 nav_observer.Wait(); | 487 nav_observer.Wait(); |
485 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry()); | 488 ASSERT_TRUE(newtab->controller().GetLastCommittedEntry()); |
486 EXPECT_EQ(https_url.spec(), | 489 EXPECT_EQ(https_url.spec(), |
487 newtab->controller().GetLastCommittedEntry()->url().spec()); | 490 newtab->controller().GetLastCommittedEntry()->url().spec()); |
488 | 491 |
489 // Popup window should still be in the opener's process. | 492 // Popup window should still be in the opener's process. |
490 RenderProcessHost* popup_process = newtab->render_view_host()->process(); | 493 content::RenderProcessHost* popup_process = |
| 494 newtab->render_view_host()->process(); |
491 EXPECT_EQ(process, popup_process); | 495 EXPECT_EQ(process, popup_process); |
492 | 496 |
493 // Same thing if the current tab tries to navigate itself. | 497 // Same thing if the current tab tries to navigate itself. |
494 std::string navigate_str = "document.location=\""; | 498 std::string navigate_str = "document.location=\""; |
495 navigate_str += https_url.spec(); | 499 navigate_str += https_url.spec(); |
496 navigate_str += "\";"; | 500 navigate_str += "\";"; |
497 | 501 |
498 ui_test_utils::WindowedNotificationObserver nav_observer2( | 502 ui_test_utils::WindowedNotificationObserver nav_observer2( |
499 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 503 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
500 content::NotificationService::AllSources()); | 504 content::NotificationService::AllSources()); |
501 oldtab->render_view_host()-> | 505 oldtab->render_view_host()-> |
502 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(navigate_str)); | 506 ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(navigate_str)); |
503 nav_observer2.Wait(); | 507 nav_observer2.Wait(); |
504 ASSERT_TRUE(oldtab->controller().GetLastCommittedEntry()); | 508 ASSERT_TRUE(oldtab->controller().GetLastCommittedEntry()); |
505 EXPECT_EQ(https_url.spec(), | 509 EXPECT_EQ(https_url.spec(), |
506 oldtab->controller().GetLastCommittedEntry()->url().spec()); | 510 oldtab->controller().GetLastCommittedEntry()->url().spec()); |
507 | 511 |
508 // Original window should still be in the original process. | 512 // Original window should still be in the original process. |
509 RenderProcessHost* new_process = newtab->render_view_host()->process(); | 513 content::RenderProcessHost* new_process = |
| 514 newtab->render_view_host()->process(); |
510 EXPECT_EQ(process, new_process); | 515 EXPECT_EQ(process, new_process); |
511 } | 516 } |
512 | 517 |
513 // Test that get_process_idle_time() returns reasonable values when compared | 518 // Test that get_process_idle_time() returns reasonable values when compared |
514 // with time deltas measured locally. | 519 // with time deltas measured locally. |
515 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { | 520 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { |
516 base::TimeTicks start = base::TimeTicks::Now(); | 521 base::TimeTicks start = base::TimeTicks::Now(); |
517 ui_test_utils::NavigateToURL(browser(), | 522 ui_test_utils::NavigateToURL(browser(), |
518 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 523 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
519 FilePath(kTitle1File))); | 524 FilePath(kTitle1File))); |
520 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 525 content::RenderProcessHost::iterator it( |
| 526 content::RenderProcessHost::AllHostsIterator()); |
521 for (; !it.IsAtEnd(); it.Advance()) { | 527 for (; !it.IsAtEnd(); it.Advance()) { |
522 base::TimeDelta renderer_td = | 528 base::TimeDelta renderer_td = |
523 it.GetCurrentValue()->get_child_process_idle_time(); | 529 it.GetCurrentValue()->GetChildProcessIdleTime(); |
524 base::TimeDelta browser_td = base::TimeTicks::Now() - start; | 530 base::TimeDelta browser_td = base::TimeTicks::Now() - start; |
525 EXPECT_TRUE(browser_td >= renderer_td); | 531 EXPECT_TRUE(browser_td >= renderer_td); |
526 } | 532 } |
527 } | 533 } |
528 | 534 |
529 // Test IDC_CREATE_SHORTCUTS command is enabled for url scheme file, ftp, http | 535 // Test IDC_CREATE_SHORTCUTS command is enabled for url scheme file, ftp, http |
530 // and https and disabled for chrome://, about:// etc. | 536 // and https and disabled for chrome://, about:// etc. |
531 // TODO(pinkerton): Disable app-mode in the model until we implement it | 537 // TODO(pinkerton): Disable app-mode in the model until we implement it |
532 // on the Mac. http://crbug.com/13148 | 538 // on the Mac. http://crbug.com/13148 |
533 #if !defined(OS_MACOSX) | 539 #if !defined(OS_MACOSX) |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 | 1355 |
1350 // The normal browser should now have four. | 1356 // The normal browser should now have four. |
1351 EXPECT_EQ(4, browser()->tab_count()); | 1357 EXPECT_EQ(4, browser()->tab_count()); |
1352 | 1358 |
1353 // Close the additional browsers. | 1359 // Close the additional browsers. |
1354 popup_browser->CloseAllTabs(); | 1360 popup_browser->CloseAllTabs(); |
1355 app_browser->CloseAllTabs(); | 1361 app_browser->CloseAllTabs(); |
1356 app_popup_browser->CloseAllTabs(); | 1362 app_popup_browser->CloseAllTabs(); |
1357 } | 1363 } |
1358 #endif | 1364 #endif |
OLD | NEW |