| OLD | NEW |
| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
| 9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
| 10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 FaviconTabHelper::FromWebContents(active_tab); | 572 FaviconTabHelper::FromWebContents(active_tab); |
| 573 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); | 573 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 574 | 574 |
| 575 // Favicon should be shown off the NTP. | 575 // Favicon should be shown off the NTP. |
| 576 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 576 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 577 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 577 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 578 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); | 578 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); |
| 579 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); | 579 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 580 } | 580 } |
| 581 | 581 |
| 582 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { | |
| 583 // Prior to setup, Instant has an ntp with a failed "google.com" load in | |
| 584 // it, which is rendered in the dedicated Instant renderer process. | |
| 585 // | |
| 586 // TODO(sreeram): Fix this up when we stop doing crazy things on init. | |
| 587 InstantService* instant_service = | |
| 588 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 589 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 590 #if !defined(OS_MACOSX) | |
| 591 // The failed "google.com" load is deleted, which sometimes leads to the | |
| 592 // process shutting down on Mac. | |
| 593 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | |
| 594 #endif | |
| 595 | |
| 596 // Setup Instant. | |
| 597 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 598 FocusOmniboxAndWaitForInstantNTPSupport(); | |
| 599 | |
| 600 // The registered Instant render process should still exist. | |
| 601 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | |
| 602 // And the Instant ntp should live inside it. | |
| 603 content::WebContents* ntp_contents = instant()->ntp_->contents(); | |
| 604 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 605 ntp_contents->GetRenderProcessHost()->GetID())); | |
| 606 | |
| 607 // Navigating to the NTP should use the Instant render process. | |
| 608 ui_test_utils::NavigateToURLWithDisposition( | |
| 609 browser(), | |
| 610 GURL(chrome::kChromeUINewTabURL), | |
| 611 CURRENT_TAB, | |
| 612 ui_test_utils::BROWSER_TEST_NONE); | |
| 613 content::WebContents* active_tab = | |
| 614 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 615 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 616 active_tab->GetRenderProcessHost()->GetID())); | |
| 617 | |
| 618 // Navigating elsewhere should not use the Instant render process. | |
| 619 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | |
| 620 EXPECT_FALSE(instant_service->IsInstantProcess( | |
| 621 active_tab->GetRenderProcessHost()->GetID())); | |
| 622 } | |
| 623 | |
| 624 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) { | 582 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) { |
| 625 content::WindowedNotificationObserver observer( | 583 content::WindowedNotificationObserver observer( |
| 626 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 584 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
| 627 content::NotificationService::AllSources()); | 585 content::NotificationService::AllSources()); |
| 628 // Initialize Instant. | 586 // Initialize Instant. |
| 629 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 587 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 630 FocusOmniboxAndWaitForInstantNTPSupport(); | 588 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 631 | 589 |
| 632 // Get a handle to the NTP and the current state of the JS. | 590 // Get a handle to the NTP and the current state of the JS. |
| 633 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 591 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 EXPECT_FALSE(instant_service->IsInstantProcess( | 902 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 945 contents->GetRenderProcessHost()->GetID())); | 903 contents->GetRenderProcessHost()->GetID())); |
| 946 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); | 904 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); |
| 947 int new_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); | 905 int new_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); |
| 948 int new_render_process_id = contents->GetRenderProcessHost()->GetID(); | 906 int new_render_process_id = contents->GetRenderProcessHost()->GetID(); |
| 949 | 907 |
| 950 EXPECT_TRUE(old_render_process_id != new_render_process_id || | 908 EXPECT_TRUE(old_render_process_id != new_render_process_id || |
| 951 old_render_view_id != new_render_view_id); | 909 old_render_view_id != new_render_view_id); |
| 952 } | 910 } |
| 953 | 911 |
| 954 // Test that renderer initiated navigations to an Instant URL from an | |
| 955 // Instant process end up in an Instant process. | |
| 956 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
| 957 RendererInitiatedNavigationInInstantProcess) { | |
| 958 InstantService* instant_service = | |
| 959 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 960 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 961 | |
| 962 // Setup Instant. | |
| 963 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 964 FocusOmniboxAndWaitForInstantNTPSupport(); | |
| 965 | |
| 966 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 967 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 968 | |
| 969 ui_test_utils::NavigateToURLWithDisposition( | |
| 970 browser(), | |
| 971 instant_url(), | |
| 972 CURRENT_TAB, | |
| 973 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 974 content::WebContents* contents = | |
| 975 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 976 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 977 contents->GetRenderProcessHost()->GetID())); | |
| 978 | |
| 979 std::string instant_url_with_query = instant_url().spec() + "q=3"; | |
| 980 std::string add_link_script = base::StringPrintf( | |
| 981 "var a = document.createElement('a');" | |
| 982 "a.id = 'toClick';" | |
| 983 "a.href = '%s';" | |
| 984 "document.body.appendChild(a);", | |
| 985 instant_url_with_query.c_str()); | |
| 986 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); | |
| 987 | |
| 988 content::WindowedNotificationObserver observer( | |
| 989 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 990 content::NotificationService::AllSources()); | |
| 991 EXPECT_TRUE(content::ExecuteScript( | |
| 992 contents, "document.getElementById('toClick').click();")); | |
| 993 observer.Wait(); | |
| 994 | |
| 995 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 996 contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 997 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 998 contents->GetRenderProcessHost()->GetID())); | |
| 999 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); | |
| 1000 } | |
| 1001 | |
| 1002 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { | 912 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { |
| 1003 // Get a committed Instant tab, which will be in the Instant process and thus | 913 // Get a committed Instant tab, which will be in the Instant process and thus |
| 1004 // support chrome::GetSearchTerms(). | 914 // support chrome::GetSearchTerms(). |
| 1005 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 915 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1006 FocusOmnibox(); | 916 FocusOmnibox(); |
| 1007 | 917 |
| 1008 // Create an observer to wait for the instant tab to support Instant. | 918 // Create an observer to wait for the instant tab to support Instant. |
| 1009 content::WindowedNotificationObserver observer( | 919 content::WindowedNotificationObserver observer( |
| 1010 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 920 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 1011 content::NotificationService::AllSources()); | 921 content::NotificationService::AllSources()); |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 content::WindowedNotificationObserver observer( | 1708 content::WindowedNotificationObserver observer( |
| 1799 content::NOTIFICATION_LOAD_STOP, | 1709 content::NOTIFICATION_LOAD_STOP, |
| 1800 content::Source<content::NavigationController>( | 1710 content::Source<content::NavigationController>( |
| 1801 &ntp_contents->GetController())); | 1711 &ntp_contents->GetController())); |
| 1802 service->SetDefaultSearchProvider(template_url); | 1712 service->SetDefaultSearchProvider(template_url); |
| 1803 observer.Wait(); | 1713 observer.Wait(); |
| 1804 | 1714 |
| 1805 // Make sure the URL remains the same. | 1715 // Make sure the URL remains the same. |
| 1806 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); | 1716 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); |
| 1807 } | 1717 } |
| 1718 |
| 1719 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { |
| 1720 // Prior to setup, Instant has an ntp with a failed "google.com" load in |
| 1721 // it, which is rendered in the dedicated Instant renderer process. |
| 1722 // |
| 1723 // TODO(sreeram): Fix this up when we stop doing crazy things on init. |
| 1724 InstantService* instant_service = |
| 1725 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 1726 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 1727 #if !defined(OS_MACOSX) |
| 1728 // The failed "google.com" load is deleted, which sometimes leads to the |
| 1729 // process shutting down on Mac. |
| 1730 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
| 1731 #endif |
| 1732 |
| 1733 // Setup Instant. |
| 1734 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1735 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 1736 |
| 1737 // The registered Instant render process should still exist. |
| 1738 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
| 1739 // And the Instant ntp should live inside it. |
| 1740 content::WebContents* ntp_contents = |
| 1741 instant_service->ntp_prerenderer()->ntp()->contents(); |
| 1742 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 1743 ntp_contents->GetRenderProcessHost()->GetID())); |
| 1744 |
| 1745 // Navigating to the NTP should use the Instant render process. |
| 1746 ui_test_utils::NavigateToURLWithDisposition( |
| 1747 browser(), |
| 1748 GURL(chrome::kChromeUINewTabURL), |
| 1749 CURRENT_TAB, |
| 1750 ui_test_utils::BROWSER_TEST_NONE); |
| 1751 content::WebContents* active_tab = |
| 1752 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1753 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 1754 active_tab->GetRenderProcessHost()->GetID())); |
| 1755 |
| 1756 // Navigating elsewhere should not use the Instant render process. |
| 1757 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 1758 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 1759 active_tab->GetRenderProcessHost()->GetID())); |
| 1760 } |
| 1761 |
| 1762 // Test that renderer initiated navigations to an Instant URL from an |
| 1763 // Instant process end up in an Instant process. |
| 1764 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 1765 RendererInitiatedNavigationInInstantProcess) { |
| 1766 InstantService* instant_service = |
| 1767 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 1768 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 1769 |
| 1770 // Setup Instant. |
| 1771 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1772 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 1773 |
| 1774 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 1775 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1776 |
| 1777 ui_test_utils::NavigateToURLWithDisposition( |
| 1778 browser(), |
| 1779 instant_url(), |
| 1780 CURRENT_TAB, |
| 1781 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1782 content::WebContents* contents = |
| 1783 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1784 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 1785 contents->GetRenderProcessHost()->GetID())); |
| 1786 |
| 1787 std::string instant_url_with_query = instant_url().spec() + "q=3"; |
| 1788 std::string add_link_script = base::StringPrintf( |
| 1789 "var a = document.createElement('a');" |
| 1790 "a.id = 'toClick';" |
| 1791 "a.href = '%s';" |
| 1792 "document.body.appendChild(a);", |
| 1793 instant_url_with_query.c_str()); |
| 1794 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); |
| 1795 |
| 1796 content::WindowedNotificationObserver observer( |
| 1797 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1798 content::NotificationService::AllSources()); |
| 1799 EXPECT_TRUE(content::ExecuteScript( |
| 1800 contents, "document.getElementById('toClick').click();")); |
| 1801 observer.Wait(); |
| 1802 |
| 1803 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1804 contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1805 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 1806 contents->GetRenderProcessHost()->GetID())); |
| 1807 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); |
| 1808 } |
| OLD | NEW |