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

Side by Side Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ui and unit tests Created 7 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
OLDNEW
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"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/autocomplete/autocomplete_controller.h" 18 #include "chrome/browser/autocomplete/autocomplete_controller.h"
19 #include "chrome/browser/autocomplete/autocomplete_match.h" 19 #include "chrome/browser/autocomplete/autocomplete_match.h"
20 #include "chrome/browser/autocomplete/autocomplete_provider.h" 20 #include "chrome/browser/autocomplete/autocomplete_provider.h"
21 #include "chrome/browser/autocomplete/autocomplete_result.h" 21 #include "chrome/browser/autocomplete/autocomplete_result.h"
22 #include "chrome/browser/autocomplete/search_provider.h" 22 #include "chrome/browser/autocomplete/search_provider.h"
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
24 #include "chrome/browser/bookmarks/bookmark_utils.h" 24 #include "chrome/browser/bookmarks/bookmark_utils.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/extensions/extension_browsertest.h" 26 #include "chrome/browser/extensions/extension_browsertest.h"
27 #include "chrome/browser/extensions/extension_service.h" 27 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/favicon/favicon_tab_helper.h" 28 #include "chrome/browser/favicon/favicon_tab_helper.h"
29 #include "chrome/browser/google/google_url_tracker.h"
29 #include "chrome/browser/history/history_db_task.h" 30 #include "chrome/browser/history/history_db_task.h"
30 #include "chrome/browser/history/history_service.h" 31 #include "chrome/browser/history/history_service.h"
31 #include "chrome/browser/history/history_service_factory.h" 32 #include "chrome/browser/history/history_service_factory.h"
32 #include "chrome/browser/history/history_types.h" 33 #include "chrome/browser/history/history_types.h"
33 #include "chrome/browser/history/top_sites.h" 34 #include "chrome/browser/history/top_sites.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/search/instant_service.h" 36 #include "chrome/browser/search/instant_service.h"
36 #include "chrome/browser/search/instant_service_factory.h" 37 #include "chrome/browser/search/instant_service_factory.h"
37 #include "chrome/browser/search/search.h" 38 #include "chrome/browser/search/search.h"
39 #include "chrome/browser/search/search_test_utils.h"
38 #include "chrome/browser/search_engines/template_url_service.h" 40 #include "chrome/browser/search_engines/template_url_service.h"
39 #include "chrome/browser/search_engines/template_url_service_factory.h" 41 #include "chrome/browser/search_engines/template_url_service_factory.h"
40 #include "chrome/browser/task_manager/task_manager.h" 42 #include "chrome/browser/task_manager/task_manager.h"
41 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" 43 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
42 #include "chrome/browser/themes/theme_service.h" 44 #include "chrome/browser/themes/theme_service.h"
43 #include "chrome/browser/themes/theme_service_factory.h" 45 #include "chrome/browser/themes/theme_service_factory.h"
44 #include "chrome/browser/ui/browser_list.h" 46 #include "chrome/browser/ui/browser_list.h"
45 #include "chrome/browser/ui/browser_tabstrip.h" 47 #include "chrome/browser/ui/browser_tabstrip.h"
46 #include "chrome/browser/ui/omnibox/omnibox_view.h" 48 #include "chrome/browser/ui/omnibox/omnibox_view.h"
47 #include "chrome/browser/ui/search/instant_ntp.h" 49 #include "chrome/browser/ui/search/instant_ntp.h"
48 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" 50 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
49 #include "chrome/browser/ui/search/instant_tab.h" 51 #include "chrome/browser/ui/search/instant_tab.h"
50 #include "chrome/browser/ui/search/instant_test_utils.h" 52 #include "chrome/browser/ui/search/instant_test_utils.h"
51 #include "chrome/browser/ui/search/search_tab_helper.h" 53 #include "chrome/browser/ui/search/search_tab_helper.h"
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" 54 #include "chrome/browser/ui/tabs/tab_strip_model.h"
53 #include "chrome/browser/ui/webui/theme_source.h" 55 #include "chrome/browser/ui/webui/theme_source.h"
54 #include "chrome/common/chrome_switches.h" 56 #include "chrome/common/chrome_switches.h"
55 #include "chrome/common/instant_types.h" 57 #include "chrome/common/instant_types.h"
56 #include "chrome/common/pref_names.h" 58 #include "chrome/common/pref_names.h"
57 #include "chrome/common/thumbnail_score.h" 59 #include "chrome/common/thumbnail_score.h"
58 #include "chrome/common/url_constants.h" 60 #include "chrome/common/url_constants.h"
59 #include "chrome/test/base/in_process_browser_test.h" 61 #include "chrome/test/base/in_process_browser_test.h"
60 #include "chrome/test/base/interactive_test_utils.h" 62 #include "chrome/test/base/interactive_test_utils.h"
61 #include "chrome/test/base/ui_test_utils.h" 63 #include "chrome/test/base/ui_test_utils.h"
62 #include "components/sessions/serialized_navigation_entry.h" 64 #include "components/sessions/serialized_navigation_entry.h"
63 #include "content/public/browser/navigation_controller.h" 65 #include "content/public/browser/navigation_controller.h"
64 #include "content/public/browser/navigation_entry.h" 66 #include "content/public/browser/navigation_entry.h"
67 #include "content/public/browser/notification_details.h"
65 #include "content/public/browser/notification_service.h" 68 #include "content/public/browser/notification_service.h"
69 #include "content/public/browser/notification_source.h"
66 #include "content/public/browser/render_process_host.h" 70 #include "content/public/browser/render_process_host.h"
67 #include "content/public/browser/render_view_host.h" 71 #include "content/public/browser/render_view_host.h"
68 #include "content/public/browser/site_instance.h" 72 #include "content/public/browser/site_instance.h"
69 #include "content/public/browser/url_data_source.h" 73 #include "content/public/browser/url_data_source.h"
70 #include "content/public/browser/web_contents.h" 74 #include "content/public/browser/web_contents.h"
71 #include "content/public/browser/web_contents_view.h" 75 #include "content/public/browser/web_contents_view.h"
72 #include "content/public/common/bindings_policy.h" 76 #include "content/public/common/bindings_policy.h"
73 #include "content/public/test/browser_test_utils.h" 77 #include "content/public/test/browser_test_utils.h"
74 #include "content/public/test/test_utils.h" 78 #include "content/public/test/test_utils.h"
75 #include "grit/generated_resources.h" 79 #include "grit/generated_resources.h"
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 active_tab->GetController().GoBack(); 1539 active_tab->GetController().GoBack();
1536 back_observer.Wait(); 1540 back_observer.Wait();
1537 1541
1538 // Verify that onmostvisitedchange event is dispatched when we navigate from 1542 // Verify that onmostvisitedchange event is dispatched when we navigate from
1539 // SRP to NTP. 1543 // SRP to NTP.
1540 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1544 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
1541 EXPECT_TRUE(UpdateSearchState(active_tab)); 1545 EXPECT_TRUE(UpdateSearchState(active_tab));
1542 EXPECT_EQ(1, on_most_visited_change_calls_); 1546 EXPECT_EQ(1, on_most_visited_change_calls_);
1543 } 1547 }
1544 1548
1545 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { 1549 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
samarth 2013/08/02 21:51:15 This can almost certainly become a unit test. Ther
Anuj 2013/08/09 07:22:00 Done.
1546 InstantService* instant_service = 1550 InstantService* instant_service =
1547 InstantServiceFactory::GetForProfile(browser()->profile()); 1551 InstantServiceFactory::GetForProfile(browser()->profile());
1548 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 1552 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
1549 1553
1550 // Setup Instant. 1554 // Setup Instant.
1551 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1555 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1552 FocusOmniboxAndWaitForInstantNTPSupport(); 1556 FocusOmniboxAndWaitForInstantNTPSupport();
1553 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 1557 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
1554 1558
1555 // Navigating to the NTP should use the Instant render process. 1559 // Navigating to the NTP should use the Instant render process.
1556 content::WindowedNotificationObserver new_tab_observer( 1560 ui_test_utils::NavigateToURLWithDisposition(
1557 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 1561 browser(),
1558 content::NotificationService::AllSources()); 1562 GURL(chrome::kChromeSearchLocalNtpUrl),
1563 CURRENT_TAB,
1564 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1565 content::WebContents* local_ntp_contents =
1566 browser()->tab_strip_model()->GetActiveWebContents();
1567 EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
1568 EXPECT_TRUE(instant_service->IsInstantProcess(
1569 local_ntp_contents->GetRenderProcessHost()->GetID()));
1570 GURL local_ntp_url = local_ntp_contents->GetURL();
1571
1559 ui_test_utils::NavigateToURLWithDisposition( 1572 ui_test_utils::NavigateToURLWithDisposition(
1560 browser(), 1573 browser(),
1561 GURL(chrome::kChromeUINewTabURL), 1574 GURL(chrome::kChromeUINewTabURL),
1562 CURRENT_TAB, 1575 NEW_FOREGROUND_TAB,
1563 ui_test_utils::BROWSER_TEST_NONE); 1576 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1564 new_tab_observer.Wait();
1565
1566 content::WebContents* ntp_contents = 1577 content::WebContents* ntp_contents =
1567 browser()->tab_strip_model()->GetActiveWebContents(); 1578 browser()->tab_strip_model()->GetActiveWebContents();
1568 EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents)); 1579 EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents));
1569 EXPECT_TRUE(instant_service->IsInstantProcess( 1580 EXPECT_TRUE(instant_service->IsInstantProcess(
1570 ntp_contents->GetRenderProcessHost()->GetID())); 1581 ntp_contents->GetRenderProcessHost()->GetID()));
1571 GURL ntp_url = ntp_contents->GetURL(); 1582 GURL ntp_url = ntp_contents->GetURL();
1572 1583
1573 AddBlankTabAndShow(browser()); 1584 AddBlankTabAndShow(browser());
1574 content::WebContents* active_tab = 1585 content::WebContents* active_tab =
1575 browser()->tab_strip_model()->GetActiveWebContents(); 1586 browser()->tab_strip_model()->GetActiveWebContents();
1576 EXPECT_FALSE(chrome::IsInstantNTP(active_tab)); 1587 EXPECT_FALSE(chrome::IsInstantNTP(active_tab));
1577 EXPECT_FALSE(instant_service->IsInstantProcess( 1588 EXPECT_FALSE(instant_service->IsInstantProcess(
1578 active_tab->GetRenderProcessHost()->GetID())); 1589 active_tab->GetRenderProcessHost()->GetID()));
1579 1590
1580 TemplateURLData data; 1591 content::WindowedNotificationObserver ntp_observer(
1581 data.short_name = ASCIIToUTF16("t");
1582 data.SetURL("http://defaultturl/q={searchTerms}");
1583 data.suggestions_url = "http://defaultturl2/q={searchTerms}";
1584 data.instant_url = "http://does/not/exist";
1585 data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}");
1586 data.search_terms_replacement_key = "strk";
1587
1588 TemplateURL* template_url = new TemplateURL(browser()->profile(), data);
1589 TemplateURLService* service =
1590 TemplateURLServiceFactory::GetForProfile(browser()->profile());
1591 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
1592 service->Add(template_url); // Takes ownership of |template_url|.
1593
1594 // Change the default search provider.
1595 content::WindowedNotificationObserver observer(
1596 content::NOTIFICATION_LOAD_STOP, 1592 content::NOTIFICATION_LOAD_STOP,
1597 content::Source<content::NavigationController>( 1593 content::Source<content::NavigationController>(
1598 &ntp_contents->GetController())); 1594 &ntp_contents->GetController()));
1599 service->SetDefaultSearchProvider(template_url); 1595 content::WindowedNotificationObserver local_ntp_observer(
1600 observer.Wait(); 1596 content::NOTIFICATION_LOAD_STOP,
1597 content::Source<content::NavigationController>(
1598 &local_ntp_contents->GetController()));
1599
1600 // Change the default search provider.
1601 search_test_utils::SetDefaultInstantTemplateUrl(browser()->profile(), false);
1602
1603 ntp_observer.Wait();
1604 local_ntp_observer.Wait();
1605
1606 // |local_ntp_contents| should use the Instant render process.
1607 EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
1608 EXPECT_TRUE(instant_service->IsInstantProcess(
1609 local_ntp_contents->GetRenderProcessHost()->GetID()));
1610 // Make sure the URL remains the same.
1611 EXPECT_EQ(local_ntp_url, local_ntp_contents->GetURL());
1601 1612
1602 // |ntp_contents| should not use the Instant render process. 1613 // |ntp_contents| should not use the Instant render process.
1603 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); 1614 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents));
1604 EXPECT_FALSE(instant_service->IsInstantProcess( 1615 EXPECT_FALSE(instant_service->IsInstantProcess(
1605 ntp_contents->GetRenderProcessHost()->GetID())); 1616 ntp_contents->GetRenderProcessHost()->GetID()));
1606 // Make sure the URL remains the same. 1617 // Make sure the URL remains the same.
1607 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); 1618 EXPECT_EQ(ntp_url, ntp_contents->GetURL());
1608 } 1619 }
1609 1620
1610 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 1621 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnGoogleBaseURLChanged) {
1611 ReloadLocalNTPOnSearchProviderChange) { 1622 InstantService* instant_service =
1623 InstantServiceFactory::GetForProfile(browser()->profile());
1624 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
1625
1612 // Setup Instant. 1626 // Setup Instant.
1613 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1627 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1614 FocusOmniboxAndWaitForInstantNTPSupport(); 1628 FocusOmniboxAndWaitForInstantNTPSupport();
1629 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
1615 1630
1616 // Navigate to Local NTP. 1631 // Navigating to the NTP should use the Instant render process.
1617 content::WindowedNotificationObserver new_tab_observer(
1618 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
1619 content::NotificationService::AllSources());
1620 ui_test_utils::NavigateToURLWithDisposition( 1632 ui_test_utils::NavigateToURLWithDisposition(
1621 browser(), 1633 browser(),
1622 GURL(chrome::kChromeSearchLocalNtpUrl), 1634 GURL(chrome::kChromeSearchLocalNtpUrl),
1623 CURRENT_TAB, 1635 CURRENT_TAB,
1624 ui_test_utils::BROWSER_TEST_NONE); 1636 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1625 new_tab_observer.Wait(); 1637 content::WebContents* local_ntp_contents =
1638 browser()->tab_strip_model()->GetActiveWebContents();
1639 EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
1640 EXPECT_TRUE(instant_service->IsInstantProcess(
1641 local_ntp_contents->GetRenderProcessHost()->GetID()));
1642 GURL local_ntp_url = local_ntp_contents->GetURL();
1626 1643
1644 ui_test_utils::NavigateToURLWithDisposition(
1645 browser(),
1646 GURL(chrome::kChromeUINewTabURL),
1647 NEW_FOREGROUND_TAB,
1648 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1627 content::WebContents* ntp_contents = 1649 content::WebContents* ntp_contents =
1628 browser()->tab_strip_model()->GetActiveWebContents(); 1650 browser()->tab_strip_model()->GetActiveWebContents();
1651 EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents));
1652 EXPECT_TRUE(instant_service->IsInstantProcess(
1653 ntp_contents->GetRenderProcessHost()->GetID()));
1629 GURL ntp_url = ntp_contents->GetURL(); 1654 GURL ntp_url = ntp_contents->GetURL();
1630 1655
1631 TemplateURLData data; 1656 AddBlankTabAndShow(browser());
1632 data.short_name = ASCIIToUTF16("t"); 1657 content::WebContents* active_tab =
1633 data.SetURL("http://defaultturl/q={searchTerms}"); 1658 browser()->tab_strip_model()->GetActiveWebContents();
1634 data.suggestions_url = "http://defaultturl2/q={searchTerms}"; 1659 EXPECT_FALSE(chrome::IsInstantNTP(active_tab));
1635 data.instant_url = "http://does/not/exist"; 1660 EXPECT_FALSE(instant_service->IsInstantProcess(
1636 data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}"); 1661 active_tab->GetRenderProcessHost()->GetID()));
1637 data.search_terms_replacement_key = "strk";
1638 1662
1639 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); 1663 content::WindowedNotificationObserver ntp_observer(
1640 TemplateURLService* service =
1641 TemplateURLServiceFactory::GetForProfile(browser()->profile());
1642 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
1643 service->Add(template_url); // Takes ownership of |template_url|.
1644
1645 // Change the default search provider. This will reload the local NTP and the
1646 // page URL will remain the same.
1647 content::WindowedNotificationObserver observer(
1648 content::NOTIFICATION_LOAD_STOP, 1664 content::NOTIFICATION_LOAD_STOP,
1649 content::Source<content::NavigationController>( 1665 content::Source<content::NavigationController>(
1650 &ntp_contents->GetController())); 1666 &ntp_contents->GetController()));
1651 service->SetDefaultSearchProvider(template_url); 1667 content::WindowedNotificationObserver local_ntp_observer(
1652 observer.Wait(); 1668 content::NOTIFICATION_LOAD_STOP,
1669 content::Source<content::NavigationController>(
1670 &local_ntp_contents->GetController()));
1671
1672 // Change the Google Base URL
samarth 2013/08/02 21:51:15 Can you not do this in a unit test? Everything els
Anuj 2013/08/09 07:22:00 Done.
1673 PrefService* profile_prefs = browser()->profile()->GetPrefs();
1674 profile_prefs->SetString(prefs::kLastPromptedGoogleURL,
1675 std::string("https://www.google.com"));
1676 GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"),
1677 GURL("https://www.google.es/"));
1678 content::NotificationService::current()->Notify(
1679 chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
1680 content::Source<Profile>(browser()->profile()->GetOriginalProfile()),
1681 content::Details<GoogleURLTracker::UpdatedDetails>(&details));
1682
1683 // Ensure both local_ntp and ntp tabs reload.
1684 ntp_observer.Wait();
1685 local_ntp_observer.Wait();
1686
1687 // |local_ntp_contents| should use the Instant render process.
1688 EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
1689 EXPECT_TRUE(instant_service->IsInstantProcess(
1690 local_ntp_contents->GetRenderProcessHost()->GetID()));
1691 // Make sure the URL remains the same.
1692 EXPECT_EQ(local_ntp_url, local_ntp_contents->GetURL());
1653 1693
1654 // Make sure the URL remains the same. 1694 // Make sure the URL remains the same.
1655 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); 1695 EXPECT_EQ(ntp_url, ntp_contents->GetURL());
1656 } 1696 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698