| 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 "chrome/browser/instant/instant_commit_type.h" |
| 5 #include "chrome/browser/instant/instant_loader.h" | 6 #include "chrome/browser/instant/instant_loader.h" |
| 6 #include "chrome/browser/instant/instant_test_utils.h" | 7 #include "chrome/browser/instant/instant_test_utils.h" |
| 7 #include "chrome/browser/ui/search/search.h" | 8 #include "chrome/browser/ui/search/search.h" |
| 8 #include "chrome/test/base/interactive_test_utils.h" | 9 #include "chrome/test/base/interactive_test_utils.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 10 | 11 |
| 11 class InstantExtendedTest : public InstantTestBase { | 12 class InstantExtendedTest : public InstantTestBase { |
| 12 protected: | 13 protected: |
| 13 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 14 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 14 chrome::search::EnableInstantExtendedAPIForTesting(); | 15 chrome::search::EnableInstantExtendedAPIForTesting(); |
| 15 ASSERT_TRUE(test_server()->Start()); | 16 ASSERT_TRUE(https_test_server_->Start()); |
| 16 instant_url_ = test_server()->GetURL("files/instant_extended.html"); | 17 instant_url_ = https_test_server_-> |
| 18 GetURL("files/instant_extended.html?strk=1&"); |
| 17 } | 19 } |
| 18 }; | 20 }; |
| 19 | 21 |
| 20 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { | 22 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { |
| 21 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 23 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 22 EXPECT_TRUE(instant()->extended_enabled_); | 24 EXPECT_TRUE(instant()->extended_enabled_); |
| 23 } | 25 } |
| 24 | 26 |
| 25 // Test that Instant is preloaded when the omnibox is focused. | 27 // Test that Instant is preloaded when the omnibox is focused. |
| 26 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { | 28 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 75 content::WebContents* preview_tab = instant()->GetPreviewContents(); |
| 74 EXPECT_TRUE(preview_tab); | 76 EXPECT_TRUE(preview_tab); |
| 75 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 77 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
| 76 EXPECT_TRUE(instant()->model()->mode().is_default()); | 78 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 77 | 79 |
| 78 // Typing in the omnibox should show the overlay. | 80 // Typing in the omnibox should show the overlay. |
| 79 SetOmniboxTextAndWaitForInstantToShow("query"); | 81 SetOmniboxTextAndWaitForInstantToShow("query"); |
| 80 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | 82 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
| 81 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 83 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
| 82 } | 84 } |
| 85 |
| 86 // Test that omnibox text is correctly set when overlay is committed with Enter. |
| 87 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponEnterCommit) { |
| 88 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 89 FocusOmniboxAndWaitForInstantSupport(); |
| 90 |
| 91 // The page will autocomplete once we set the omnibox value. |
| 92 EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';")); |
| 93 |
| 94 // Set the text, and wait for suggestions to show up. |
| 95 SetOmniboxTextAndWaitForInstantToShow("santa"); |
| 96 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); |
| 97 |
| 98 // Test that the current suggestion is correctly set. |
| 99 EXPECT_EQ(ASCIIToUTF16(" claus"), omnibox()->GetInstantSuggestion()); |
| 100 |
| 101 // Commit the search by pressing Enter. |
| 102 browser()->window()->GetLocationBar()->AcceptInput(); |
| 103 |
| 104 // 'Enter' commits the query as it was typed. |
| 105 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); |
| 106 |
| 107 // Suggestion should be cleared at this point. |
| 108 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 109 } |
| 110 |
| 111 // Test that omnibox text is correctly set when overlay is committed with focus |
| 112 // lost. |
| 113 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) { |
| 114 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 115 FocusOmniboxAndWaitForInstantSupport(); |
| 116 |
| 117 // Set autocomplete text (grey text). |
| 118 EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';")); |
| 119 |
| 120 // Set the text, and wait for suggestions to show up. |
| 121 SetOmniboxTextAndWaitForInstantToShow("johnny"); |
| 122 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); |
| 123 |
| 124 // Test that the current suggestion is correctly set. |
| 125 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); |
| 126 |
| 127 // Commit the overlay by lost focus (e.g. clicking on the page). |
| 128 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 129 |
| 130 // Search term extraction should kick in with the autocompleted text. |
| 131 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText()); |
| 132 |
| 133 // Suggestion should be cleared at this point. |
| 134 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 135 } |
| OLD | NEW |