Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/instant/instant_controller.h" | 10 #include "chrome/browser/instant/instant_controller.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 | 41 |
| 42 using content::WebContents; | 42 using content::WebContents; |
| 43 | 43 |
| 44 // Tests are flaky on Linux because of http://crbug.com/80118. | 44 // Tests are flaky on Linux because of http://crbug.com/80118. |
| 45 #if defined(OS_LINUX) && !defined(USE_ASH) | 45 #if defined(OS_WIN) |
| 46 #define MAYBE(TestName) DISABLED_ ## TestName | |
| 47 #elif defined(OS_WIN) | |
| 48 #define MAYBE(TestName) FLAKY_ ## TestName | 46 #define MAYBE(TestName) FLAKY_ ## TestName |
| 49 #else | 47 #else |
| 50 #define MAYBE(TestName) TestName | 48 #define MAYBE(TestName) TestName |
| 51 #endif | 49 #endif |
| 52 | 50 |
| 53 class InstantTest : public InProcessBrowserTest { | 51 class InstantTest : public InProcessBrowserTest { |
| 54 public: | 52 public: |
| 55 InstantTest() {} | 53 InstantTest() : |
| 54 search_term_(ASCIIToUTF16("def")) { | |
|
sky
2012/07/25 17:29:56
Either put search_term_ on the previous line, or w
jered1
2012/07/25 20:22:04
Done.
| |
| 55 } | |
| 56 | 56 |
| 57 void EnableInstant() { | 57 void EnableInstant() { |
| 58 InstantController::Enable(browser()->profile()); | 58 InstantController::Enable(browser()->profile()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SetupInstantProvider(const std::string& page) { | 61 void SetupInstantProvider(const std::string& page) { |
| 62 Profile* profile = browser()->profile(); | 62 Profile* profile = browser()->profile(); |
| 63 TemplateURLService* model = | 63 TemplateURLService* model = |
| 64 TemplateURLServiceFactory::GetForProfile(profile); | 64 TemplateURLServiceFactory::GetForProfile(profile); |
| 65 | 65 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 77 data.SetURL(base::StringPrintf("http://%s:%d/files/%s?q={searchTerms}", | 77 data.SetURL(base::StringPrintf("http://%s:%d/files/%s?q={searchTerms}", |
| 78 test_server()->host_port_pair().host().c_str(), | 78 test_server()->host_port_pair().host().c_str(), |
| 79 test_server()->host_port_pair().port(), page.c_str())); | 79 test_server()->host_port_pair().port(), page.c_str())); |
| 80 data.instant_url = data.url(); | 80 data.instant_url = data.url(); |
| 81 // TemplateURLService takes ownership of this. | 81 // TemplateURLService takes ownership of this. |
| 82 TemplateURL* template_url = new TemplateURL(profile, data); | 82 TemplateURL* template_url = new TemplateURL(profile, data); |
| 83 model->Add(template_url); | 83 model->Add(template_url); |
| 84 model->SetDefaultSearchProvider(template_url); | 84 model->SetDefaultSearchProvider(template_url); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SetOmniboxFocusAndUserText(const string16& user_text) { | |
| 88 omnibox()->SetFocus(); | |
| 89 omnibox()->SetUserText(user_text); | |
| 90 } | |
| 91 | |
| 87 // Type a character to get instant to trigger and determine instant support. | 92 // Type a character to get instant to trigger and determine instant support. |
| 88 void DetermineInstantSupport() { | 93 void DetermineInstantSupport() { |
| 89 content::WindowedNotificationObserver observer( | 94 content::WindowedNotificationObserver observer( |
| 90 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 95 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 91 content::NotificationService::AllSources()); | 96 content::NotificationService::AllSources()); |
| 92 // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword. | 97 // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword. |
| 93 // "c" might someday trigger a "chrome:" provider. | 98 // "c" might someday trigger a "chrome:" provider. |
| 94 omnibox()->SetUserText(ASCIIToUTF16("d")); | 99 SetOmniboxFocusAndUserText(ASCIIToUTF16("d")); |
| 95 observer.Wait(); | 100 observer.Wait(); |
| 96 } | 101 } |
| 97 | 102 |
| 98 // Types "def" into the omnibox and waits for the preview to be shown. | 103 // Types "def" into the omnibox and waits for the preview to be shown. |
| 99 void SearchAndWaitForPreviewToShow() { | 104 void SearchAndWaitForPreviewToShow() { |
| 100 content::WindowedNotificationObserver observer( | 105 content::WindowedNotificationObserver observer( |
| 101 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | 106 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 102 content::NotificationService::AllSources()); | 107 content::NotificationService::AllSources()); |
| 103 omnibox()->SetUserText(ASCIIToUTF16("def")); | 108 SetOmniboxFocusAndUserText(search_term_); |
| 104 observer.Wait(); | 109 observer.Wait(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 // Sends a message to the renderer and waits for the response to come back to | 112 // Sends a message to the renderer and waits for the response to come back to |
| 108 // the browser. Returns true on success. | 113 // the browser. Returns true on success. |
| 109 bool WaitForMessageToBeProcessedByRenderer() { | 114 bool WaitForMessageToBeProcessedByRenderer() { |
| 110 bool result = false; | 115 bool result = false; |
| 111 return GetBoolFromJavascript(preview()->web_contents(), "true", &result) && | 116 return GetBoolFromJavascript(preview()->web_contents(), "true", &result) && |
| 112 result; | 117 result; |
| 113 } | 118 } |
| 114 | 119 |
| 115 InstantController* instant() const { | 120 InstantController* instant() const { |
| 116 return browser()->instant_controller()->instant(); | 121 return browser()->instant_controller()->instant(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 OmniboxView* omnibox() const { | 124 OmniboxView* omnibox() const { |
| 120 return browser()->window()->GetLocationBar()->GetLocationEntry(); | 125 return browser()->window()->GetLocationBar()->GetLocationEntry(); |
| 121 } | 126 } |
| 122 | 127 |
| 123 TabContents* preview() const { | 128 TabContents* preview() const { |
| 124 return instant()->GetPreviewContents(); | 129 return instant()->GetPreviewContents(); |
| 125 } | 130 } |
| 126 | 131 |
| 127 InstantLoader* loader() const { | 132 InstantLoader* loader() const { |
| 128 return instant()->loader_.get(); | 133 return instant()->loader_.get(); |
| 129 } | 134 } |
| 130 | 135 |
| 131 std::string GetSuggestion() const { | 136 string16 last_full_text() const { |
|
sky
2012/07/25 17:29:56
const string16&
jered1
2012/07/25 20:22:04
Done.
| |
| 132 return UTF16ToUTF8(loader()->complete_suggested_text_); | 137 return instant()->last_full_text_; |
| 138 } | |
| 139 | |
| 140 bool is_showing() const { | |
| 141 return instant()->is_showing_; | |
| 133 } | 142 } |
| 134 | 143 |
| 135 bool PressEnter() { | 144 bool PressEnter() { |
| 136 return ui_test_utils::SendKeyPressSync( | 145 return ui_test_utils::SendKeyPressSync( |
| 137 browser(), ui::VKEY_RETURN, false, false, false, false); | 146 browser(), ui::VKEY_RETURN, false, false, false, false); |
| 138 } | 147 } |
| 139 | 148 |
| 140 bool SetSuggestionsJavascriptArgument(const std::string& argument) { | 149 bool SetSuggestionsJavascriptArgument(const std::string& argument) { |
| 141 std::wstring script = UTF8ToWide(base::StringPrintf( | 150 std::wstring script = UTF8ToWide(base::StringPrintf( |
| 142 "window.setSuggestionsArgument = %s;", argument.c_str())); | 151 "window.setSuggestionsArgument = %s;", argument.c_str())); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 selection_end); | 265 selection_end); |
| 257 } | 266 } |
| 258 | 267 |
| 259 protected: | 268 protected: |
| 260 virtual void SetUpCommandLine(CommandLine* command_line) { | 269 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 261 // Do not prelaunch the GPU process for these tests because it will show | 270 // Do not prelaunch the GPU process for these tests because it will show |
| 262 // up in task manager but whether it appears before or after the new tab | 271 // up in task manager but whether it appears before or after the new tab |
| 263 // renderer process is not well defined. | 272 // renderer process is not well defined. |
| 264 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); | 273 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); |
| 265 } | 274 } |
| 275 | |
| 276 const string16 search_term_; | |
| 266 }; | 277 }; |
| 267 | 278 |
| 268 // TODO(tonyg): Add the following tests: | 279 // TODO(tonyg): Add the following tests: |
| 269 // - Test that the search box API is not populated for pages other than the | 280 // - Test that the search box API is not populated for pages other than the |
| 270 // default search provider. | 281 // default search provider. |
| 271 // - Test resize events. | 282 // - Test resize events. |
| 272 | 283 |
| 273 // Verify that the onchange event is dispatched upon typing in the box. | 284 // Verify that the onchange event is dispatched upon typing in the box. |
| 274 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnChangeEvent)) { | 285 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnChangeEvent)) { |
| 275 ASSERT_TRUE(test_server()->Start()); | 286 ASSERT_TRUE(test_server()->Start()); |
| 276 EnableInstant(); | 287 EnableInstant(); |
| 277 SetupInstantProvider("instant.html"); | 288 SetupInstantProvider("instant.html"); |
| 278 DetermineInstantSupport(); | 289 DetermineInstantSupport(); |
| 279 SearchAndWaitForPreviewToShow(); | 290 SearchAndWaitForPreviewToShow(); |
| 280 | 291 |
| 281 EXPECT_TRUE(preview()); | 292 EXPECT_TRUE(preview()); |
| 282 EXPECT_TRUE(instant()->is_displayable()); | 293 EXPECT_TRUE(is_showing()); |
| 283 EXPECT_TRUE(instant()->IsCurrent()); | 294 EXPECT_TRUE(instant()->IsCurrent()); |
| 284 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); | 295 EXPECT_EQ(ASCIIToUTF16("defghi"), omnibox()->GetText()); |
| 285 | 296 |
| 286 // Make sure the URL that will get committed when we press <Enter> matches | 297 // Make sure the URL that will get committed when we press <Enter> matches |
| 287 // that of the default search provider. | 298 // that of the default search provider. |
| 288 const TemplateURL* default_turl = | 299 const TemplateURL* default_turl = |
| 289 TemplateURLServiceFactory::GetForProfile(browser()->profile())-> | 300 TemplateURLServiceFactory::GetForProfile(browser()->profile())-> |
| 290 GetDefaultSearchProvider(); | 301 GetDefaultSearchProvider(); |
| 291 EXPECT_TRUE(default_turl); | 302 EXPECT_TRUE(default_turl); |
| 292 EXPECT_EQ(default_turl->url_ref().ReplaceSearchTerms( | 303 EXPECT_EQ(default_turl->url_ref().ReplaceSearchTerms( |
| 293 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("defghi"))), | 304 TemplateURLRef::SearchTermsArgs(string16())), |
| 294 loader()->url().spec()); | 305 loader()->instant_url().spec()); |
| 295 | 306 |
| 296 // Check that the value is reflected and onchange is called. | 307 // Check that the value is reflected and onchange is called. |
| 297 EXPECT_EQ("true 0 0 1 true d false def false 3 3", | 308 EXPECT_EQ("true 0 0 2 false d false def true 3 3", |
| 298 GetSearchStateAsString(preview()->web_contents(), false)); | 309 GetSearchStateAsString(preview()->web_contents(), false)); |
| 299 } | 310 } |
| 300 | 311 |
| 301 // Verify that the onsubmit event is dispatched upon pressing <Enter>. | 312 // Verify that the onsubmit event is dispatched upon pressing <Enter>. |
| 302 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) { | 313 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) { |
| 303 ASSERT_TRUE(test_server()->Start()); | 314 ASSERT_TRUE(test_server()->Start()); |
| 304 EnableInstant(); | 315 EnableInstant(); |
| 305 SetupInstantProvider("instant.html"); | 316 SetupInstantProvider("instant.html"); |
| 306 DetermineInstantSupport(); | 317 DetermineInstantSupport(); |
| 307 SearchAndWaitForPreviewToShow(); | 318 SearchAndWaitForPreviewToShow(); |
| 308 | 319 |
| 309 EXPECT_TRUE(preview()); | 320 EXPECT_TRUE(preview()); |
| 310 EXPECT_TRUE(instant()->is_displayable()); | 321 EXPECT_TRUE(is_showing()); |
| 311 EXPECT_TRUE(instant()->IsCurrent()); | 322 EXPECT_TRUE(instant()->IsCurrent()); |
| 312 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); | 323 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); |
| 313 | 324 |
| 314 WebContents* preview_tab = preview()->web_contents(); | 325 WebContents* preview_tab = preview()->web_contents(); |
| 315 EXPECT_TRUE(preview_tab); | 326 EXPECT_TRUE(preview_tab); |
| 316 | 327 |
| 317 ASSERT_TRUE(PressEnter()); | 328 ASSERT_TRUE(PressEnter()); |
| 318 | 329 |
| 319 // Check that the preview has been committed. | 330 // Check that the preview has been committed. |
| 320 EXPECT_FALSE(preview()); | 331 EXPECT_FALSE(preview()); |
| 321 EXPECT_FALSE(instant()->is_displayable()); | 332 EXPECT_FALSE(is_showing()); |
| 322 EXPECT_FALSE(instant()->IsCurrent()); | 333 EXPECT_FALSE(instant()->IsCurrent()); |
| 323 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); | 334 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
| 324 | 335 |
| 325 // We should have two entries. One corresponding to the page the user was | 336 // We should have two entries. One corresponding to the page the user was |
| 326 // first on, and one for the search page. | 337 // first on, and one for the search page. |
| 327 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); | 338 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
| 328 | 339 |
| 329 // Check that the value is reflected and onsubmit is called. | 340 // Check that the value is reflected and onsubmit is called. |
| 330 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", | 341 EXPECT_EQ("true 1 0 2 false d false defghi true 6 6", |
| 331 GetSearchStateAsString(preview_tab, true)); | 342 GetSearchStateAsString(preview_tab, true)); |
| 332 | 343 |
| 333 // Make sure the searchbox values were reset. | 344 // Make sure the searchbox values were reset. |
| 334 EXPECT_EQ("true 1 0 1 true d false false 0 0", | 345 EXPECT_EQ("true 1 0 2 false d false false 0 0", |
| 335 GetSearchStateAsString(preview_tab, false)); | 346 GetSearchStateAsString(preview_tab, false)); |
| 336 } | 347 } |
| 337 | 348 |
| 338 // Verify that the oncancel event is dispatched upon losing focus. | 349 // Verify that the oncancel event is dispatched upon losing focus. |
| 339 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnCancelEvent) { | 350 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnCancelEvent) { |
| 340 ASSERT_TRUE(test_server()->Start()); | 351 ASSERT_TRUE(test_server()->Start()); |
| 341 EnableInstant(); | 352 EnableInstant(); |
| 342 SetupInstantProvider("instant.html"); | 353 SetupInstantProvider("instant.html"); |
| 343 DetermineInstantSupport(); | 354 DetermineInstantSupport(); |
| 344 SearchAndWaitForPreviewToShow(); | 355 SearchAndWaitForPreviewToShow(); |
| 345 | 356 |
| 346 EXPECT_TRUE(preview()); | 357 EXPECT_TRUE(preview()); |
| 347 EXPECT_TRUE(instant()->is_displayable()); | 358 EXPECT_TRUE(is_showing()); |
| 348 EXPECT_TRUE(instant()->IsCurrent()); | 359 EXPECT_TRUE(instant()->IsCurrent()); |
| 349 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); | 360 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); |
| 350 | 361 |
| 351 WebContents* preview_tab = preview()->web_contents(); | 362 WebContents* preview_tab = preview()->web_contents(); |
| 352 EXPECT_TRUE(preview_tab); | 363 EXPECT_TRUE(preview_tab); |
| 353 | 364 |
| 354 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 365 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 355 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 366 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 356 | 367 |
| 357 // Check that the preview has been committed. | 368 // Check that the preview has been committed. |
| 358 EXPECT_FALSE(preview()); | 369 EXPECT_FALSE(preview()); |
| 359 EXPECT_FALSE(instant()->is_displayable()); | 370 EXPECT_FALSE(is_showing()); |
| 360 EXPECT_FALSE(instant()->IsCurrent()); | 371 EXPECT_FALSE(instant()->IsCurrent()); |
| 361 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); | 372 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
| 362 | 373 |
| 363 // Check that the value is reflected and oncancel is called. | 374 // Check that the value is reflected and oncancel is called. |
| 364 EXPECT_EQ("true 0 1 1 true d false def false 3 3", | 375 EXPECT_EQ("true 0 1 1 true d false def false 3 3", |
| 365 GetSearchStateAsString(preview_tab, true)); | 376 GetSearchStateAsString(preview_tab, true)); |
| 366 | 377 |
| 367 // Make sure the searchbox values were reset. | 378 // Make sure the searchbox values were reset. |
| 368 EXPECT_EQ("true 0 1 1 true d false false 0 0", | 379 EXPECT_EQ("true 0 1 1 true d false false 0 0", |
| 369 GetSearchStateAsString(preview_tab, false)); | 380 GetSearchStateAsString(preview_tab, false)); |
| 370 } | 381 } |
| 371 | 382 |
| 372 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsArrayOfStrings)) { | 383 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsArrayOfStrings)) { |
| 373 ASSERT_TRUE(test_server()->Start()); | 384 ASSERT_TRUE(test_server()->Start()); |
| 374 EnableInstant(); | 385 EnableInstant(); |
| 375 SetupInstantProvider("instant.html"); | 386 SetupInstantProvider("instant.html"); |
| 376 DetermineInstantSupport(); | 387 DetermineInstantSupport(); |
| 377 | 388 |
| 378 ASSERT_TRUE(SetSuggestionsJavascriptArgument("['defg', 'unused']")); | 389 ASSERT_TRUE(SetSuggestionsJavascriptArgument("['defg', 'unused']")); |
| 379 SearchAndWaitForPreviewToShow(); | 390 SearchAndWaitForPreviewToShow(); |
| 380 EXPECT_EQ("defg", GetSuggestion()); | 391 EXPECT_EQ(ASCIIToUTF16("defg"), last_full_text()); |
| 381 } | 392 } |
| 382 | 393 |
| 383 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyArray)) { | 394 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyArray)) { |
| 384 ASSERT_TRUE(test_server()->Start()); | 395 ASSERT_TRUE(test_server()->Start()); |
| 385 EnableInstant(); | 396 EnableInstant(); |
| 386 SetupInstantProvider("instant.html"); | 397 SetupInstantProvider("instant.html"); |
| 387 DetermineInstantSupport(); | 398 DetermineInstantSupport(); |
| 388 | 399 |
| 389 ASSERT_TRUE(SetSuggestionsJavascriptArgument("[]")); | 400 ASSERT_TRUE(SetSuggestionsJavascriptArgument("[]")); |
| 390 SearchAndWaitForPreviewToShow(); | 401 SearchAndWaitForPreviewToShow(); |
| 391 EXPECT_EQ("", GetSuggestion()); | 402 EXPECT_EQ(search_term_, last_full_text()); |
| 392 } | 403 } |
| 393 | 404 |
| 394 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsValidJson)) { | 405 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsValidJson)) { |
| 395 ASSERT_TRUE(test_server()->Start()); | 406 ASSERT_TRUE(test_server()->Start()); |
| 396 EnableInstant(); | 407 EnableInstant(); |
| 397 SetupInstantProvider("instant.html"); | 408 SetupInstantProvider("instant.html"); |
| 398 DetermineInstantSupport(); | 409 DetermineInstantSupport(); |
| 399 | 410 |
| 400 ASSERT_TRUE(SetSuggestionsJavascriptArgument( | 411 ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
| 401 "{suggestions:[{value:'defg'},{value:'unused'}]}")); | 412 "{suggestions:[{value:'defg'},{value:'unused'}]}")); |
| 402 SearchAndWaitForPreviewToShow(); | 413 SearchAndWaitForPreviewToShow(); |
| 403 EXPECT_EQ("defg", GetSuggestion()); | 414 EXPECT_EQ(ASCIIToUTF16("defg"), last_full_text()); |
| 404 } | 415 } |
| 405 | 416 |
| 406 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsInvalidSuggestions)) { | 417 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsInvalidSuggestions)) { |
| 407 ASSERT_TRUE(test_server()->Start()); | 418 ASSERT_TRUE(test_server()->Start()); |
| 408 EnableInstant(); | 419 EnableInstant(); |
| 409 SetupInstantProvider("instant.html"); | 420 SetupInstantProvider("instant.html"); |
| 410 DetermineInstantSupport(); | 421 DetermineInstantSupport(); |
| 411 | 422 |
| 412 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:{value:'defg'}}")); | 423 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:{value:'defg'}}")); |
| 413 SearchAndWaitForPreviewToShow(); | 424 SearchAndWaitForPreviewToShow(); |
| 414 EXPECT_EQ("", GetSuggestion()); | 425 EXPECT_EQ(search_term_, last_full_text()); |
| 415 } | 426 } |
| 416 | 427 |
| 417 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyJson)) { | 428 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyJson)) { |
| 418 ASSERT_TRUE(test_server()->Start()); | 429 ASSERT_TRUE(test_server()->Start()); |
| 419 EnableInstant(); | 430 EnableInstant(); |
| 420 SetupInstantProvider("instant.html"); | 431 SetupInstantProvider("instant.html"); |
| 421 DetermineInstantSupport(); | 432 DetermineInstantSupport(); |
| 422 | 433 |
| 423 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{}")); | 434 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{}")); |
| 424 SearchAndWaitForPreviewToShow(); | 435 SearchAndWaitForPreviewToShow(); |
| 425 EXPECT_EQ("", GetSuggestion()); | 436 EXPECT_EQ(search_term_, last_full_text()); |
| 426 } | 437 } |
| 427 | 438 |
| 428 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestions)) { | 439 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestions)) { |
| 429 ASSERT_TRUE(test_server()->Start()); | 440 ASSERT_TRUE(test_server()->Start()); |
| 430 EnableInstant(); | 441 EnableInstant(); |
| 431 SetupInstantProvider("instant.html"); | 442 SetupInstantProvider("instant.html"); |
| 432 DetermineInstantSupport(); | 443 DetermineInstantSupport(); |
| 433 | 444 |
| 434 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[]}")); | 445 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[]}")); |
| 435 SearchAndWaitForPreviewToShow(); | 446 SearchAndWaitForPreviewToShow(); |
| 436 EXPECT_EQ("", GetSuggestion()); | 447 EXPECT_EQ(search_term_, last_full_text()); |
| 437 } | 448 } |
| 438 | 449 |
| 439 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestion)) { | 450 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestion)) { |
| 440 ASSERT_TRUE(test_server()->Start()); | 451 ASSERT_TRUE(test_server()->Start()); |
| 441 EnableInstant(); | 452 EnableInstant(); |
| 442 SetupInstantProvider("instant.html"); | 453 SetupInstantProvider("instant.html"); |
| 443 DetermineInstantSupport(); | 454 DetermineInstantSupport(); |
| 444 | 455 |
| 445 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[{}]}")); | 456 ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[{}]}")); |
| 446 SearchAndWaitForPreviewToShow(); | 457 SearchAndWaitForPreviewToShow(); |
| 447 EXPECT_EQ("", GetSuggestion()); | 458 EXPECT_EQ(search_term_, last_full_text()); |
| 448 } | 459 } |
| 449 | 460 |
| 450 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNever)) { | 461 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNever)) { |
| 451 ASSERT_TRUE(test_server()->Start()); | 462 ASSERT_TRUE(test_server()->Start()); |
| 452 EnableInstant(); | 463 EnableInstant(); |
| 453 SetupInstantProvider("instant.html"); | 464 SetupInstantProvider("instant.html"); |
| 454 DetermineInstantSupport(); | 465 DetermineInstantSupport(); |
| 455 | 466 |
| 456 ASSERT_TRUE(SetSuggestionsJavascriptArgument( | 467 ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
| 457 "{suggestions:[{value:'defg'}],complete_behavior:'never'}")); | 468 "{suggestions:[{value:'defg'}],complete_behavior:'never'}")); |
| 458 SearchAndWaitForPreviewToShow(); | 469 SearchAndWaitForPreviewToShow(); |
| 459 EXPECT_EQ("defg", GetSuggestion()); | 470 EXPECT_EQ(search_term_, last_full_text()); |
| 460 | 471 |
| 461 EXPECT_EQ(INSTANT_COMPLETE_NEVER, | 472 EXPECT_EQ(INSTANT_COMPLETE_NEVER, |
| 462 omnibox()->model()->instant_complete_behavior()); | 473 omnibox()->model()->instant_complete_behavior()); |
| 463 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); | 474 EXPECT_EQ(search_term_, omnibox()->GetText()); |
| 464 } | 475 } |
| 465 | 476 |
| 466 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteDelayed)) { | 477 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_InstantCompleteDelayed) { |
| 467 ASSERT_TRUE(test_server()->Start()); | 478 ASSERT_TRUE(test_server()->Start()); |
| 468 EnableInstant(); | 479 EnableInstant(); |
| 469 SetupInstantProvider("instant.html"); | 480 SetupInstantProvider("instant.html"); |
| 470 DetermineInstantSupport(); | 481 DetermineInstantSupport(); |
| 471 | 482 |
| 472 ASSERT_TRUE(SetSuggestionsJavascriptArgument( | 483 ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
| 473 "{suggestions:[{value:'defg'}],complete_behavior:'delayed'}")); | 484 "{suggestions:[{value:'defg'}],complete_behavior:'delayed'}")); |
| 474 SearchAndWaitForPreviewToShow(); | 485 SearchAndWaitForPreviewToShow(); |
| 475 EXPECT_EQ("defg", GetSuggestion()); | 486 EXPECT_EQ(search_term_, last_full_text()); |
| 476 | 487 |
| 477 EXPECT_EQ(INSTANT_COMPLETE_DELAYED, | 488 EXPECT_EQ(INSTANT_COMPLETE_DELAYED, |
| 478 omnibox()->model()->instant_complete_behavior()); | 489 omnibox()->model()->instant_complete_behavior()); |
| 479 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); | 490 EXPECT_EQ(ASCIIToUTF16("defg"), omnibox()->GetText()); |
| 480 } | 491 } |
| 481 | 492 |
| 482 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNow)) { | 493 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNow)) { |
| 483 ASSERT_TRUE(test_server()->Start()); | 494 ASSERT_TRUE(test_server()->Start()); |
| 484 EnableInstant(); | 495 EnableInstant(); |
| 485 SetupInstantProvider("instant.html"); | 496 SetupInstantProvider("instant.html"); |
| 486 DetermineInstantSupport(); | 497 DetermineInstantSupport(); |
| 487 | 498 |
| 488 ASSERT_TRUE(SetSuggestionsJavascriptArgument( | 499 ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
| 489 "{suggestions:[{value:'defg'}],complete_behavior:'now'}")); | 500 "{suggestions:[{value:'defg'}],complete_behavior:'now'}")); |
| 490 SearchAndWaitForPreviewToShow(); | 501 SearchAndWaitForPreviewToShow(); |
| 491 EXPECT_EQ("defg", GetSuggestion()); | 502 EXPECT_EQ(ASCIIToUTF16("defg"), last_full_text()); |
| 492 | 503 |
| 493 EXPECT_EQ(INSTANT_COMPLETE_NOW, | 504 EXPECT_EQ(INSTANT_COMPLETE_NOW, |
| 494 omnibox()->model()->instant_complete_behavior()); | 505 omnibox()->model()->instant_complete_behavior()); |
| 495 EXPECT_EQ("defg", UTF16ToUTF8(omnibox()->GetText())); | 506 EXPECT_EQ(ASCIIToUTF16("defg"), omnibox()->GetText()); |
| 496 } | 507 } |
| 497 | 508 |
| 498 // Verifies that instant previews aren't shown for crash URLs. | 509 // Verifies that instant previews aren't shown for crash URLs. |
| 499 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(CrashUrlCancelsInstant)) { | 510 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(CrashUrlCancelsInstant)) { |
| 500 ASSERT_TRUE(test_server()->Start()); | 511 ASSERT_TRUE(test_server()->Start()); |
| 501 EnableInstant(); | 512 EnableInstant(); |
| 502 SetupInstantProvider("instant.html"); | 513 SetupInstantProvider("instant.html"); |
| 503 | 514 |
| 504 omnibox()->SetUserText(ASCIIToUTF16(chrome::kChromeUICrashURL)); | 515 SetOmniboxFocusAndUserText(ASCIIToUTF16(chrome::kChromeUICrashURL)); |
| 505 EXPECT_FALSE(preview()); | 516 EXPECT_FALSE(preview()); |
| 506 } | 517 } |
| 507 | 518 |
| 508 // Tests that instant doesn't fire for intranet paths that look like searches. | 519 // Tests that instant doesn't fire for intranet paths that look like searches. |
| 509 // http://crbug.com/99836 | 520 // http://crbug.com/99836 |
| 510 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(IntranetPathLooksLikeSearch)) { | 521 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(IntranetPathLooksLikeSearch)) { |
| 511 ASSERT_TRUE(test_server()->Start()); | 522 ASSERT_TRUE(test_server()->Start()); |
| 512 EnableInstant(); | 523 EnableInstant(); |
| 513 SetupInstantProvider("instant.html"); | 524 SetupInstantProvider("instant.html"); |
| 514 | 525 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 525 EXPECT_FALSE(preview()); | 536 EXPECT_FALSE(preview()); |
| 526 } | 537 } |
| 527 | 538 |
| 528 // Verifies that instant previews aren't shown for non-search URLs. | 539 // Verifies that instant previews aren't shown for non-search URLs. |
| 529 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ShowPreviewNonSearch)) { | 540 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ShowPreviewNonSearch)) { |
| 530 ASSERT_TRUE(test_server()->Start()); | 541 ASSERT_TRUE(test_server()->Start()); |
| 531 EnableInstant(); | 542 EnableInstant(); |
| 532 SetupInstantProvider("instant.html"); | 543 SetupInstantProvider("instant.html"); |
| 533 | 544 |
| 534 GURL url(test_server()->GetURL("files/empty.html")); | 545 GURL url(test_server()->GetURL("files/empty.html")); |
| 535 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 546 SetOmniboxFocusAndUserText(UTF8ToUTF16(url.spec())); |
| 536 EXPECT_FALSE(preview()); | 547 EXPECT_FALSE(preview()); |
| 537 } | 548 } |
| 538 | 549 |
| 539 // Transition from non-search to search and make sure everything works. | 550 // Transition from non-search to search and make sure everything works. |
| 540 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(NonSearchToSearch)) { | 551 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(NonSearchToSearch)) { |
| 541 ASSERT_TRUE(test_server()->Start()); | 552 ASSERT_TRUE(test_server()->Start()); |
| 542 EnableInstant(); | 553 EnableInstant(); |
| 543 SetupInstantProvider("instant.html"); | 554 SetupInstantProvider("instant.html"); |
| 544 | 555 |
| 545 // Load a non-search URL. | 556 // Load a non-search URL. |
| 546 GURL url(test_server()->GetURL("files/empty.html")); | 557 GURL url(test_server()->GetURL("files/empty.html")); |
| 547 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 558 SetOmniboxFocusAndUserText(UTF8ToUTF16(url.spec())); |
| 548 EXPECT_FALSE(preview()); | 559 EXPECT_FALSE(preview()); |
| 549 | 560 |
| 550 // Now type in some search text. | 561 // Now type in some search text. |
| 551 DetermineInstantSupport(); | 562 DetermineInstantSupport(); |
| 552 | 563 |
| 553 // We should now have a preview, but it shouldn't be showing yet, because we | 564 // We should now have a preview, but it shouldn't be showing yet, because we |
| 554 // haven't gotten back suggestions. | 565 // haven't gotten back suggestions. |
| 555 EXPECT_TRUE(preview()); | 566 EXPECT_TRUE(preview()); |
| 556 EXPECT_FALSE(loader()->ready()); | 567 EXPECT_FALSE(is_showing()); |
| 557 EXPECT_FALSE(instant()->is_displayable()); | 568 EXPECT_TRUE(instant()->IsCurrent()); |
| 558 EXPECT_FALSE(instant()->IsCurrent()); | |
| 559 | 569 |
| 560 // Reset the user text so that the page is told the text changed. | 570 // Reset the user text so that the page is told the text changed. |
| 561 // | 571 // |
| 562 // Typing into the omnibox sends onchange() to the page, which responds with | 572 // Typing into the omnibox sends onchange() to the page, which responds with |
| 563 // suggestions, which causes the preview to be shown. However, when we called | 573 // suggestions, which causes the preview to be shown. However, when we called |
| 564 // DetermineInstantSupport(), the resulting onchange was dropped on the floor | 574 // DetermineInstantSupport(), the resulting onchange was dropped on the floor |
| 565 // because the page wasn't loaded yet. This is fine (the user may type before | 575 // because the page wasn't loaded yet. This is fine (the user may type before |
| 566 // the page loads too). To handle this, we explicitly call onchange after the | 576 // the page loads too). To handle this, we explicitly call onchange after the |
| 567 // page loads (see initScript in searchbox_extension.cc). The search provider | 577 // page loads (see initScript in searchbox_extension.cc). The search provider |
| 568 // used in this test (instant.html) doesn't support initScript, so we have to | 578 // used in this test (instant.html) doesn't support initScript, so we have to |
| 569 // trigger an onchange ourselves. | 579 // trigger an onchange ourselves. |
| 570 SearchAndWaitForPreviewToShow(); | 580 SearchAndWaitForPreviewToShow(); |
| 571 | 581 |
| 572 // We should now be showing the preview. | 582 // We should now be showing the preview. |
| 573 EXPECT_TRUE(preview()); | 583 EXPECT_TRUE(preview()); |
| 574 EXPECT_TRUE(loader()->ready()); | 584 EXPECT_TRUE(is_showing()); |
| 575 EXPECT_TRUE(instant()->is_displayable()); | |
| 576 EXPECT_TRUE(instant()->IsCurrent()); | 585 EXPECT_TRUE(instant()->IsCurrent()); |
| 577 | 586 |
| 578 content::RenderWidgetHostView* rwhv = | 587 content::RenderWidgetHostView* rwhv = |
| 579 preview()->web_contents()->GetRenderWidgetHostView(); | 588 preview()->web_contents()->GetRenderWidgetHostView(); |
| 580 EXPECT_TRUE(rwhv); | 589 EXPECT_TRUE(rwhv); |
| 581 EXPECT_TRUE(rwhv->IsShowing()); | 590 EXPECT_TRUE(rwhv->IsShowing()); |
| 582 } | 591 } |
| 583 | 592 |
| 584 // Transition from search to non-search and make sure instant isn't displayable. | 593 // Transition from search to non-search and make sure instant isn't displayable. |
| 585 // See bug http://crbug.com/100368 for details. | 594 // See bug http://crbug.com/100368 for details. |
| 586 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { | 595 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { |
| 587 ASSERT_TRUE(test_server()->Start()); | 596 ASSERT_TRUE(test_server()->Start()); |
| 588 EnableInstant(); | 597 EnableInstant(); |
| 589 SetupInstantProvider("instant.html"); | 598 SetupInstantProvider("instant.html"); |
| 590 | 599 |
| 591 content::WindowedNotificationObserver instant_support_observer( | 600 content::WindowedNotificationObserver instant_support_observer( |
| 592 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 601 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 593 content::NotificationService::AllSources()); | 602 content::NotificationService::AllSources()); |
| 594 | 603 |
| 595 // Type in some search text. | 604 // Type in some search text. |
| 596 omnibox()->SetUserText(ASCIIToUTF16("def")); | 605 SetOmniboxFocusAndUserText(search_term_); |
| 597 | 606 |
| 598 // Load a non search URL. Don't wait for the preview to navigate. It'll still | 607 // Load a non search URL. Don't wait for the preview to navigate. It'll still |
| 599 // end up loading in the background. | 608 // end up loading in the background. |
| 600 GURL url(test_server()->GetURL("files/empty.html")); | 609 GURL url(test_server()->GetURL("files/empty.html")); |
| 601 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 610 SetOmniboxFocusAndUserText(UTF8ToUTF16(url.spec())); |
| 602 | 611 |
| 603 instant_support_observer.Wait(); | 612 instant_support_observer.Wait(); |
| 604 | 613 |
| 605 // We should now have a preview, but it shouldn't be showing yet. | 614 // We should now have a preview, but it shouldn't be showing yet. |
| 606 EXPECT_TRUE(preview()); | 615 EXPECT_TRUE(preview()); |
| 607 EXPECT_FALSE(loader()->ready()); | 616 EXPECT_FALSE(is_showing()); |
| 608 EXPECT_FALSE(instant()->is_displayable()); | |
| 609 EXPECT_FALSE(instant()->IsCurrent()); | 617 EXPECT_FALSE(instant()->IsCurrent()); |
| 610 | 618 |
| 611 // Send onchange so that the page sends up suggestions. See the comments in | 619 // Send onchange so that the page sends up suggestions. See the comments in |
| 612 // NonSearchToSearch for why this is needed. | 620 // NonSearchToSearch for why this is needed. |
| 613 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 621 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 614 preview()->web_contents()->GetRenderViewHost(), std::wstring(), | 622 preview()->web_contents()->GetRenderViewHost(), std::wstring(), |
| 615 L"window.chrome.searchBox.onchange();")); | 623 L"window.chrome.searchBox.onchange();")); |
| 616 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); | 624 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); |
| 617 | 625 |
| 618 // Instant should be active, but not displaying. | 626 // Instant should be active, but not displaying. |
| 619 EXPECT_TRUE(preview()); | 627 EXPECT_TRUE(preview()); |
| 620 EXPECT_TRUE(loader()->ready()); | 628 EXPECT_FALSE(is_showing()); |
| 621 EXPECT_FALSE(instant()->is_displayable()); | |
| 622 EXPECT_FALSE(instant()->IsCurrent()); | 629 EXPECT_FALSE(instant()->IsCurrent()); |
| 623 } | 630 } |
| 624 | 631 |
| 625 // Makes sure that if the server doesn't support the instant API we don't show | 632 // Makes sure that if the server doesn't support the instant API we don't show |
| 626 // anything. | 633 // anything. |
| 627 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) { | 634 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) { |
| 628 ASSERT_TRUE(test_server()->Start()); | 635 ASSERT_TRUE(test_server()->Start()); |
| 629 EnableInstant(); | 636 EnableInstant(); |
| 630 SetupInstantProvider("empty.html"); | 637 SetupInstantProvider("empty.html"); |
| 631 | 638 |
| 632 content::WindowedNotificationObserver tab_closed_observer( | 639 content::WindowedNotificationObserver tab_closed_observer( |
| 633 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 640 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 634 content::NotificationService::AllSources()); | 641 content::NotificationService::AllSources()); |
| 635 | 642 |
| 636 omnibox()->SetUserText(ASCIIToUTF16("d")); | 643 SetOmniboxFocusAndUserText(ASCIIToUTF16("d")); |
| 637 EXPECT_TRUE(preview()); | 644 EXPECT_TRUE(preview()); |
| 638 | 645 |
| 639 // When the response comes back that the page doesn't support instant the tab | 646 // When the response comes back that the page doesn't support instant the tab |
| 640 // should be closed. | 647 // should be closed. |
| 641 tab_closed_observer.Wait(); | 648 tab_closed_observer.Wait(); |
| 642 EXPECT_FALSE(preview()); | 649 EXPECT_FALSE(preview()); |
| 643 } | 650 } |
| 644 | 651 |
| 645 // Verifies transitioning from loading a non-search string to a search string | 652 // Verifies transitioning from loading a non-search string to a search string |
| 646 // with the provider not supporting instant works (meaning we don't display | 653 // with the provider not supporting instant works (meaning we don't display |
| 647 // anything). | 654 // anything). |
| 648 IN_PROC_BROWSER_TEST_F(InstantTest, | 655 IN_PROC_BROWSER_TEST_F(InstantTest, |
| 649 MAYBE(NonSearchToSearchDoesntSupportInstant)) { | 656 MAYBE(NonSearchToSearchDoesntSupportInstant)) { |
| 650 ASSERT_TRUE(test_server()->Start()); | 657 ASSERT_TRUE(test_server()->Start()); |
| 651 EnableInstant(); | 658 EnableInstant(); |
| 652 SetupInstantProvider("empty.html"); | 659 SetupInstantProvider("empty.html"); |
| 653 | 660 |
| 654 GURL url(test_server()->GetURL("files/empty.html")); | 661 GURL url(test_server()->GetURL("files/empty.html")); |
| 655 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 662 SetOmniboxFocusAndUserText(UTF8ToUTF16(url.spec())); |
| 656 EXPECT_FALSE(preview()); | 663 EXPECT_FALSE(preview()); |
| 657 | 664 |
| 658 content::WindowedNotificationObserver tab_closed_observer( | 665 content::WindowedNotificationObserver tab_closed_observer( |
| 659 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 666 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 660 content::NotificationService::AllSources()); | 667 content::NotificationService::AllSources()); |
| 661 | 668 |
| 662 // Now type in some search text. | 669 // Now type in some search text. |
| 663 omnibox()->SetUserText(ASCIIToUTF16("d")); | 670 SetOmniboxFocusAndUserText(ASCIIToUTF16("d")); |
| 664 EXPECT_TRUE(preview()); | 671 EXPECT_TRUE(preview()); |
| 665 | 672 |
| 666 // When the response comes back that the page doesn't support instant the tab | 673 // When the response comes back that the page doesn't support instant the tab |
| 667 // should be closed. | 674 // should be closed. |
| 668 tab_closed_observer.Wait(); | 675 tab_closed_observer.Wait(); |
| 669 EXPECT_FALSE(preview()); | 676 EXPECT_FALSE(preview()); |
| 670 } | 677 } |
| 671 | 678 |
| 672 // Verifies the page was told a non-zero height. | 679 // Verifies the page was told a non-zero height. |
| 673 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ValidHeight)) { | 680 // TODO(dominich): This seems to be a dumb test. Confirm that it's dumb. |
| 681 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_ValidHeight) { | |
| 674 ASSERT_TRUE(test_server()->Start()); | 682 ASSERT_TRUE(test_server()->Start()); |
| 675 EnableInstant(); | 683 EnableInstant(); |
| 676 SetupInstantProvider("instant.html"); | 684 SetupInstantProvider("instant.html"); |
| 677 DetermineInstantSupport(); | 685 DetermineInstantSupport(); |
| 678 SearchAndWaitForPreviewToShow(); | 686 SearchAndWaitForPreviewToShow(); |
| 679 | 687 |
| 680 int height = -1; | 688 int height = -1; |
| 681 | 689 |
| 682 // searchBox height is not yet set during initial load. | 690 // searchBox height is not yet set during initial load. |
| 683 ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(), | 691 ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 707 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) { | 715 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) { |
| 708 ASSERT_TRUE(test_server()->Start()); | 716 ASSERT_TRUE(test_server()->Start()); |
| 709 EnableInstant(); | 717 EnableInstant(); |
| 710 SetupInstantProvider("instant.html"); | 718 SetupInstantProvider("instant.html"); |
| 711 DetermineInstantSupport(); | 719 DetermineInstantSupport(); |
| 712 SearchAndWaitForPreviewToShow(); | 720 SearchAndWaitForPreviewToShow(); |
| 713 | 721 |
| 714 std::string value; | 722 std::string value; |
| 715 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), | 723 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), |
| 716 "window.chrome.searchBox.value", &value)); | 724 "window.chrome.searchBox.value", &value)); |
| 717 EXPECT_EQ("def", value); | 725 EXPECT_EQ(search_term_, UTF8ToUTF16(value)); |
| 718 | 726 |
| 719 // Commit the preview. | 727 // Commit the preview. |
| 720 ASSERT_TRUE(PressEnter()); | 728 ASSERT_TRUE(PressEnter()); |
| 721 EXPECT_FALSE(preview()); | 729 EXPECT_FALSE(preview()); |
| 722 | 730 |
| 723 // The searchBox actually gets cleared on commit. | 731 // The searchBox actually gets cleared on commit. |
| 724 ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), | 732 ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), |
| 725 "window.chrome.searchBox.value", &value)); | 733 "window.chrome.searchBox.value", &value)); |
| 726 EXPECT_EQ("", value); | 734 EXPECT_EQ("", value); |
| 727 | 735 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 758 | 766 |
| 759 // Focusing the omnibox should cause instant to be preloaded. | 767 // Focusing the omnibox should cause instant to be preloaded. |
| 760 content::WindowedNotificationObserver instant_support_observer( | 768 content::WindowedNotificationObserver instant_support_observer( |
| 761 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 769 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 762 content::NotificationService::AllSources()); | 770 content::NotificationService::AllSources()); |
| 763 browser()->window()->GetLocationBar()->FocusLocation(false); | 771 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 764 instant_support_observer.Wait(); | 772 instant_support_observer.Wait(); |
| 765 | 773 |
| 766 // Instant should have a preview, but not display it. | 774 // Instant should have a preview, but not display it. |
| 767 EXPECT_TRUE(preview()); | 775 EXPECT_TRUE(preview()); |
| 768 EXPECT_FALSE(instant()->is_displayable()); | 776 EXPECT_FALSE(is_showing()); |
| 769 EXPECT_FALSE(instant()->IsCurrent()); | 777 EXPECT_FALSE(instant()->IsCurrent()); |
| 770 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); | 778 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); |
| 771 | 779 |
| 772 // Adding a new tab shouldn't delete (or recreate) the TabContents. | 780 // Adding a new tab shouldn't delete (or recreate) the TabContents. |
| 773 TabContents* preview_tab = preview(); | 781 TabContents* preview_tab = preview(); |
| 774 AddBlankTabAndShow(browser()); | 782 AddBlankTabAndShow(browser()); |
| 775 EXPECT_EQ(preview_tab, preview()); | 783 EXPECT_EQ(preview_tab, preview()); |
| 776 | 784 |
| 777 // Doing a search should still use the same loader for the preview. | 785 // Doing a search should still use the same loader for the preview. |
| 778 SearchAndWaitForPreviewToShow(); | 786 SearchAndWaitForPreviewToShow(); |
| 779 EXPECT_EQ(preview_tab, preview()); | 787 EXPECT_EQ(preview_tab, preview()); |
| 780 | 788 |
| 781 // Verify that the preview is in fact showing instant search. | 789 // Verify that the preview is in fact showing instant search. |
| 782 EXPECT_TRUE(instant()->is_displayable()); | 790 EXPECT_TRUE(is_showing()); |
| 783 EXPECT_TRUE(instant()->IsCurrent()); | 791 EXPECT_TRUE(instant()->IsCurrent()); |
| 784 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true)); | 792 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true)); |
| 785 } | 793 } |
| 786 | 794 |
| 787 // Tests that the instant search page's visibility is set correctly. | 795 // Tests that the instant search page's visibility is set correctly. |
| 788 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { | 796 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { |
| 789 ASSERT_TRUE(test_server()->Start()); | 797 ASSERT_TRUE(test_server()->Start()); |
| 790 EnableInstant(); | 798 EnableInstant(); |
| 791 SetupInstantProvider("instant.html"); | 799 SetupInstantProvider("instant.html"); |
| 792 | 800 |
| 793 // Initially navigate to the empty page which should be visible. | 801 // Initially navigate to the empty page which should be visible. |
| 794 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); | 802 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); |
| 795 WebContents* initial_contents = chrome::GetActiveWebContents(browser()); | 803 WebContents* initial_contents = chrome::GetActiveWebContents(browser()); |
| 796 | 804 |
| 797 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 805 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
| 798 | 806 |
| 799 // Type a search term and wait for the preview to appear. | 807 // Type a search term and wait for the preview to appear. |
| 800 browser()->window()->GetLocationBar()->FocusLocation(false); | 808 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 801 DetermineInstantSupport(); | 809 DetermineInstantSupport(); |
| 802 SearchAndWaitForPreviewToShow(); | 810 SearchAndWaitForPreviewToShow(); |
| 803 WebContents* preview_contents = preview()->web_contents(); | 811 WebContents* preview_contents = preview()->web_contents(); |
| 804 | 812 |
| 805 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 813 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 806 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 814 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
| 807 | 815 |
| 808 // Deleting the user text should hide the preview. | 816 // Deleting the user text should hide the preview. |
| 809 omnibox()->SetUserText(string16()); | 817 SetOmniboxFocusAndUserText(string16()); |
| 810 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); | 818 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); |
| 811 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 819 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
| 812 | 820 |
| 813 // Set the user text back and we should see the preview again. | 821 // Set the user text back and we should see the preview again. |
| 814 omnibox()->SetUserText(ASCIIToUTF16("def")); | 822 // TODO(dominich): This bit is not working. Copy-pasting allows us to see this |
| 823 // in Chrome too. | |
|
sky
2012/07/25 17:29:56
This comment doesn't make sense to me, but I'm ass
jered1
2012/07/25 20:22:04
I've deleted the comment. Sreeram will just fix th
| |
| 824 SetOmniboxFocusAndUserText(ASCIIToUTF16("def")); | |
| 815 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 825 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 816 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 826 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
| 817 | 827 |
| 818 // Commit the preview. | 828 // Commit the preview. |
| 819 ASSERT_TRUE(PressEnter()); | 829 ASSERT_TRUE(PressEnter()); |
| 820 EXPECT_EQ(preview_contents, chrome::GetActiveWebContents(browser())); | 830 EXPECT_EQ(preview_contents, chrome::GetActiveWebContents(browser())); |
| 821 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 831 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 822 } | 832 } |
| 823 | 833 |
| 824 // Tests that the task manager identifies instant's preview tab correctly. | 834 // Tests that the task manager identifies instant's preview tab correctly. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 835 DetermineInstantSupport(); | 845 DetermineInstantSupport(); |
| 836 SearchAndWaitForPreviewToShow(); | 846 SearchAndWaitForPreviewToShow(); |
| 837 | 847 |
| 838 // Now there should be three rows, the third being the instant preview. | 848 // Now there should be three rows, the third being the instant preview. |
| 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 849 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 840 string16 prefix = l10n_util::GetStringFUTF16( | 850 string16 prefix = l10n_util::GetStringFUTF16( |
| 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 851 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
| 842 string16 title = task_manager->GetResourceTitle(2); | 852 string16 title = task_manager->GetResourceTitle(2); |
| 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 853 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 844 } | 854 } |
| OLD | NEW |