| 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/chrome_autocomplete_scheme_classifier.h" | 7 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 8 #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h" | 8 #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 10 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TemplateURLServiceFactory::GetForProfile(profile)); | 35 TemplateURLServiceFactory::GetForProfile(profile)); |
| 36 | 36 |
| 37 AutocompleteController* autocomplete_controller = | 37 AutocompleteController* autocomplete_controller = |
| 38 GetAutocompleteController(browser()); | 38 GetAutocompleteController(browser()); |
| 39 | 39 |
| 40 // Test that our extension's keyword is suggested to us when we partially type | 40 // Test that our extension's keyword is suggested to us when we partially type |
| 41 // it. | 41 // it. |
| 42 { | 42 { |
| 43 autocomplete_controller->Start(AutocompleteInput( | 43 autocomplete_controller->Start(AutocompleteInput( |
| 44 ASCIIToUTF16("keywor"), base::string16::npos, std::string(), GURL(), | 44 ASCIIToUTF16("keywor"), base::string16::npos, std::string(), GURL(), |
| 45 OmniboxEventProto::NTP, true, false, true, true, false, | 45 base::string16(), OmniboxEventProto::NTP, true, false, true, true, |
| 46 ChromeAutocompleteSchemeClassifier(profile))); | 46 false, ChromeAutocompleteSchemeClassifier(profile))); |
| 47 WaitForAutocompleteDone(autocomplete_controller); | 47 WaitForAutocompleteDone(autocomplete_controller); |
| 48 EXPECT_TRUE(autocomplete_controller->done()); | 48 EXPECT_TRUE(autocomplete_controller->done()); |
| 49 | 49 |
| 50 // Now, peek into the controller to see if it has the results we expect. | 50 // Now, peek into the controller to see if it has the results we expect. |
| 51 // First result should be to search for what was typed, second should be to | 51 // First result should be to search for what was typed, second should be to |
| 52 // enter "extension keyword" mode. | 52 // enter "extension keyword" mode. |
| 53 const AutocompleteResult& result = autocomplete_controller->result(); | 53 const AutocompleteResult& result = autocomplete_controller->result(); |
| 54 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); | 54 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); |
| 55 AutocompleteMatch match = result.match_at(0); | 55 AutocompleteMatch match = result.match_at(0); |
| 56 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, match.type); | 56 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, match.type); |
| 57 EXPECT_FALSE(match.deletable); | 57 EXPECT_FALSE(match.deletable); |
| 58 | 58 |
| 59 match = result.match_at(1); | 59 match = result.match_at(1); |
| 60 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); | 60 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Test that our extension can send suggestions back to us. | 63 // Test that our extension can send suggestions back to us. |
| 64 { | 64 { |
| 65 autocomplete_controller->Start(AutocompleteInput( | 65 autocomplete_controller->Start(AutocompleteInput( |
| 66 ASCIIToUTF16("keyword suggestio"), base::string16::npos, std::string(), | 66 ASCIIToUTF16("keyword suggestio"), base::string16::npos, std::string(), |
| 67 GURL(), OmniboxEventProto::NTP, true, false, true, true, false, | 67 GURL(), base::string16(), OmniboxEventProto::NTP, true, false, true, |
| 68 ChromeAutocompleteSchemeClassifier(profile))); | 68 true, false, ChromeAutocompleteSchemeClassifier(profile))); |
| 69 WaitForAutocompleteDone(autocomplete_controller); | 69 WaitForAutocompleteDone(autocomplete_controller); |
| 70 EXPECT_TRUE(autocomplete_controller->done()); | 70 EXPECT_TRUE(autocomplete_controller->done()); |
| 71 | 71 |
| 72 // Now, peek into the controller to see if it has the results we expect. | 72 // Now, peek into the controller to see if it has the results we expect. |
| 73 // First result should be to invoke the keyword with what we typed, 2-4 | 73 // First result should be to invoke the keyword with what we typed, 2-4 |
| 74 // should be to invoke with suggestions from the extension, and the last | 74 // should be to invoke with suggestions from the extension, and the last |
| 75 // should be to search for what we typed. | 75 // should be to search for what we typed. |
| 76 const AutocompleteResult& result = autocomplete_controller->result(); | 76 const AutocompleteResult& result = autocomplete_controller->result(); |
| 77 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 77 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
| 78 | 78 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); | 168 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); |
| 169 ResultCatcher catcher; | 169 ResultCatcher catcher; |
| 170 AutocompleteController* autocomplete_controller = | 170 AutocompleteController* autocomplete_controller = |
| 171 GetAutocompleteController(browser()); | 171 GetAutocompleteController(browser()); |
| 172 omnibox_view->OnBeforePossibleChange(); | 172 omnibox_view->OnBeforePossibleChange(); |
| 173 omnibox_view->SetUserText(ASCIIToUTF16("keyword command")); | 173 omnibox_view->SetUserText(ASCIIToUTF16("keyword command")); |
| 174 omnibox_view->OnAfterPossibleChange(true); | 174 omnibox_view->OnAfterPossibleChange(true); |
| 175 | 175 |
| 176 autocomplete_controller->Start(AutocompleteInput( | 176 autocomplete_controller->Start(AutocompleteInput( |
| 177 ASCIIToUTF16("keyword command"), base::string16::npos, std::string(), | 177 ASCIIToUTF16("keyword command"), base::string16::npos, std::string(), |
| 178 GURL(), OmniboxEventProto::NTP, true, false, true, true, false, | 178 GURL(), base::string16(), OmniboxEventProto::NTP, true, false, true, true, |
| 179 ChromeAutocompleteSchemeClassifier(profile))); | 179 false, ChromeAutocompleteSchemeClassifier(profile))); |
| 180 omnibox_view->model()->AcceptInput(WindowOpenDisposition::CURRENT_TAB, false); | 180 omnibox_view->model()->AcceptInput(WindowOpenDisposition::CURRENT_TAB, false); |
| 181 WaitForAutocompleteDone(autocomplete_controller); | 181 WaitForAutocompleteDone(autocomplete_controller); |
| 182 EXPECT_TRUE(autocomplete_controller->done()); | 182 EXPECT_TRUE(autocomplete_controller->done()); |
| 183 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 183 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 184 | 184 |
| 185 omnibox_view->OnBeforePossibleChange(); | 185 omnibox_view->OnBeforePossibleChange(); |
| 186 omnibox_view->SetUserText(ASCIIToUTF16("keyword newtab")); | 186 omnibox_view->SetUserText(ASCIIToUTF16("keyword newtab")); |
| 187 omnibox_view->OnAfterPossibleChange(true); | 187 omnibox_view->OnAfterPossibleChange(true); |
| 188 WaitForAutocompleteDone(autocomplete_controller); | 188 WaitForAutocompleteDone(autocomplete_controller); |
| 189 EXPECT_TRUE(autocomplete_controller->done()); | 189 EXPECT_TRUE(autocomplete_controller->done()); |
| 190 | 190 |
| 191 autocomplete_controller->Start(AutocompleteInput( | 191 autocomplete_controller->Start(AutocompleteInput( |
| 192 ASCIIToUTF16("keyword newtab"), base::string16::npos, std::string(), | 192 ASCIIToUTF16("keyword newtab"), base::string16::npos, std::string(), |
| 193 GURL(), OmniboxEventProto::NTP, true, false, true, true, false, | 193 GURL(), base::string16(), OmniboxEventProto::NTP, true, false, true, true, |
| 194 ChromeAutocompleteSchemeClassifier(profile))); | 194 false, ChromeAutocompleteSchemeClassifier(profile))); |
| 195 omnibox_view->model()->AcceptInput(WindowOpenDisposition::NEW_FOREGROUND_TAB, | 195 omnibox_view->model()->AcceptInput(WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 196 false); | 196 false); |
| 197 WaitForAutocompleteDone(autocomplete_controller); | 197 WaitForAutocompleteDone(autocomplete_controller); |
| 198 EXPECT_TRUE(autocomplete_controller->done()); | 198 EXPECT_TRUE(autocomplete_controller->done()); |
| 199 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 199 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Tests that we get suggestions from and send input to the incognito context | 202 // Tests that we get suggestions from and send input to the incognito context |
| 203 // of an incognito split mode extension. | 203 // of an incognito split mode extension. |
| 204 // http://crbug.com/100927 | 204 // http://crbug.com/100927 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 TemplateURLServiceFactory::GetForProfile(browser()->profile())); | 221 TemplateURLServiceFactory::GetForProfile(browser()->profile())); |
| 222 | 222 |
| 223 LocationBar* location_bar = GetLocationBar(incognito_browser); | 223 LocationBar* location_bar = GetLocationBar(incognito_browser); |
| 224 AutocompleteController* autocomplete_controller = | 224 AutocompleteController* autocomplete_controller = |
| 225 GetAutocompleteController(incognito_browser); | 225 GetAutocompleteController(incognito_browser); |
| 226 | 226 |
| 227 // Test that we get the incognito-specific suggestions. | 227 // Test that we get the incognito-specific suggestions. |
| 228 { | 228 { |
| 229 autocomplete_controller->Start(AutocompleteInput( | 229 autocomplete_controller->Start(AutocompleteInput( |
| 230 ASCIIToUTF16("keyword suggestio"), base::string16::npos, std::string(), | 230 ASCIIToUTF16("keyword suggestio"), base::string16::npos, std::string(), |
| 231 GURL(), OmniboxEventProto::NTP, true, false, true, true, false, | 231 GURL(), base::string16(), OmniboxEventProto::NTP, true, false, true, |
| 232 ChromeAutocompleteSchemeClassifier(profile))); | 232 true, false, ChromeAutocompleteSchemeClassifier(profile))); |
| 233 WaitForAutocompleteDone(autocomplete_controller); | 233 WaitForAutocompleteDone(autocomplete_controller); |
| 234 EXPECT_TRUE(autocomplete_controller->done()); | 234 EXPECT_TRUE(autocomplete_controller->done()); |
| 235 | 235 |
| 236 // First result should be to invoke the keyword with what we typed, 2-4 | 236 // First result should be to invoke the keyword with what we typed, 2-4 |
| 237 // should be to invoke with suggestions from the extension, and the last | 237 // should be to invoke with suggestions from the extension, and the last |
| 238 // should be to search for what we typed. | 238 // should be to search for what we typed. |
| 239 const AutocompleteResult& result = autocomplete_controller->result(); | 239 const AutocompleteResult& result = autocomplete_controller->result(); |
| 240 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 240 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
| 241 ASSERT_FALSE(result.match_at(0).keyword.empty()); | 241 ASSERT_FALSE(result.match_at(0).keyword.empty()); |
| 242 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), | 242 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), |
| 243 result.match_at(3).fill_into_edit); | 243 result.match_at(3).fill_into_edit); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Test that our input is sent to the incognito context. The test will do a | 246 // Test that our input is sent to the incognito context. The test will do a |
| 247 // text comparison and succeed only if "command incognito" is sent to the | 247 // text comparison and succeed only if "command incognito" is sent to the |
| 248 // incognito context. | 248 // incognito context. |
| 249 { | 249 { |
| 250 ResultCatcher catcher; | 250 ResultCatcher catcher; |
| 251 autocomplete_controller->Start(AutocompleteInput( | 251 autocomplete_controller->Start(AutocompleteInput( |
| 252 ASCIIToUTF16("keyword command incognito"), base::string16::npos, | 252 ASCIIToUTF16("keyword command incognito"), base::string16::npos, |
| 253 std::string(), GURL(), OmniboxEventProto::NTP, true, false, true, true, | 253 std::string(), GURL(), base::string16(), OmniboxEventProto::NTP, true, |
| 254 false, ChromeAutocompleteSchemeClassifier(profile))); | 254 false, true, true, false, ChromeAutocompleteSchemeClassifier(profile))); |
| 255 location_bar->AcceptInput(); | 255 location_bar->AcceptInput(); |
| 256 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 256 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 257 } | 257 } |
| 258 } | 258 } |
| OLD | NEW |