| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "chrome/browser/search/search.h" | 6 #include "chrome/browser/search/search.h" |
| 7 #include "chrome/browser/task_manager/task_manager.h" | 7 #include "chrome/browser/task_manager/task_manager.h" |
| 8 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 8 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
| 12 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 12 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 13 #include "chrome/browser/ui/search/instant_ntp.h" | 13 #include "chrome/browser/ui/search/instant_ntp.h" |
| 14 #include "chrome/browser/ui/search/instant_overlay.h" | |
| 15 #include "chrome/browser/ui/search/instant_test_utils.h" | 14 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/omnibox_focus_state.h" | 17 #include "chrome/common/omnibox_focus_state.h" |
| 19 #include "chrome/common/search_types.h" | 18 #include "chrome/common/search_types.h" |
| 20 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/interactive_test_utils.h" | 21 #include "chrome/test/base/interactive_test_utils.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 virtual ~InstantExtendedManualTest() { | 52 virtual ~InstantExtendedManualTest() { |
| 54 scoped_host_resolver_proc_.reset(); | 53 scoped_host_resolver_proc_.reset(); |
| 55 host_resolver_proc_ = NULL; | 54 host_resolver_proc_ = NULL; |
| 56 } | 55 } |
| 57 | 56 |
| 58 virtual void SetUpOnMainThread() OVERRIDE { | 57 virtual void SetUpOnMainThread() OVERRIDE { |
| 59 const testing::TestInfo* const test_info = | 58 const testing::TestInfo* const test_info = |
| 60 testing::UnitTest::GetInstance()->current_test_info(); | 59 testing::UnitTest::GetInstance()->current_test_info(); |
| 61 ASSERT_TRUE(StartsWithASCII(test_info->name(), "MANUAL_", true) || | 60 ASSERT_TRUE(StartsWithASCII(test_info->name(), "MANUAL_", true) || |
| 62 StartsWithASCII(test_info->name(), "DISABLED_", true)); | 61 StartsWithASCII(test_info->name(), "DISABLED_", true)); |
| 63 // Make IsOffline() return false so we don't try to use the local overlay. | 62 // Make IsOffline() return false so we don't try to use the local NTP. |
| 64 disable_network_change_notifier_.reset( | 63 disable_network_change_notifier_.reset( |
| 65 new net::NetworkChangeNotifier::DisableForTest()); | 64 new net::NetworkChangeNotifier::DisableForTest()); |
| 66 } | 65 } |
| 67 | 66 |
| 68 virtual void CleanUpOnMainThread() OVERRIDE { | 67 virtual void CleanUpOnMainThread() OVERRIDE { |
| 69 disable_network_change_notifier_.reset(); | 68 disable_network_change_notifier_.reset(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 protected: | 71 protected: |
| 73 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 72 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 74 chrome::EnableInstantExtendedAPIForTesting(); | 73 chrome::EnableInstantExtendedAPIForTesting(); |
| 75 } | 74 } |
| 76 | 75 |
| 77 content::WebContents* active_tab() { | 76 content::WebContents* active_tab() { |
| 78 return browser()->tab_strip_model()->GetActiveWebContents(); | 77 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 bool PressBackspace() { | |
| 82 return ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK, | |
| 83 false, false, false, false); | |
| 84 } | |
| 85 | |
| 86 bool PressBackspaceAndWaitForSuggestions() { | |
| 87 content::WindowedNotificationObserver observer( | |
| 88 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION, | |
| 89 content::NotificationService::AllSources()); | |
| 90 bool result = PressBackspace(); | |
| 91 observer.Wait(); | |
| 92 return result; | |
| 93 } | |
| 94 | |
| 95 bool PressBackspaceAndWaitForOverlayToShow() { | |
| 96 InstantTestModelObserver observer( | |
| 97 instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS); | |
| 98 return PressBackspace() && observer.WaitForExpectedOverlayState() == | |
| 99 SearchMode::MODE_SEARCH_SUGGESTIONS; | |
| 100 } | |
| 101 | |
| 102 bool PressEnterAndWaitForNavigationWithTitle(content::WebContents* contents, | |
| 103 const string16& title) { | |
| 104 content::TitleWatcher title_watcher(contents, title); | |
| 105 content::WindowedNotificationObserver nav_observer( | |
| 106 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 107 content::NotificationService::AllSources()); | |
| 108 browser()->window()->GetLocationBar()->AcceptInput(); | |
| 109 nav_observer.Wait(); | |
| 110 return title_watcher.WaitAndGetTitle() == title; | |
| 111 } | |
| 112 | |
| 113 GURL GetActiveTabURL() { | |
| 114 return active_tab()->GetController().GetActiveEntry()->GetURL(); | |
| 115 } | |
| 116 | |
| 117 bool GetSelectionState(bool* selected) { | |
| 118 return GetBoolFromJS(instant()->GetOverlayContents(), | |
| 119 "google.ac.gs().api.i()", selected); | |
| 120 } | |
| 121 | |
| 122 bool IsGooglePage(content::WebContents* contents) { | 80 bool IsGooglePage(content::WebContents* contents) { |
| 123 bool is_google = false; | 81 bool is_google = false; |
| 124 if (!GetBoolFromJS(contents, "!!window.google", &is_google)) | 82 if (!GetBoolFromJS(contents, "!!window.google", &is_google)) |
| 125 return false; | 83 return false; |
| 126 return is_google; | 84 return is_google; |
| 127 } | 85 } |
| 128 | 86 |
| 129 private: | 87 private: |
| 130 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; | 88 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; |
| 131 scoped_ptr<net::ScopedDefaultHostResolverProc> scoped_host_resolver_proc_; | 89 scoped_ptr<net::ScopedDefaultHostResolverProc> scoped_host_resolver_proc_; |
| 132 scoped_ptr<net::NetworkChangeNotifier::DisableForTest> | 90 scoped_ptr<net::NetworkChangeNotifier::DisableForTest> |
| 133 disable_network_change_notifier_; | 91 disable_network_change_notifier_; |
| 134 }; | 92 }; |
| 135 | 93 |
| 136 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_ShowsGoogleNTP) { | 94 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_ShowsGoogleNTP) { |
| 137 set_browser(browser()); | 95 set_browser(browser()); |
| 138 instant()->SetInstantEnabled(false, true); | 96 instant()->ReloadStaleNTP(); |
| 139 instant()->SetInstantEnabled(true, false); | |
| 140 FocusOmniboxAndWaitForInstantNTPSupport(); | 97 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 141 | 98 |
| 142 content::WindowedNotificationObserver observer( | 99 content::WindowedNotificationObserver observer( |
| 143 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 100 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 144 content::NotificationService::AllSources()); | 101 content::NotificationService::AllSources()); |
| 145 ui_test_utils::NavigateToURLWithDisposition( | 102 ui_test_utils::NavigateToURLWithDisposition( |
| 146 browser(), | 103 browser(), |
| 147 GURL(chrome::kChromeUINewTabURL), | 104 GURL(chrome::kChromeUINewTabURL), |
| 148 CURRENT_TAB, | 105 CURRENT_TAB, |
| 149 ui_test_utils::BROWSER_TEST_NONE); | 106 ui_test_utils::BROWSER_TEST_NONE); |
| 150 observer.Wait(); | 107 observer.Wait(); |
| 151 content::WebContents* active_tab = | 108 content::WebContents* active_tab = |
| 152 browser()->tab_strip_model()->GetActiveWebContents(); | 109 browser()->tab_strip_model()->GetActiveWebContents(); |
| 153 EXPECT_TRUE(IsGooglePage(active_tab)); | 110 EXPECT_TRUE(IsGooglePage(active_tab)); |
| 154 } | 111 } |
| 155 | 112 |
| 156 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_SearchesFromFakebox) { | 113 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_SearchesFromFakebox) { |
| 157 set_browser(browser()); | 114 set_browser(browser()); |
| 158 instant()->SetInstantEnabled(false, true); | 115 instant()->ReloadStaleNTP(); |
| 159 instant()->SetInstantEnabled(true, false); | |
| 160 FocusOmniboxAndWaitForInstantNTPSupport(); | 116 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 161 | 117 |
| 162 // Open a new tab page. | 118 // Open a new tab page. |
| 163 content::WindowedNotificationObserver observer( | 119 content::WindowedNotificationObserver observer( |
| 164 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 120 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 165 content::NotificationService::AllSources()); | 121 content::NotificationService::AllSources()); |
| 166 ui_test_utils::NavigateToURLWithDisposition( | 122 ui_test_utils::NavigateToURLWithDisposition( |
| 167 browser(), | 123 browser(), |
| 168 GURL(chrome::kChromeUINewTabURL), | 124 GURL(chrome::kChromeUINewTabURL), |
| 169 CURRENT_TAB, | 125 CURRENT_TAB, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 200 // The omnibox should say "test" and have visible focus. | 156 // The omnibox should say "test" and have visible focus. |
| 201 EXPECT_EQ("test", GetOmniboxText()); | 157 EXPECT_EQ("test", GetOmniboxText()); |
| 202 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); | 158 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); |
| 203 | 159 |
| 204 // Pressing enter should search for [test]. | 160 // Pressing enter should search for [test]. |
| 205 const string16& search_title = ASCIIToUTF16("test - Google Search"); | 161 const string16& search_title = ASCIIToUTF16("test - Google Search"); |
| 206 content::TitleWatcher title_watcher(active_tab, search_title); | 162 content::TitleWatcher title_watcher(active_tab, search_title); |
| 207 PressEnterAndWaitForNavigation(); | 163 PressEnterAndWaitForNavigation(); |
| 208 EXPECT_EQ(search_title, title_watcher.WaitAndGetTitle()); | 164 EXPECT_EQ(search_title, title_watcher.WaitAndGetTitle()); |
| 209 } | 165 } |
| OLD | NEW |