| 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/strings/string16.h" | 5 #include "base/strings/string16.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 7 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_input.h" | 8 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_result.h" | 10 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h" | 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/omnibox/location_bar.h" | 15 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 16 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 16 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "ui/base/window_open_disposition.h" | 18 #include "ui/base/window_open_disposition.h" |
| 19 | 19 |
| 20 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
| 21 using metrics::OmniboxEventProto; |
| 21 | 22 |
| 22 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { | 23 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { |
| 23 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; | 24 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; |
| 24 | 25 |
| 25 // The results depend on the TemplateURLService being loaded. Make sure it is | 26 // The results depend on the TemplateURLService being loaded. Make sure it is |
| 26 // loaded so that the autocomplete results are consistent. | 27 // loaded so that the autocomplete results are consistent. |
| 27 ui_test_utils::WaitForTemplateURLServiceToLoad( | 28 ui_test_utils::WaitForTemplateURLServiceToLoad( |
| 28 TemplateURLServiceFactory::GetForProfile(browser()->profile())); | 29 TemplateURLServiceFactory::GetForProfile(browser()->profile())); |
| 29 | 30 |
| 30 AutocompleteController* autocomplete_controller = | 31 AutocompleteController* autocomplete_controller = |
| 31 GetAutocompleteController(browser()); | 32 GetAutocompleteController(browser()); |
| 32 | 33 |
| 33 // Test that our extension's keyword is suggested to us when we partially type | 34 // Test that our extension's keyword is suggested to us when we partially type |
| 34 // it. | 35 // it. |
| 35 { | 36 { |
| 36 autocomplete_controller->Start( | 37 autocomplete_controller->Start( |
| 37 AutocompleteInput(ASCIIToUTF16("keywor"), base::string16::npos, | 38 AutocompleteInput(ASCIIToUTF16("keywor"), base::string16::npos, |
| 38 base::string16(), GURL(), AutocompleteInput::NTP, | 39 base::string16(), GURL(), OmniboxEventProto::NTP, |
| 39 true, false, true, true)); | 40 true, false, true, true)); |
| 40 WaitForAutocompleteDone(autocomplete_controller); | 41 WaitForAutocompleteDone(autocomplete_controller); |
| 41 EXPECT_TRUE(autocomplete_controller->done()); | 42 EXPECT_TRUE(autocomplete_controller->done()); |
| 42 | 43 |
| 43 // Now, peek into the controller to see if it has the results we expect. | 44 // Now, peek into the controller to see if it has the results we expect. |
| 44 // First result should be to search for what was typed, second should be to | 45 // First result should be to search for what was typed, second should be to |
| 45 // enter "extension keyword" mode. | 46 // enter "extension keyword" mode. |
| 46 const AutocompleteResult& result = autocomplete_controller->result(); | 47 const AutocompleteResult& result = autocomplete_controller->result(); |
| 47 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); | 48 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); |
| 48 AutocompleteMatch match = result.match_at(0); | 49 AutocompleteMatch match = result.match_at(0); |
| 49 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, match.type); | 50 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, match.type); |
| 50 EXPECT_FALSE(match.deletable); | 51 EXPECT_FALSE(match.deletable); |
| 51 | 52 |
| 52 match = result.match_at(1); | 53 match = result.match_at(1); |
| 53 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); | 54 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Test that our extension can send suggestions back to us. | 57 // Test that our extension can send suggestions back to us. |
| 57 { | 58 { |
| 58 autocomplete_controller->Start( | 59 autocomplete_controller->Start( |
| 59 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), | 60 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), |
| 60 base::string16::npos, base::string16(), GURL(), | 61 base::string16::npos, base::string16(), GURL(), |
| 61 AutocompleteInput::NTP, true, false, true, true)); | 62 OmniboxEventProto::NTP, true, false, true, true)); |
| 62 WaitForAutocompleteDone(autocomplete_controller); | 63 WaitForAutocompleteDone(autocomplete_controller); |
| 63 EXPECT_TRUE(autocomplete_controller->done()); | 64 EXPECT_TRUE(autocomplete_controller->done()); |
| 64 | 65 |
| 65 // Now, peek into the controller to see if it has the results we expect. | 66 // Now, peek into the controller to see if it has the results we expect. |
| 66 // First result should be to invoke the keyword with what we typed, 2-4 | 67 // First result should be to invoke the keyword with what we typed, 2-4 |
| 67 // should be to invoke with suggestions from the extension, and the last | 68 // should be to invoke with suggestions from the extension, and the last |
| 68 // should be to search for what we typed. | 69 // should be to search for what we typed. |
| 69 const AutocompleteResult& result = autocomplete_controller->result(); | 70 const AutocompleteResult& result = autocomplete_controller->result(); |
| 70 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 71 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
| 71 | 72 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); | 161 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); |
| 161 ResultCatcher catcher; | 162 ResultCatcher catcher; |
| 162 AutocompleteController* autocomplete_controller = | 163 AutocompleteController* autocomplete_controller = |
| 163 GetAutocompleteController(browser()); | 164 GetAutocompleteController(browser()); |
| 164 omnibox_view->OnBeforePossibleChange(); | 165 omnibox_view->OnBeforePossibleChange(); |
| 165 omnibox_view->SetUserText(ASCIIToUTF16("keyword command")); | 166 omnibox_view->SetUserText(ASCIIToUTF16("keyword command")); |
| 166 omnibox_view->OnAfterPossibleChange(); | 167 omnibox_view->OnAfterPossibleChange(); |
| 167 | 168 |
| 168 autocomplete_controller->Start( | 169 autocomplete_controller->Start( |
| 169 AutocompleteInput(ASCIIToUTF16("keyword command"), base::string16::npos, | 170 AutocompleteInput(ASCIIToUTF16("keyword command"), base::string16::npos, |
| 170 base::string16(), GURL(), AutocompleteInput::NTP, | 171 base::string16(), GURL(), OmniboxEventProto::NTP, |
| 171 true, false, true, true)); | 172 true, false, true, true)); |
| 172 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); | 173 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); |
| 173 WaitForAutocompleteDone(autocomplete_controller); | 174 WaitForAutocompleteDone(autocomplete_controller); |
| 174 EXPECT_TRUE(autocomplete_controller->done()); | 175 EXPECT_TRUE(autocomplete_controller->done()); |
| 175 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 176 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 176 | 177 |
| 177 omnibox_view->OnBeforePossibleChange(); | 178 omnibox_view->OnBeforePossibleChange(); |
| 178 omnibox_view->SetUserText(ASCIIToUTF16("keyword newtab")); | 179 omnibox_view->SetUserText(ASCIIToUTF16("keyword newtab")); |
| 179 omnibox_view->OnAfterPossibleChange(); | 180 omnibox_view->OnAfterPossibleChange(); |
| 180 WaitForAutocompleteDone(autocomplete_controller); | 181 WaitForAutocompleteDone(autocomplete_controller); |
| 181 EXPECT_TRUE(autocomplete_controller->done()); | 182 EXPECT_TRUE(autocomplete_controller->done()); |
| 182 | 183 |
| 183 autocomplete_controller->Start( | 184 autocomplete_controller->Start( |
| 184 AutocompleteInput(ASCIIToUTF16("keyword newtab"), base::string16::npos, | 185 AutocompleteInput(ASCIIToUTF16("keyword newtab"), base::string16::npos, |
| 185 base::string16(), GURL(), AutocompleteInput::NTP, | 186 base::string16(), GURL(), OmniboxEventProto::NTP, |
| 186 true, false, true, true)); | 187 true, false, true, true)); |
| 187 omnibox_view->model()->AcceptInput(NEW_FOREGROUND_TAB, false); | 188 omnibox_view->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
| 188 WaitForAutocompleteDone(autocomplete_controller); | 189 WaitForAutocompleteDone(autocomplete_controller); |
| 189 EXPECT_TRUE(autocomplete_controller->done()); | 190 EXPECT_TRUE(autocomplete_controller->done()); |
| 190 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 191 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 // Tests that we get suggestions from and send input to the incognito context | 194 // Tests that we get suggestions from and send input to the incognito context |
| 194 // of an incognito split mode extension. | 195 // of an incognito split mode extension. |
| 195 // http://crbug.com/100927 | 196 // http://crbug.com/100927 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 213 | 214 |
| 214 LocationBar* location_bar = GetLocationBar(incognito_browser); | 215 LocationBar* location_bar = GetLocationBar(incognito_browser); |
| 215 AutocompleteController* autocomplete_controller = | 216 AutocompleteController* autocomplete_controller = |
| 216 GetAutocompleteController(incognito_browser); | 217 GetAutocompleteController(incognito_browser); |
| 217 | 218 |
| 218 // Test that we get the incognito-specific suggestions. | 219 // Test that we get the incognito-specific suggestions. |
| 219 { | 220 { |
| 220 autocomplete_controller->Start( | 221 autocomplete_controller->Start( |
| 221 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), | 222 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), |
| 222 base::string16::npos, base::string16(), GURL(), | 223 base::string16::npos, base::string16(), GURL(), |
| 223 AutocompleteInput::NTP, true, false, true, true)); | 224 OmniboxEventProto::NTP, true, false, true, true)); |
| 224 WaitForAutocompleteDone(autocomplete_controller); | 225 WaitForAutocompleteDone(autocomplete_controller); |
| 225 EXPECT_TRUE(autocomplete_controller->done()); | 226 EXPECT_TRUE(autocomplete_controller->done()); |
| 226 | 227 |
| 227 // First result should be to invoke the keyword with what we typed, 2-4 | 228 // First result should be to invoke the keyword with what we typed, 2-4 |
| 228 // should be to invoke with suggestions from the extension, and the last | 229 // should be to invoke with suggestions from the extension, and the last |
| 229 // should be to search for what we typed. | 230 // should be to search for what we typed. |
| 230 const AutocompleteResult& result = autocomplete_controller->result(); | 231 const AutocompleteResult& result = autocomplete_controller->result(); |
| 231 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 232 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
| 232 ASSERT_FALSE(result.match_at(0).keyword.empty()); | 233 ASSERT_FALSE(result.match_at(0).keyword.empty()); |
| 233 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), | 234 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), |
| 234 result.match_at(3).fill_into_edit); | 235 result.match_at(3).fill_into_edit); |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Test that our input is sent to the incognito context. The test will do a | 238 // Test that our input is sent to the incognito context. The test will do a |
| 238 // text comparison and succeed only if "command incognito" is sent to the | 239 // text comparison and succeed only if "command incognito" is sent to the |
| 239 // incognito context. | 240 // incognito context. |
| 240 { | 241 { |
| 241 ResultCatcher catcher; | 242 ResultCatcher catcher; |
| 242 autocomplete_controller->Start( | 243 autocomplete_controller->Start( |
| 243 AutocompleteInput(ASCIIToUTF16("keyword command incognito"), | 244 AutocompleteInput(ASCIIToUTF16("keyword command incognito"), |
| 244 base::string16::npos, base::string16(), GURL(), | 245 base::string16::npos, base::string16(), GURL(), |
| 245 AutocompleteInput::NTP, true, false, true, true)); | 246 OmniboxEventProto::NTP, true, false, true, true)); |
| 246 location_bar->AcceptInput(); | 247 location_bar->AcceptInput(); |
| 247 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 248 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 248 } | 249 } |
| 249 } | 250 } |
| OLD | NEW |