| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ASSERT_TRUE(location_bar_); | 72 ASSERT_TRUE(location_bar_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TabContentsWrapper* GetPendingPreviewContents() { | 75 TabContentsWrapper* GetPendingPreviewContents() { |
| 76 return browser()->instant()->GetPendingPreviewContents(); | 76 return browser()->instant()->GetPendingPreviewContents(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Type a character to get instant to trigger. | 79 // Type a character to get instant to trigger. |
| 80 void SetupLocationBar() { | 80 void SetupLocationBar() { |
| 81 FindLocationBar(); | 81 FindLocationBar(); |
| 82 location_bar_->location_entry()->SetUserText(L"a"); | 82 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Waits for preview to be shown. | 85 // Waits for preview to be shown. |
| 86 void WaitForPreviewToNavigate(bool use_current) { | 86 void WaitForPreviewToNavigate(bool use_current) { |
| 87 InstantController* instant = browser()->instant(); | 87 InstantController* instant = browser()->instant(); |
| 88 ASSERT_TRUE(instant); | 88 ASSERT_TRUE(instant); |
| 89 TabContentsWrapper* tab = use_current ? | 89 TabContentsWrapper* tab = use_current ? |
| 90 instant->GetPreviewContents() : GetPendingPreviewContents(); | 90 instant->GetPreviewContents() : GetPendingPreviewContents(); |
| 91 ASSERT_TRUE(tab); | 91 ASSERT_TRUE(tab); |
| 92 preview_ = tab->tab_contents(); | 92 preview_ = tab->tab_contents(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 ASSERT_TRUE(browser()->instant()->is_active()); | 104 ASSERT_TRUE(browser()->instant()->is_active()); |
| 105 | 105 |
| 106 // When the page loads, the initial searchBox values are set and only a | 106 // When the page loads, the initial searchBox values are set and only a |
| 107 // resize will have been sent. | 107 // resize will have been sent. |
| 108 ASSERT_EQ("true 0 0 0 1 a false a false 1 1", | 108 ASSERT_EQ("true 0 0 0 1 a false a false 1 1", |
| 109 GetSearchStateAsString(preview_)); | 109 GetSearchStateAsString(preview_)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void SetLocationBarText(const std::wstring& text) { | 112 void SetLocationBarText(const std::wstring& text) { |
| 113 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 113 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 114 location_bar_->location_entry()->SetUserText(text); | 114 location_bar_->location_entry()->SetUserText(WideToUTF16Hack(text)); |
| 115 ui_test_utils::WaitForNotification( | 115 ui_test_utils::WaitForNotification( |
| 116 NotificationType::INSTANT_CONTROLLER_SHOWN); | 116 NotificationType::INSTANT_CONTROLLER_SHOWN); |
| 117 } | 117 } |
| 118 | 118 |
| 119 const string16& GetSuggestion() const { | 119 const string16& GetSuggestion() const { |
| 120 return browser()->instant()->loader_manager_-> | 120 return browser()->instant()->loader_manager_-> |
| 121 current_loader()->complete_suggested_text_; | 121 current_loader()->complete_suggested_text_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void SendKey(ui::KeyboardCode key) { | 124 void SendKey(ui::KeyboardCode key) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 ASSERT_TRUE(browser()->instant()->is_displayable()); | 406 ASSERT_TRUE(browser()->instant()->is_displayable()); |
| 407 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); | 407 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); |
| 408 ASSERT_TRUE(initial_tab); | 408 ASSERT_TRUE(initial_tab); |
| 409 RenderWidgetHostView* rwhv = | 409 RenderWidgetHostView* rwhv = |
| 410 initial_tab->tab_contents()->GetRenderWidgetHostView(); | 410 initial_tab->tab_contents()->GetRenderWidgetHostView(); |
| 411 ASSERT_TRUE(rwhv); | 411 ASSERT_TRUE(rwhv); |
| 412 ASSERT_TRUE(rwhv->IsShowing()); | 412 ASSERT_TRUE(rwhv->IsShowing()); |
| 413 | 413 |
| 414 // Now type in some search text. | 414 // Now type in some search text. |
| 415 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 415 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
| 416 location_bar_->location_entry()->SetUserText(L"abc"); | 416 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("abc")); |
| 417 | 417 |
| 418 // Wait for the preview to navigate. | 418 // Wait for the preview to navigate. |
| 419 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(false)); | 419 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(false)); |
| 420 | 420 |
| 421 // The controller is still determining if the provider really supports | 421 // The controller is still determining if the provider really supports |
| 422 // instant. As a result the tabcontents should not have changed. | 422 // instant. As a result the tabcontents should not have changed. |
| 423 TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents(); | 423 TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents(); |
| 424 ASSERT_EQ(current_tab, initial_tab); | 424 ASSERT_EQ(current_tab, initial_tab); |
| 425 // The preview should still be showing. | 425 // The preview should still be showing. |
| 426 rwhv = current_tab->tab_contents()->GetRenderWidgetHostView(); | 426 rwhv = current_tab->tab_contents()->GetRenderWidgetHostView(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 438 // Because we're waiting on the page, instant isn't current. | 438 // Because we're waiting on the page, instant isn't current. |
| 439 ASSERT_FALSE(browser()->instant()->IsCurrent()); | 439 ASSERT_FALSE(browser()->instant()->IsCurrent()); |
| 440 | 440 |
| 441 // Bounce a message to the renderer so that we know the instant has gotten a | 441 // Bounce a message to the renderer so that we know the instant has gotten a |
| 442 // response back from the renderer as to whether the page supports instant. | 442 // response back from the renderer as to whether the page supports instant. |
| 443 ASSERT_NO_FATAL_FAILURE( | 443 ASSERT_NO_FATAL_FAILURE( |
| 444 WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); | 444 WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); |
| 445 | 445 |
| 446 // Reset the user text so that the page is told the text changed. We should be | 446 // Reset the user text so that the page is told the text changed. We should be |
| 447 // able to nuke this once 66104 is fixed. | 447 // able to nuke this once 66104 is fixed. |
| 448 location_bar_->location_entry()->SetUserText(L"abcd"); | 448 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("abcd")); |
| 449 | 449 |
| 450 // Wait for the renderer to process it. | 450 // Wait for the renderer to process it. |
| 451 ASSERT_NO_FATAL_FAILURE( | 451 ASSERT_NO_FATAL_FAILURE( |
| 452 WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); | 452 WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); |
| 453 | 453 |
| 454 // We should have gotten a response back from the renderer that resulted in | 454 // We should have gotten a response back from the renderer that resulted in |
| 455 // committing. | 455 // committing. |
| 456 ASSERT_FALSE(GetPendingPreviewContents()); | 456 ASSERT_FALSE(GetPendingPreviewContents()); |
| 457 ASSERT_TRUE(browser()->instant()->is_active()); | 457 ASSERT_TRUE(browser()->instant()->is_active()); |
| 458 ASSERT_TRUE(browser()->instant()->is_displayable()); | 458 ASSERT_TRUE(browser()->instant()->is_displayable()); |
| 459 TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents(); | 459 TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents(); |
| 460 ASSERT_TRUE(new_tab); | 460 ASSERT_TRUE(new_tab); |
| 461 ASSERT_NE(new_tab, initial_tab); | 461 ASSERT_NE(new_tab, initial_tab); |
| 462 RenderWidgetHostView* new_rwhv = | 462 RenderWidgetHostView* new_rwhv = |
| 463 new_tab->tab_contents()->GetRenderWidgetHostView(); | 463 new_tab->tab_contents()->GetRenderWidgetHostView(); |
| 464 ASSERT_TRUE(new_rwhv); | 464 ASSERT_TRUE(new_rwhv); |
| 465 ASSERT_NE(new_rwhv, rwhv); | 465 ASSERT_NE(new_rwhv, rwhv); |
| 466 ASSERT_TRUE(new_rwhv->IsShowing()); | 466 ASSERT_TRUE(new_rwhv->IsShowing()); |
| 467 } | 467 } |
| 468 | 468 |
| 469 // Makes sure that if the server doesn't support the instant API we don't show | 469 // Makes sure that if the server doesn't support the instant API we don't show |
| 470 // anything. | 470 // anything. |
| 471 IN_PROC_BROWSER_TEST_F(InstantTest, SearchServerDoesntSupportInstant) { | 471 IN_PROC_BROWSER_TEST_F(InstantTest, SearchServerDoesntSupportInstant) { |
| 472 ASSERT_TRUE(test_server()->Start()); | 472 ASSERT_TRUE(test_server()->Start()); |
| 473 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); | 473 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
| 474 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 474 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 475 location_bar_->location_entry()->SetUserText(L"a"); | 475 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); |
| 476 ASSERT_TRUE(browser()->instant()); | 476 ASSERT_TRUE(browser()->instant()); |
| 477 // Because we typed in a search string we should think we're showing instant | 477 // Because we typed in a search string we should think we're showing instant |
| 478 // results. | 478 // results. |
| 479 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); | 479 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); |
| 480 // But because we're waiting to determine if the page really supports instant | 480 // But because we're waiting to determine if the page really supports instant |
| 481 // we shouldn't be showing the preview. | 481 // we shouldn't be showing the preview. |
| 482 EXPECT_FALSE(browser()->instant()->is_displayable()); | 482 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 483 // But instant should still be active. | 483 // But instant should still be active. |
| 484 EXPECT_TRUE(browser()->instant()->is_active()); | 484 EXPECT_TRUE(browser()->instant()->is_active()); |
| 485 | 485 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 504 ASSERT_TRUE(browser()->instant()->is_displayable()); | 504 ASSERT_TRUE(browser()->instant()->is_displayable()); |
| 505 ASSERT_TRUE(browser()->instant()->is_active()); | 505 ASSERT_TRUE(browser()->instant()->is_active()); |
| 506 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); | 506 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); |
| 507 ASSERT_TRUE(initial_tab); | 507 ASSERT_TRUE(initial_tab); |
| 508 RenderWidgetHostView* rwhv = | 508 RenderWidgetHostView* rwhv = |
| 509 initial_tab->tab_contents()->GetRenderWidgetHostView(); | 509 initial_tab->tab_contents()->GetRenderWidgetHostView(); |
| 510 ASSERT_TRUE(rwhv); | 510 ASSERT_TRUE(rwhv); |
| 511 ASSERT_TRUE(rwhv->IsShowing()); | 511 ASSERT_TRUE(rwhv->IsShowing()); |
| 512 | 512 |
| 513 // Now type in some search text. | 513 // Now type in some search text. |
| 514 location_bar_->location_entry()->SetUserText(L"a"); | 514 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); |
| 515 | 515 |
| 516 // Instant should still be live. | 516 // Instant should still be live. |
| 517 ASSERT_TRUE(browser()->instant()->is_displayable()); | 517 ASSERT_TRUE(browser()->instant()->is_displayable()); |
| 518 ASSERT_TRUE(browser()->instant()->is_active()); | 518 ASSERT_TRUE(browser()->instant()->is_active()); |
| 519 // Because we typed in a search string we should think we're showing instant | 519 // Because we typed in a search string we should think we're showing instant |
| 520 // results. | 520 // results. |
| 521 EXPECT_TRUE(browser()->instant()->MightSupportInstant()); | 521 EXPECT_TRUE(browser()->instant()->MightSupportInstant()); |
| 522 // Instant should not be current (it's still loading). | 522 // Instant should not be current (it's still loading). |
| 523 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 523 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 524 | 524 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 554 &height)); | 554 &height)); |
| 555 EXPECT_GT(height, 0); | 555 EXPECT_GT(height, 0); |
| 556 } | 556 } |
| 557 | 557 |
| 558 // Verifies that if the server returns a 403 we don't show the preview and | 558 // Verifies that if the server returns a 403 we don't show the preview and |
| 559 // query the host again. | 559 // query the host again. |
| 560 IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { | 560 IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { |
| 561 ASSERT_TRUE(test_server()->Start()); | 561 ASSERT_TRUE(test_server()->Start()); |
| 562 GURL url(test_server()->GetURL("files/instant/403.html")); | 562 GURL url(test_server()->GetURL("files/instant/403.html")); |
| 563 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 563 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 564 location_bar_->location_entry()->SetUserText(UTF8ToWide(url.spec())); | 564 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
| 565 // The preview shouldn't be showing, but it should be loading. | 565 // The preview shouldn't be showing, but it should be loading. |
| 566 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); | 566 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); |
| 567 ASSERT_TRUE(browser()->instant()->is_active()); | 567 ASSERT_TRUE(browser()->instant()->is_active()); |
| 568 ASSERT_FALSE(browser()->instant()->is_displayable()); | 568 ASSERT_FALSE(browser()->instant()->is_displayable()); |
| 569 | 569 |
| 570 // When instant sees the 403, it should close the tab. | 570 // When instant sees the 403, it should close the tab. |
| 571 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 571 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); |
| 572 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 572 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
| 573 ASSERT_TRUE(browser()->instant()->is_active()); | 573 ASSERT_TRUE(browser()->instant()->is_active()); |
| 574 ASSERT_FALSE(browser()->instant()->is_displayable()); | 574 ASSERT_FALSE(browser()->instant()->is_displayable()); |
| 575 | 575 |
| 576 // Try loading another url on the server. Instant shouldn't create a new tab | 576 // Try loading another url on the server. Instant shouldn't create a new tab |
| 577 // as the server returned 403. | 577 // as the server returned 403. |
| 578 GURL url2(test_server()->GetURL("files/instant/empty.html")); | 578 GURL url2(test_server()->GetURL("files/instant/empty.html")); |
| 579 location_bar_->location_entry()->SetUserText(UTF8ToWide(url2.spec())); | 579 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); |
| 580 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 580 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
| 581 ASSERT_TRUE(browser()->instant()->is_active()); | 581 ASSERT_TRUE(browser()->instant()->is_active()); |
| 582 ASSERT_FALSE(browser()->instant()->is_displayable()); | 582 ASSERT_FALSE(browser()->instant()->is_displayable()); |
| 583 } | 583 } |
| 584 | 584 |
| 585 // Verify that the onsubmit event is dispatched upon pressing enter. | 585 // Verify that the onsubmit event is dispatched upon pressing enter. |
| 586 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { | 586 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
| 587 ASSERT_TRUE(test_server()->Start()); | 587 ASSERT_TRUE(test_server()->Start()); |
| 588 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 588 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
| 589 | 589 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 641 |
| 642 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 642 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 643 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 643 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
| 644 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 644 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
| 645 | 645 |
| 646 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 646 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
| 647 | 647 |
| 648 // Pressing tab to convert instant suggest into inline autocomplete. | 648 // Pressing tab to convert instant suggest into inline autocomplete. |
| 649 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 649 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
| 650 | 650 |
| 651 ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); | 651 ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText()); |
| 652 | 652 |
| 653 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", | 653 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", |
| 654 GetSearchStateAsString(preview_)); | 654 GetSearchStateAsString(preview_)); |
| 655 | 655 |
| 656 // Pressing tab again to accept the current instant preview. | 656 // Pressing tab again to accept the current instant preview. |
| 657 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 657 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
| 658 | 658 |
| 659 // Check that the preview contents have been committed. | 659 // Check that the preview contents have been committed. |
| 660 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 660 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
| 661 ASSERT_FALSE(browser()->instant()->is_active()); | 661 ASSERT_FALSE(browser()->instant()->is_active()); |
| 662 TabContents* contents = browser()->GetSelectedTabContents(); | 662 TabContents* contents = browser()->GetSelectedTabContents(); |
| 663 ASSERT_TRUE(contents); | 663 ASSERT_TRUE(contents); |
| 664 | 664 |
| 665 // Check that the value is reflected and onsubmit is called. | 665 // Check that the value is reflected and onsubmit is called. |
| 666 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6", | 666 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6", |
| 667 GetSearchStateAsString(preview_)); | 667 GetSearchStateAsString(preview_)); |
| 668 } | 668 } |
| OLD | NEW |