| 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 "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" |
| 7 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 10 #include "chrome/browser/history/history_types.h" |
| 11 #include "chrome/browser/history/top_sites.h" |
| 8 #include "chrome/browser/instant/instant_commit_type.h" | 12 #include "chrome/browser/instant/instant_commit_type.h" |
| 9 #include "chrome/browser/instant/instant_ntp.h" | 13 #include "chrome/browser/instant/instant_ntp.h" |
| 10 #include "chrome/browser/instant/instant_overlay.h" | 14 #include "chrome/browser/instant/instant_overlay.h" |
| 11 #include "chrome/browser/instant/instant_service.h" | 15 #include "chrome/browser/instant/instant_service.h" |
| 12 #include "chrome/browser/instant/instant_service_factory.h" | 16 #include "chrome/browser/instant/instant_service_factory.h" |
| 13 #include "chrome/browser/instant/instant_tab.h" | 17 #include "chrome/browser/instant/instant_tab.h" |
| 14 #include "chrome/browser/instant/instant_test_utils.h" | 18 #include "chrome/browser/instant/instant_test_utils.h" |
| 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/themes/theme_service.h" |
| 21 #include "chrome/browser/themes/theme_service_factory.h" |
| 22 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 15 #include "chrome/browser/ui/search/search.h" | 23 #include "chrome/browser/ui/search/search.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/ui/webui/theme_source.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/thumbnail_score.h" |
| 18 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/interactive_test_utils.h" | 30 #include "chrome/test/base/interactive_test_utils.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/site_instance.h" | 34 #include "content/public/browser/site_instance.h" |
| 35 #include "content/public/browser/url_data_source.h" |
| 24 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
| 39 #include "third_party/skia/include/core/SkBitmap.h" |
| 27 | 40 |
| 28 class InstantExtendedTest : public InstantTestBase { | 41 namespace { |
| 42 // Creates a bitmap of the specified color. Caller takes ownership. |
| 43 gfx::Image CreateBitmap(SkColor color) { |
| 44 SkBitmap thumbnail; |
| 45 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); |
| 46 thumbnail.allocPixels(); |
| 47 thumbnail.eraseColor(color); |
| 48 return gfx::Image::CreateFrom1xBitmap(thumbnail); // adds ref. |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
| 53 class InstantExtendedTest : public InstantTestBase, |
| 54 public InProcessBrowserTest { |
| 29 public: | 55 public: |
| 30 InstantExtendedTest() | 56 InstantExtendedTest() |
| 31 : on_most_visited_change_calls_(0), | 57 : on_most_visited_change_calls_(0), |
| 32 most_visited_items_count_(0), | 58 most_visited_items_count_(0), |
| 33 first_most_visited_item_id_(0) { | 59 first_most_visited_item_id_(0) { |
| 34 } | 60 } |
| 35 protected: | 61 protected: |
| 36 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 62 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 37 chrome::search::EnableInstantExtendedAPIForTesting(); | 63 chrome::search::EnableInstantExtendedAPIForTesting(); |
| 38 ASSERT_TRUE(https_test_server_.Start()); | 64 ASSERT_TRUE(https_test_server().Start()); |
| 39 instant_url_ = https_test_server_. | 65 GURL instant_url = https_test_server().GetURL( |
| 40 GetURL("files/instant_extended.html?strk=1&"); | 66 "files/instant_extended.html?strk=1&"); |
| 41 } | 67 InstantTestBase::Init(instant_url); |
| 42 | |
| 43 void FocusOmniboxAndWaitForInstantSupport() { | |
| 44 content::WindowedNotificationObserver ntp_observer( | |
| 45 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED, | |
| 46 content::NotificationService::AllSources()); | |
| 47 content::WindowedNotificationObserver overlay_observer( | |
| 48 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, | |
| 49 content::NotificationService::AllSources()); | |
| 50 FocusOmnibox(); | |
| 51 ntp_observer.Wait(); | |
| 52 overlay_observer.Wait(); | |
| 53 } | 68 } |
| 54 | 69 |
| 55 std::string GetOmniboxText() { | 70 std::string GetOmniboxText() { |
| 56 return UTF16ToUTF8(omnibox()->GetText()); | 71 return UTF16ToUTF8(omnibox()->GetText()); |
| 57 } | 72 } |
| 58 | 73 |
| 59 void SendDownArrow() { | 74 void SendDownArrow() { |
| 60 omnibox()->model()->OnUpOrDownKeyPressed(1); | 75 omnibox()->model()->OnUpOrDownKeyPressed(1); |
| 61 // Wait for JavaScript to run the key handler by executing a blank script. | 76 // Wait for JavaScript to run the key handler by executing a blank script. |
| 62 EXPECT_TRUE(ExecuteScript(std::string())); | 77 EXPECT_TRUE(ExecuteScript(std::string())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 81 &most_visited_items_count_) && | 96 &most_visited_items_count_) && |
| 82 GetIntFromJS(contents, "firstMostVisitedItemId", | 97 GetIntFromJS(contents, "firstMostVisitedItemId", |
| 83 &first_most_visited_item_id_); | 98 &first_most_visited_item_id_); |
| 84 } | 99 } |
| 85 | 100 |
| 86 int on_most_visited_change_calls_; | 101 int on_most_visited_change_calls_; |
| 87 int most_visited_items_count_; | 102 int most_visited_items_count_; |
| 88 int first_most_visited_item_id_; | 103 int first_most_visited_item_id_; |
| 89 }; | 104 }; |
| 90 | 105 |
| 106 // Test class used to verify chrome-search: scheme and access policy from the |
| 107 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it |
| 108 // loads a theme that provides a background image. |
| 109 class InstantPolicyTest : public InstantTestBase, public ExtensionBrowserTest { |
| 110 public: |
| 111 InstantPolicyTest() {} |
| 112 |
| 113 protected: |
| 114 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 115 chrome::search::EnableInstantExtendedAPIForTesting(); |
| 116 ASSERT_TRUE(https_test_server().Start()); |
| 117 GURL instant_url = https_test_server().GetURL( |
| 118 "files/instant_extended.html?strk=1&"); |
| 119 InstantTestBase::Init(instant_url); |
| 120 } |
| 121 |
| 122 void InstallThemeSource() { |
| 123 ThemeSource* theme = new ThemeSource(profile()); |
| 124 content::URLDataSource::Add(profile(), theme); |
| 125 } |
| 126 |
| 127 void InstallThemeAndVerify(const std::string& theme_dir, |
| 128 const std::string& theme_name) { |
| 129 const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_dir); |
| 130 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( |
| 131 theme_path, 1, ExtensionBrowserTest::browser())); |
| 132 const extensions::Extension* theme = |
| 133 ThemeServiceFactory::GetThemeForProfile( |
| 134 ExtensionBrowserTest::browser()->profile()); |
| 135 ASSERT_NE(static_cast<extensions::Extension*>(NULL), theme); |
| 136 ASSERT_EQ(theme->name(), theme_name); |
| 137 } |
| 138 |
| 139 private: |
| 140 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); |
| 141 }; |
| 142 |
| 91 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { | 143 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { |
| 92 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 144 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 93 EXPECT_TRUE(instant()->extended_enabled_); | 145 EXPECT_TRUE(instant()->extended_enabled_); |
| 94 } | 146 } |
| 95 | 147 |
| 96 // Test that Instant is preloaded when the omnibox is focused. | 148 // Test that Instant is preloaded when the omnibox is focused. |
| 97 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { | 149 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
| 98 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 150 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 99 | 151 |
| 100 // Explicitly unfocus the omnibox. | 152 // Explicitly unfocus the omnibox. |
| 101 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 153 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 102 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 154 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 103 | 155 |
| 104 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 156 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 105 EXPECT_FALSE(omnibox()->model()->has_focus()); | 157 EXPECT_FALSE(omnibox()->model()->has_focus()); |
| 106 | 158 |
| 107 // Delete any existing preview. | 159 // Delete any existing preview. |
| 108 instant()->overlay_.reset(); | 160 instant()->overlay_.reset(); |
| 109 EXPECT_FALSE(instant()->GetPreviewContents()); | 161 EXPECT_FALSE(instant()->GetPreviewContents()); |
| 110 | 162 |
| 111 // Refocus the omnibox. The InstantController should've preloaded Instant. | 163 // Refocus the omnibox. The InstantController should've preloaded Instant. |
| 112 FocusOmniboxAndWaitForInstantSupport(); | 164 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 113 | 165 |
| 114 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 166 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 115 EXPECT_TRUE(omnibox()->model()->has_focus()); | 167 EXPECT_TRUE(omnibox()->model()->has_focus()); |
| 116 | 168 |
| 117 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 169 content::WebContents* preview_tab = instant()->GetPreviewContents(); |
| 118 EXPECT_TRUE(preview_tab); | 170 EXPECT_TRUE(preview_tab); |
| 119 | 171 |
| 120 // Check that the page supports Instant, but it isn't showing. | 172 // Check that the page supports Instant, but it isn't showing. |
| 121 EXPECT_TRUE(instant()->overlay_->supports_instant()); | 173 EXPECT_TRUE(instant()->overlay_->supports_instant()); |
| 122 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 174 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
| 123 EXPECT_TRUE(instant()->model()->mode().is_default()); | 175 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 124 | 176 |
| 125 // Adding a new tab shouldn't delete or recreate the preview; otherwise, | 177 // Adding a new tab shouldn't delete or recreate the preview; otherwise, |
| 126 // what's the point of preloading? | 178 // what's the point of preloading? |
| 127 AddBlankTabAndShow(browser()); | 179 AddBlankTabAndShow(browser()); |
| 128 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 180 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
| 129 | 181 |
| 130 // Unfocusing and refocusing the omnibox should also preserve the preview. | 182 // Unfocusing and refocusing the omnibox should also preserve the preview. |
| 131 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 183 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 132 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 184 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 133 | 185 |
| 134 FocusOmnibox(); | 186 FocusOmnibox(); |
| 135 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 187 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 136 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 188 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
| 137 } | 189 } |
| 138 | 190 |
| 139 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { | 191 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { |
| 140 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 192 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 141 | 193 |
| 142 // Focus omnibox and confirm overlay isn't shown. | 194 // Focus omnibox and confirm overlay isn't shown. |
| 143 FocusOmniboxAndWaitForInstantSupport(); | 195 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 144 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 196 content::WebContents* preview_tab = instant()->GetPreviewContents(); |
| 145 EXPECT_TRUE(preview_tab); | 197 EXPECT_TRUE(preview_tab); |
| 146 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 198 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
| 147 EXPECT_TRUE(instant()->model()->mode().is_default()); | 199 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 148 | 200 |
| 149 // Typing in the omnibox should show the overlay. | 201 // Typing in the omnibox should show the overlay. |
| 150 SetOmniboxTextAndWaitForInstantToShow("query"); | 202 SetOmniboxTextAndWaitForInstantToShow("query"); |
| 151 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | 203 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
| 152 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 204 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
| 153 } | 205 } |
| 154 | 206 |
| 155 // Test that middle clicking on a suggestion opens the result in a new tab. | 207 // Test that middle clicking on a suggestion opens the result in a new tab. |
| 156 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 208 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 157 MiddleClickOnSuggestionOpensInNewTab) { | 209 MiddleClickOnSuggestionOpensInNewTab) { |
| 158 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 210 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 159 FocusOmniboxAndWaitForInstantSupport(); | 211 FocusOmniboxAndWaitForInstantSupport(); |
| 160 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 212 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 161 | 213 |
| 162 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 214 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 163 | 215 |
| 164 // Typing in the omnibox should show the overlay. | 216 // Typing in the omnibox should show the overlay. |
| 165 SetOmniboxTextAndWaitForInstantToShow("santa"); | 217 SetOmniboxTextAndWaitForInstantToShow("santa"); |
| 166 EXPECT_TRUE(instant()->IsPreviewingSearchResults()); | 218 EXPECT_TRUE(instant()->IsPreviewingSearchResults()); |
| 167 | 219 |
| 168 // Create an event listener that opens the top suggestion in a new tab. | 220 // Create an event listener that opens the top suggestion in a new tab. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 179 | 231 |
| 180 // Click to trigger the event listener. | 232 // Click to trigger the event listener. |
| 181 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 233 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 182 | 234 |
| 183 // Wait for the new tab to be added. | 235 // Wait for the new tab to be added. |
| 184 observer.Wait(); | 236 observer.Wait(); |
| 185 | 237 |
| 186 // Check that the new tab URL is as expected. | 238 // Check that the new tab URL is as expected. |
| 187 content::WebContents* new_tab_contents = | 239 content::WebContents* new_tab_contents = |
| 188 browser()->tab_strip_model()->GetWebContentsAt(1); | 240 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 189 EXPECT_EQ(new_tab_contents->GetURL().spec(), instant_url_.spec()+"q=santa"); | 241 EXPECT_EQ(new_tab_contents->GetURL().spec(), instant_url().spec()+"q=santa"); |
| 190 | 242 |
| 191 // Check that there are now two tabs. | 243 // Check that there are now two tabs. |
| 192 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 244 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 193 } | 245 } |
| 194 | 246 |
| 195 // Test that omnibox text is correctly set when overlay is committed with Enter. | 247 // Test that omnibox text is correctly set when overlay is committed with Enter. |
| 196 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 248 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponEnterCommit) { |
| 197 OmniboxTextUponEnterCommit) { | 249 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 198 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | |
| 199 FocusOmniboxAndWaitForInstantSupport(); | 250 FocusOmniboxAndWaitForInstantSupport(); |
| 200 | 251 |
| 201 // The page will autocomplete once we set the omnibox value. | 252 // The page will autocomplete once we set the omnibox value. |
| 202 EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';")); | 253 EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';")); |
| 203 | 254 |
| 204 // Set the text, and wait for suggestions to show up. | 255 // Set the text, and wait for suggestions to show up. |
| 205 SetOmniboxTextAndWaitForInstantToShow("santa"); | 256 SetOmniboxTextAndWaitForInstantToShow("santa"); |
| 206 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); | 257 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); |
| 207 | 258 |
| 208 // Test that the current suggestion is correctly set. | 259 // Test that the current suggestion is correctly set. |
| 209 EXPECT_EQ(ASCIIToUTF16(" claus"), omnibox()->GetInstantSuggestion()); | 260 EXPECT_EQ(ASCIIToUTF16(" claus"), omnibox()->GetInstantSuggestion()); |
| 210 | 261 |
| 211 // Commit the search by pressing Enter. | 262 // Commit the search by pressing Enter. |
| 212 browser()->window()->GetLocationBar()->AcceptInput(); | 263 browser()->window()->GetLocationBar()->AcceptInput(); |
| 213 | 264 |
| 214 // 'Enter' commits the query as it was typed. | 265 // 'Enter' commits the query as it was typed. |
| 215 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); | 266 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); |
| 216 | 267 |
| 217 // Suggestion should be cleared at this point. | 268 // Suggestion should be cleared at this point. |
| 218 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 269 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 219 } | 270 } |
| 220 | 271 |
| 221 // Test that omnibox text is correctly set when committed with focus lost. | 272 // Test that omnibox text is correctly set when committed with focus lost. |
| 222 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 273 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) { |
| 223 OmniboxTextUponFocusLostCommit) { | 274 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 224 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 275 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 225 FocusOmniboxAndWaitForInstantSupport(); | |
| 226 | 276 |
| 227 // Set autocomplete text (grey text). | 277 // Set autocomplete text (grey text). |
| 228 EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';")); | 278 EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';")); |
| 229 | 279 |
| 230 // Set the text, and wait for suggestions to show up. | 280 // Set the text, and wait for suggestions to show up. |
| 231 SetOmniboxTextAndWaitForInstantToShow("johnny"); | 281 SetOmniboxTextAndWaitForInstantToShow("johnny"); |
| 232 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); | 282 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); |
| 233 | 283 |
| 234 // Test that the current suggestion is correctly set. | 284 // Test that the current suggestion is correctly set. |
| 235 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); | 285 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); |
| 236 | 286 |
| 237 // Commit the overlay by lost focus (e.g. clicking on the page). | 287 // Commit the overlay by lost focus (e.g. clicking on the page). |
| 238 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 288 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 239 | 289 |
| 240 // Search term extraction should kick in with the autocompleted text. | 290 // Search term extraction should kick in with the autocompleted text. |
| 241 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText()); | 291 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText()); |
| 242 | 292 |
| 243 // Suggestion should be cleared at this point. | 293 // Suggestion should be cleared at this point. |
| 244 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 294 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 245 } | 295 } |
| 246 | 296 |
| 247 // Test that omnibox text is correctly set when clicking on committed SERP. | 297 // Test that omnibox text is correctly set when clicking on committed SERP. |
| 248 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 298 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 249 OmniboxTextUponFocusedCommittedSERP) { | 299 OmniboxTextUponFocusedCommittedSERP) { |
| 250 // Setup Instant. | 300 // Setup Instant. |
| 251 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 301 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 252 FocusOmniboxAndWaitForInstantSupport(); | 302 FocusOmniboxAndWaitForInstantSupport(); |
| 253 | 303 |
| 254 // Do a search and commit it. | 304 // Do a search and commit it. |
| 255 SetOmniboxTextAndWaitForInstantToShow("hello k"); | 305 SetOmniboxTextAndWaitForInstantToShow("hello k"); |
| 256 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); | 306 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); |
| 257 browser()->window()->GetLocationBar()->AcceptInput(); | 307 browser()->window()->GetLocationBar()->AcceptInput(); |
| 258 | 308 |
| 259 // With a committed results page, do a search by unfocusing the omnibox and | 309 // With a committed results page, do a search by unfocusing the omnibox and |
| 260 // focusing the contents. | 310 // focusing the contents. |
| 261 SetOmniboxText("hello"); | 311 SetOmniboxText("hello"); |
| 262 // Calling handleOnChange manually to make sure it is called before the | 312 // Calling handleOnChange manually to make sure it is called before the |
| 263 // Focus() call below. | 313 // Focus() call below. |
| 264 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), | 314 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), |
| 265 "suggestion = 'hello kitty';" | 315 "suggestion = 'hello kitty';" |
| 266 "handleOnChange();")); | 316 "handleOnChange();")); |
| 267 instant()->instant_tab()->contents()->GetView()->Focus(); | 317 instant()->instant_tab()->contents()->GetView()->Focus(); |
| 268 | 318 |
| 269 // Search term extraction should kick in with the autocompleted text. | 319 // Search term extraction should kick in with the autocompleted text. |
| 270 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); | 320 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); |
| 271 | 321 |
| 272 // Suggestion should be cleared at this point. | 322 // Suggestion should be cleared at this point. |
| 273 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 323 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 274 } | 324 } |
| 275 | 325 |
| 276 // This test simulates a search provider using the InstantExtended API to | 326 // This test simulates a search provider using the InstantExtended API to |
| 277 // navigate through the suggested results and back to the original user query. | 327 // navigate through the suggested results and back to the original user query. |
| 278 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { | 328 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { |
| 279 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 329 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 280 FocusOmniboxAndWaitForInstantSupport(); | 330 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 281 | 331 |
| 282 SetOmniboxTextAndWaitForInstantToShow("hello"); | 332 SetOmniboxTextAndWaitForInstantToShow("hello"); |
| 283 EXPECT_EQ("hello", GetOmniboxText()); | 333 EXPECT_EQ("hello", GetOmniboxText()); |
| 284 | 334 |
| 285 SendDownArrow(); | 335 SendDownArrow(); |
| 286 EXPECT_EQ("result 1", GetOmniboxText()); | 336 EXPECT_EQ("result 1", GetOmniboxText()); |
| 287 SendDownArrow(); | 337 SendDownArrow(); |
| 288 EXPECT_EQ("result 2", GetOmniboxText()); | 338 EXPECT_EQ("result 2", GetOmniboxText()); |
| 289 SendUpArrow(); | 339 SendUpArrow(); |
| 290 EXPECT_EQ("result 1", GetOmniboxText()); | 340 EXPECT_EQ("result 1", GetOmniboxText()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 307 // TODO(sreeram): Enable this check once @mathp's CL lands: | 357 // TODO(sreeram): Enable this check once @mathp's CL lands: |
| 308 // https://codereview.chromium.org/12179025/ | 358 // https://codereview.chromium.org/12179025/ |
| 309 // browser()->window()->GetLocationBar()->AcceptInput(); | 359 // browser()->window()->GetLocationBar()->AcceptInput(); |
| 310 // EXPECT_EQ("hello", GetOmniboxText()); | 360 // EXPECT_EQ("hello", GetOmniboxText()); |
| 311 } | 361 } |
| 312 | 362 |
| 313 // This test simulates a search provider using the InstantExtended API to | 363 // This test simulates a search provider using the InstantExtended API to |
| 314 // navigate through the suggested results and hitting escape to get back to the | 364 // navigate through the suggested results and hitting escape to get back to the |
| 315 // original user query. | 365 // original user query. |
| 316 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { | 366 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { |
| 317 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 367 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 318 FocusOmniboxAndWaitForInstantSupport(); | 368 FocusOmniboxAndWaitForInstantSupport(); |
| 319 | 369 |
| 320 SetOmniboxTextAndWaitForInstantToShow("hello"); | 370 SetOmniboxTextAndWaitForInstantToShow("hello"); |
| 321 EXPECT_EQ("hello", GetOmniboxText()); | 371 EXPECT_EQ("hello", GetOmniboxText()); |
| 322 | 372 |
| 323 SendDownArrow(); | 373 SendDownArrow(); |
| 324 EXPECT_EQ("result 1", GetOmniboxText()); | 374 EXPECT_EQ("result 1", GetOmniboxText()); |
| 325 SendDownArrow(); | 375 SendDownArrow(); |
| 326 EXPECT_EQ("result 2", GetOmniboxText()); | 376 EXPECT_EQ("result 2", GetOmniboxText()); |
| 327 SendEscape(); | 377 SendEscape(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 | 389 |
| 340 // Commit the search by pressing Enter. | 390 // Commit the search by pressing Enter. |
| 341 // TODO(sreeram): Enable this check once @mathp's CL lands: | 391 // TODO(sreeram): Enable this check once @mathp's CL lands: |
| 342 // https://codereview.chromium.org/12179025/ | 392 // https://codereview.chromium.org/12179025/ |
| 343 // browser()->window()->GetLocationBar()->AcceptInput(); | 393 // browser()->window()->GetLocationBar()->AcceptInput(); |
| 344 // EXPECT_EQ("hello", GetOmniboxText()); | 394 // EXPECT_EQ("hello", GetOmniboxText()); |
| 345 } | 395 } |
| 346 | 396 |
| 347 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { | 397 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { |
| 348 // Setup Instant. | 398 // Setup Instant. |
| 349 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 399 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 350 FocusOmniboxAndWaitForInstantSupport(); | 400 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 351 | 401 |
| 352 // NTP contents should be preloaded. | 402 // NTP contents should be preloaded. |
| 353 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 403 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 354 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 404 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
| 355 EXPECT_TRUE(ntp_contents); | 405 EXPECT_TRUE(ntp_contents); |
| 356 } | 406 } |
| 357 | 407 |
| 358 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { | 408 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { |
| 359 // Setup Instant. | 409 // Setup Instant. |
| 360 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 410 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 361 FocusOmniboxAndWaitForInstantSupport(); | 411 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 362 | 412 |
| 363 // NTP contents should be preloaded. | 413 // NTP contents should be preloaded. |
| 364 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 414 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 365 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 415 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
| 366 EXPECT_TRUE(ntp_contents); | 416 EXPECT_TRUE(ntp_contents); |
| 367 | 417 |
| 368 // Open new tab. Preloaded NTP contents should have been used. | 418 // Open new tab. Preloaded NTP contents should have been used. |
| 369 ui_test_utils::NavigateToURLWithDisposition( | 419 ui_test_utils::NavigateToURLWithDisposition( |
| 370 browser(), | 420 browser(), |
| 371 GURL(chrome::kChromeUINewTabURL), | 421 GURL(chrome::kChromeUINewTabURL), |
| 372 NEW_FOREGROUND_TAB, | 422 NEW_FOREGROUND_TAB, |
| 373 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 423 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 374 content::WebContents* active_tab = | 424 content::WebContents* active_tab = |
| 375 browser()->tab_strip_model()->GetActiveWebContents(); | 425 browser()->tab_strip_model()->GetActiveWebContents(); |
| 376 EXPECT_EQ(ntp_contents, active_tab); | 426 EXPECT_EQ(ntp_contents, active_tab); |
| 377 } | 427 } |
| 378 | 428 |
| 379 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { | 429 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { |
| 380 // Setup Instant. | 430 // Setup Instant. |
| 381 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 431 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 382 FocusOmniboxAndWaitForInstantSupport(); | 432 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 383 | 433 |
| 384 // NTP contents should be preloaded. | 434 // NTP contents should be preloaded. |
| 385 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 435 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 386 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 436 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
| 387 EXPECT_TRUE(ntp_contents); | 437 EXPECT_TRUE(ntp_contents); |
| 388 | 438 |
| 389 // Open new tab. Preloaded NTP contents should have been used. | 439 // Open new tab. Preloaded NTP contents should have been used. |
| 390 ui_test_utils::NavigateToURLWithDisposition( | 440 ui_test_utils::NavigateToURLWithDisposition( |
| 391 browser(), | 441 browser(), |
| 392 GURL(chrome::kChromeUINewTabURL), | 442 GURL(chrome::kChromeUINewTabURL), |
| 393 CURRENT_TAB, | 443 CURRENT_TAB, |
| 394 ui_test_utils::BROWSER_TEST_NONE); | 444 ui_test_utils::BROWSER_TEST_NONE); |
| 395 content::WebContents* active_tab = | 445 content::WebContents* active_tab = |
| 396 browser()->tab_strip_model()->GetActiveWebContents(); | 446 browser()->tab_strip_model()->GetActiveWebContents(); |
| 397 EXPECT_EQ(ntp_contents, active_tab); | 447 EXPECT_EQ(ntp_contents, active_tab); |
| 398 } | 448 } |
| 399 | 449 |
| 400 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { | 450 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { |
| 401 // Setup Instant. | 451 // Setup Instant. |
| 402 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 452 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 403 FocusOmniboxAndWaitForInstantSupport(); | 453 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 404 | 454 |
| 405 // Explicitly unfocus the omnibox. | 455 // Explicitly unfocus the omnibox. |
| 406 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 456 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 407 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 457 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 408 EXPECT_FALSE(omnibox()->model()->has_focus()); | 458 EXPECT_FALSE(omnibox()->model()->has_focus()); |
| 409 | 459 |
| 410 // Open new tab. Preloaded NTP contents should have been used. | 460 // Open new tab. Preloaded NTP contents should have been used. |
| 411 ui_test_utils::NavigateToURLWithDisposition( | 461 ui_test_utils::NavigateToURLWithDisposition( |
| 412 browser(), | 462 browser(), |
| 413 GURL(chrome::kChromeUINewTabURL), | 463 GURL(chrome::kChromeUINewTabURL), |
| 414 NEW_FOREGROUND_TAB, | 464 NEW_FOREGROUND_TAB, |
| 415 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 465 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 416 | 466 |
| 417 // Omnibox should have focus. | 467 // Omnibox should have focus. |
| 418 EXPECT_TRUE(omnibox()->model()->has_focus()); | 468 EXPECT_TRUE(omnibox()->model()->has_focus()); |
| 419 } | 469 } |
| 420 | 470 |
| 421 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { | 471 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { |
| 422 // Setup Instant. | 472 // Setup Instant. |
| 423 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 473 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 424 FocusOmniboxAndWaitForInstantSupport(); | 474 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 425 | 475 |
| 426 // Open new tab. Preloaded NTP contents should have been used. | 476 // Open new tab. Preloaded NTP contents should have been used. |
| 427 ui_test_utils::NavigateToURLWithDisposition( | 477 ui_test_utils::NavigateToURLWithDisposition( |
| 428 browser(), | 478 browser(), |
| 429 GURL(chrome::kChromeUINewTabURL), | 479 GURL(chrome::kChromeUINewTabURL), |
| 430 CURRENT_TAB, | 480 CURRENT_TAB, |
| 431 ui_test_utils::BROWSER_TEST_NONE); | 481 ui_test_utils::BROWSER_TEST_NONE); |
| 432 | 482 |
| 433 // Omnibox should be empty. | 483 // Omnibox should be empty. |
| 434 EXPECT_TRUE(omnibox()->GetText().empty()); | 484 EXPECT_TRUE(omnibox()->GetText().empty()); |
| 435 } | 485 } |
| 436 | 486 |
| 437 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) { | 487 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) { |
| 438 // Setup Instant. | 488 // Setup Instant. |
| 439 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 489 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 440 FocusOmniboxAndWaitForInstantSupport(); | 490 FocusOmniboxAndWaitForInstantSupport(); |
| 441 | 491 |
| 442 // Open new tab. Preloaded NTP contents should have been used. | 492 // Open new tab. Preloaded NTP contents should have been used. |
| 443 ui_test_utils::NavigateToURLWithDisposition( | 493 ui_test_utils::NavigateToURLWithDisposition( |
| 444 browser(), | 494 browser(), |
| 445 GURL(chrome::kChromeUINewTabURL), | 495 GURL(chrome::kChromeUINewTabURL), |
| 446 CURRENT_TAB, | 496 CURRENT_TAB, |
| 447 ui_test_utils::BROWSER_TEST_NONE); | 497 ui_test_utils::BROWSER_TEST_NONE); |
| 448 | 498 |
| 449 // No favicon should be shown. | 499 // No favicon should be shown. |
| 450 content::WebContents* active_tab = | 500 content::WebContents* active_tab = |
| 451 browser()->tab_strip_model()->GetActiveWebContents(); | 501 browser()->tab_strip_model()->GetActiveWebContents(); |
| 452 FaviconTabHelper* favicon_tab_helper = | 502 FaviconTabHelper* favicon_tab_helper = |
| 453 FaviconTabHelper::FromWebContents(active_tab); | 503 FaviconTabHelper::FromWebContents(active_tab); |
| 454 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); | 504 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 455 | 505 |
| 456 // Favicon should be shown off the NTP. | 506 // Favicon should be shown off the NTP. |
| 457 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 507 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 458 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 508 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 459 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); | 509 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); |
| 460 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); | 510 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 461 } | 511 } |
| 462 | 512 |
| 463 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) { | 513 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) { |
| 464 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 514 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 465 | 515 |
| 466 // Focus omnibox and confirm overlay isn't shown. | 516 // Focus omnibox and confirm overlay isn't shown. |
| 467 FocusOmniboxAndWaitForInstantSupport(); | 517 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 468 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 518 content::WebContents* preview_tab = instant()->GetPreviewContents(); |
| 469 EXPECT_TRUE(preview_tab); | 519 EXPECT_TRUE(preview_tab); |
| 470 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 520 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
| 471 EXPECT_TRUE(instant()->model()->mode().is_default()); | 521 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 472 | 522 |
| 473 // Navigate to the NTP. | 523 // Navigate to the NTP. |
| 474 ui_test_utils::NavigateToURLWithDisposition( | 524 ui_test_utils::NavigateToURLWithDisposition( |
| 475 browser(), | 525 browser(), |
| 476 GURL(chrome::kChromeUINewTabURL), | 526 GURL(chrome::kChromeUINewTabURL), |
| 477 CURRENT_TAB, | 527 CURRENT_TAB, |
| 478 ui_test_utils::BROWSER_TEST_NONE); | 528 ui_test_utils::BROWSER_TEST_NONE); |
| 479 | 529 |
| 480 // Typing in the omnibox should not show the overlay. | 530 // Typing in the omnibox should not show the overlay. |
| 481 SetOmniboxText("query"); | 531 SetOmniboxText("query"); |
| 482 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 532 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
| 483 EXPECT_TRUE(instant()->model()->mode().is_default()); | 533 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 484 } | 534 } |
| 485 | 535 |
| 486 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { | 536 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { |
| 487 // Prior to setup, Instant has an overlay with a failed "google.com" load in | 537 // Prior to setup, Instant has an overlay with a failed "google.com" load in |
| 488 // it, which is rendered in the dedicated Instant renderer process. | 538 // it, which is rendered in the dedicated Instant renderer process. |
| 489 // | 539 // |
| 490 // TODO(sreeram): Fix this up when we stop doing crazy things on init. | 540 // TODO(sreeram): Fix this up when we stop doing crazy things on init. |
| 491 InstantService* instant_service = | 541 InstantService* instant_service = |
| 492 InstantServiceFactory::GetForProfile(browser()->profile()); | 542 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 493 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | 543 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 494 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | 544 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
| 495 | 545 |
| 496 // Setup Instant. | 546 // Setup Instant. |
| 497 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 547 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 498 FocusOmniboxAndWaitForInstantSupport(); | 548 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 499 | 549 |
| 500 // The registered Instant render process should still exist. | 550 // The registered Instant render process should still exist. |
| 501 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | 551 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
| 502 | 552 |
| 503 // And the Instant overlay and ntp should live inside it. | 553 // And the Instant overlay and ntp should live inside it. |
| 504 content::WebContents* preview = instant()->GetPreviewContents(); | 554 content::WebContents* preview = instant()->GetPreviewContents(); |
| 505 EXPECT_TRUE(instant_service->IsInstantProcess( | 555 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 506 preview->GetRenderProcessHost()->GetID())); | 556 preview->GetRenderProcessHost()->GetID())); |
| 507 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 557 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
| 508 EXPECT_TRUE(instant_service->IsInstantProcess( | 558 EXPECT_TRUE(instant_service->IsInstantProcess( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 524 EXPECT_FALSE(instant_service->IsInstantProcess( | 574 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 525 active_tab->GetRenderProcessHost()->GetID())); | 575 active_tab->GetRenderProcessHost()->GetID())); |
| 526 } | 576 } |
| 527 | 577 |
| 528 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in | 578 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in |
| 529 // a tab uses a new BrowsingInstance, to avoid conflicts in the | 579 // a tab uses a new BrowsingInstance, to avoid conflicts in the |
| 530 // NavigationController. | 580 // NavigationController. |
| 531 // Flaky: http://crbug.com/177516 | 581 // Flaky: http://crbug.com/177516 |
| 532 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { | 582 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { |
| 533 // Setup Instant. | 583 // Setup Instant. |
| 534 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 584 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 535 FocusOmniboxAndWaitForInstantSupport(); | 585 FocusOmniboxAndWaitForInstantSupport(); |
| 536 | 586 |
| 537 // Check that the uncommited ntp page and uncommited preview have unrelated | 587 // Check that the uncommited ntp page and uncommited preview have unrelated |
| 538 // site instances. | 588 // site instances. |
| 539 // TODO(sreeram): |ntp_| is going away, so this check can be removed in the | 589 // TODO(sreeram): |ntp_| is going away, so this check can be removed in the |
| 540 // future. | 590 // future. |
| 541 content::WebContents* preview = instant()->GetPreviewContents(); | 591 content::WebContents* preview = instant()->GetPreviewContents(); |
| 542 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 592 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
| 543 EXPECT_FALSE(preview->GetSiteInstance()->IsRelatedSiteInstance( | 593 EXPECT_FALSE(preview->GetSiteInstance()->IsRelatedSiteInstance( |
| 544 ntp_contents->GetSiteInstance())); | 594 ntp_contents->GetSiteInstance())); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 569 EXPECT_NE(first_active_tab, second_active_tab); | 619 EXPECT_NE(first_active_tab, second_active_tab); |
| 570 scoped_refptr<content::SiteInstance> second_site_instance = | 620 scoped_refptr<content::SiteInstance> second_site_instance = |
| 571 second_active_tab->GetSiteInstance(); | 621 second_active_tab->GetSiteInstance(); |
| 572 EXPECT_NE(first_site_instance, second_site_instance); | 622 EXPECT_NE(first_site_instance, second_site_instance); |
| 573 EXPECT_FALSE(first_site_instance->IsRelatedSiteInstance( | 623 EXPECT_FALSE(first_site_instance->IsRelatedSiteInstance( |
| 574 second_site_instance)); | 624 second_site_instance)); |
| 575 } | 625 } |
| 576 | 626 |
| 577 // Tests that suggestions are sanity checked. | 627 // Tests that suggestions are sanity checked. |
| 578 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { | 628 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { |
| 579 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 629 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 580 FocusOmniboxAndWaitForInstantSupport(); | 630 FocusOmniboxAndWaitForInstantSupport(); |
| 581 | 631 |
| 582 // Do not set gray text that is not a suffix of the query. | 632 // Do not set gray text that is not a suffix of the query. |
| 583 EXPECT_TRUE(ExecuteScript("behavior = 2")); | 633 EXPECT_TRUE(ExecuteScript("behavior = 2")); |
| 584 EXPECT_TRUE(ExecuteScript("suggestion = 'potato'")); | 634 EXPECT_TRUE(ExecuteScript("suggestion = 'potato'")); |
| 585 SetOmniboxTextAndWaitForInstantToShow("query"); | 635 SetOmniboxTextAndWaitForInstantToShow("query"); |
| 586 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); | 636 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
| 587 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 637 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 588 | 638 |
| 589 omnibox()->RevertAll(); | 639 omnibox()->RevertAll(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 SetOmniboxText("www.example.com/"); | 677 SetOmniboxText("www.example.com/"); |
| 628 omnibox()->OnAfterPossibleChange(); | 678 omnibox()->OnAfterPossibleChange(); |
| 629 EXPECT_EQ(ASCIIToUTF16("www.example.com/"), omnibox()->GetText()); | 679 EXPECT_EQ(ASCIIToUTF16("www.example.com/"), omnibox()->GetText()); |
| 630 } | 680 } |
| 631 | 681 |
| 632 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { | 682 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { |
| 633 content::WindowedNotificationObserver observer( | 683 content::WindowedNotificationObserver observer( |
| 634 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 684 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
| 635 content::NotificationService::AllSources()); | 685 content::NotificationService::AllSources()); |
| 636 // Initialize Instant. | 686 // Initialize Instant. |
| 637 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 687 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 638 FocusOmniboxAndWaitForInstantSupport(); | 688 FocusOmniboxAndWaitForInstantSupport(); |
| 639 | 689 |
| 640 // Get a handle to the NTP and the current state of the JS. | 690 // Get a handle to the NTP and the current state of the JS. |
| 641 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 691 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 642 content::WebContents* preview_tab = instant()->ntp_->contents(); | 692 content::WebContents* preview_tab = instant()->ntp_->contents(); |
| 643 EXPECT_TRUE(preview_tab); | 693 EXPECT_TRUE(preview_tab); |
| 644 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 694 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
| 645 | 695 |
| 646 // Wait for most visited data to be ready, if necessary. | 696 // Wait for most visited data to be ready, if necessary. |
| 647 if (on_most_visited_change_calls_ == 0) { | 697 if (on_most_visited_change_calls_ == 0) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 stream << "newTabPageHandle.undoAllMostVisitedDeletions()"; | 761 stream << "newTabPageHandle.undoAllMostVisitedDeletions()"; |
| 712 EXPECT_TRUE(ExecuteScript(stream.str())); | 762 EXPECT_TRUE(ExecuteScript(stream.str())); |
| 713 observer.Wait(); | 763 observer.Wait(); |
| 714 | 764 |
| 715 // Update Most Visited state. | 765 // Update Most Visited state. |
| 716 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 766 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
| 717 | 767 |
| 718 // Make sure we have the same number of items as before. | 768 // Make sure we have the same number of items as before. |
| 719 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); | 769 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); |
| 720 } | 770 } |
| 771 |
| 772 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { |
| 773 InstallThemeSource(); |
| 774 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
| 775 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 776 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 777 |
| 778 // The "Instant" New Tab should have access to chrome-search: scheme but not |
| 779 // chrome: scheme. |
| 780 ui_test_utils::NavigateToURLWithDisposition( |
| 781 browser(), |
| 782 GURL(chrome::kChromeUINewTabURL), |
| 783 NEW_FOREGROUND_TAB, |
| 784 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 785 |
| 786 content::RenderViewHost* rvh = |
| 787 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
| 788 |
| 789 const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); |
| 790 const std::string search_url( |
| 791 "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); |
| 792 bool loaded = false; |
| 793 ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); |
| 794 EXPECT_FALSE(loaded) << chrome_url; |
| 795 ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); |
| 796 EXPECT_TRUE(loaded) << search_url; |
| 797 } |
| 798 |
| 799 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FaviconAccess) { |
| 800 // Create a favicon. |
| 801 history::TopSites* top_sites = browser()->profile()->GetTopSites(); |
| 802 GURL url("http://www.google.com/foo.html"); |
| 803 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); |
| 804 ThumbnailScore high_score(0.0, true, true, base::Time::Now()); |
| 805 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); |
| 806 |
| 807 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 808 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 809 |
| 810 // The "Instant" New Tab should have access to chrome-search: scheme but not |
| 811 // chrome: scheme. |
| 812 ui_test_utils::NavigateToURLWithDisposition( |
| 813 browser(), |
| 814 GURL(chrome::kChromeUINewTabURL), |
| 815 NEW_FOREGROUND_TAB, |
| 816 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 817 |
| 818 content::RenderViewHost* rvh = |
| 819 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
| 820 |
| 821 // Get the favicons. |
| 822 const std::string chrome_favicon_url( |
| 823 "chrome://favicon/largest/http://www.google.com/foo.html"); |
| 824 const std::string search_favicon_url( |
| 825 "chrome-search://favicon/largest/http://www.google.com/foo.html"); |
| 826 bool loaded = false; |
| 827 ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded)); |
| 828 EXPECT_FALSE(loaded) << chrome_favicon_url; |
| 829 ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded)); |
| 830 EXPECT_TRUE(loaded) << search_favicon_url; |
| 831 } |
| OLD | NEW |