Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_apitest.cc

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed ChromeOS. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/format_macros.h" 5 #include "base/format_macros.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/autocomplete/autocomplete_input.h" 9 #include "chrome/browser/autocomplete/autocomplete_input.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 TemplateURLServiceFactory::GetForProfile(browser()->profile())); 72 TemplateURLServiceFactory::GetForProfile(browser()->profile()));
73 73
74 AutocompleteController* autocomplete_controller = 74 AutocompleteController* autocomplete_controller =
75 GetAutocompleteController(browser()); 75 GetAutocompleteController(browser());
76 76
77 // Test that our extension's keyword is suggested to us when we partially type 77 // Test that our extension's keyword is suggested to us when we partially type
78 // it. 78 // it.
79 { 79 {
80 autocomplete_controller->Start( 80 autocomplete_controller->Start(
81 AutocompleteInput(ASCIIToUTF16("keywor"), string16::npos, string16(), 81 AutocompleteInput(ASCIIToUTF16("keywor"), string16::npos, string16(),
82 true, false, true, AutocompleteInput::ALL_MATCHES)); 82 GURL(), true, false, true,
83 AutocompleteInput::ALL_MATCHES));
83 WaitForAutocompleteDone(autocomplete_controller); 84 WaitForAutocompleteDone(autocomplete_controller);
84 EXPECT_TRUE(autocomplete_controller->done()); 85 EXPECT_TRUE(autocomplete_controller->done());
85 86
86 // Now, peek into the controller to see if it has the results we expect. 87 // Now, peek into the controller to see if it has the results we expect.
87 // First result should be to search for what was typed, second should be to 88 // First result should be to search for what was typed, second should be to
88 // enter "extension keyword" mode. 89 // enter "extension keyword" mode.
89 const AutocompleteResult& result = autocomplete_controller->result(); 90 const AutocompleteResult& result = autocomplete_controller->result();
90 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); 91 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result);
91 AutocompleteMatch match = result.match_at(0); 92 AutocompleteMatch match = result.match_at(0);
92 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 93 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
93 EXPECT_FALSE(match.deletable); 94 EXPECT_FALSE(match.deletable);
94 95
95 match = result.match_at(1); 96 match = result.match_at(1);
96 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); 97 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword);
97 } 98 }
98 99
99 // Test that our extension can send suggestions back to us. 100 // Test that our extension can send suggestions back to us.
100 { 101 {
101 autocomplete_controller->Start( 102 autocomplete_controller->Start(
102 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos, 103 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos,
103 string16(), true, false, true, 104 string16(), GURL(), true, false, true,
104 AutocompleteInput::ALL_MATCHES)); 105 AutocompleteInput::ALL_MATCHES));
105 WaitForAutocompleteDone(autocomplete_controller); 106 WaitForAutocompleteDone(autocomplete_controller);
106 EXPECT_TRUE(autocomplete_controller->done()); 107 EXPECT_TRUE(autocomplete_controller->done());
107 108
108 // Now, peek into the controller to see if it has the results we expect. 109 // Now, peek into the controller to see if it has the results we expect.
109 // First result should be to invoke the keyword with what we typed, 2-4 110 // First result should be to invoke the keyword with what we typed, 2-4
110 // should be to invoke with suggestions from the extension, and the last 111 // should be to invoke with suggestions from the extension, and the last
111 // should be to search for what we typed. 112 // should be to search for what we typed.
112 const AutocompleteResult& result = autocomplete_controller->result(); 113 const AutocompleteResult& result = autocomplete_controller->result();
113 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); 114 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Quickly type another query and accept it before getting suggestions back 222 // Quickly type another query and accept it before getting suggestions back
222 // for the query. The popup will close after accepting input - ensure that it 223 // for the query. The popup will close after accepting input - ensure that it
223 // does not reopen when the extension returns its suggestions. 224 // does not reopen when the extension returns its suggestions.
224 ResultCatcher catcher; 225 ResultCatcher catcher;
225 226
226 // TODO: Rather than send this second request by talking to the controller 227 // TODO: Rather than send this second request by talking to the controller
227 // directly, figure out how to send it via the proper calls to 228 // directly, figure out how to send it via the proper calls to
228 // location_bar or location_bar->(). 229 // location_bar or location_bar->().
229 autocomplete_controller->Start( 230 autocomplete_controller->Start(
230 AutocompleteInput(ASCIIToUTF16("keyword command"), string16::npos, 231 AutocompleteInput(ASCIIToUTF16("keyword command"), string16::npos,
231 string16(), true, false, true, 232 string16(), GURL(), true, false, true,
232 AutocompleteInput::ALL_MATCHES)); 233 AutocompleteInput::ALL_MATCHES));
233 location_bar->AcceptInput(); 234 location_bar->AcceptInput();
234 WaitForAutocompleteDone(autocomplete_controller); 235 WaitForAutocompleteDone(autocomplete_controller);
235 EXPECT_TRUE(autocomplete_controller->done()); 236 EXPECT_TRUE(autocomplete_controller->done());
236 // This checks that the keyword provider (via javascript) 237 // This checks that the keyword provider (via javascript)
237 // gets told to navigate to the string "command". 238 // gets told to navigate to the string "command".
238 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 239 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
239 EXPECT_FALSE(popup_model->IsOpen()); 240 EXPECT_FALSE(popup_model->IsOpen());
240 } 241 }
241 242
(...skipping 19 matching lines...) Expand all
261 TemplateURLServiceFactory::GetForProfile(browser()->profile())); 262 TemplateURLServiceFactory::GetForProfile(browser()->profile()));
262 263
263 LocationBar* location_bar = GetLocationBar(incognito_browser); 264 LocationBar* location_bar = GetLocationBar(incognito_browser);
264 AutocompleteController* autocomplete_controller = 265 AutocompleteController* autocomplete_controller =
265 GetAutocompleteController(incognito_browser); 266 GetAutocompleteController(incognito_browser);
266 267
267 // Test that we get the incognito-specific suggestions. 268 // Test that we get the incognito-specific suggestions.
268 { 269 {
269 autocomplete_controller->Start( 270 autocomplete_controller->Start(
270 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos, 271 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos,
271 string16(), true, false, true, 272 string16(), GURL(), true, false, true,
272 AutocompleteInput::ALL_MATCHES)); 273 AutocompleteInput::ALL_MATCHES));
273 WaitForAutocompleteDone(autocomplete_controller); 274 WaitForAutocompleteDone(autocomplete_controller);
274 EXPECT_TRUE(autocomplete_controller->done()); 275 EXPECT_TRUE(autocomplete_controller->done());
275 276
276 // First result should be to invoke the keyword with what we typed, 2-4 277 // First result should be to invoke the keyword with what we typed, 2-4
277 // should be to invoke with suggestions from the extension, and the last 278 // should be to invoke with suggestions from the extension, and the last
278 // should be to search for what we typed. 279 // should be to search for what we typed.
279 const AutocompleteResult& result = autocomplete_controller->result(); 280 const AutocompleteResult& result = autocomplete_controller->result();
280 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); 281 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result);
281 ASSERT_FALSE(result.match_at(0).keyword.empty()); 282 ASSERT_FALSE(result.match_at(0).keyword.empty());
282 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), 283 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"),
283 result.match_at(3).fill_into_edit); 284 result.match_at(3).fill_into_edit);
284 } 285 }
285 286
286 // Test that our input is sent to the incognito context. The test will do a 287 // Test that our input is sent to the incognito context. The test will do a
287 // text comparison and succeed only if "command incognito" is sent to the 288 // text comparison and succeed only if "command incognito" is sent to the
288 // incognito context. 289 // incognito context.
289 { 290 {
290 ResultCatcher catcher; 291 ResultCatcher catcher;
291 autocomplete_controller->Start( 292 autocomplete_controller->Start(
292 AutocompleteInput(ASCIIToUTF16("keyword command incognito"), 293 AutocompleteInput(ASCIIToUTF16("keyword command incognito"),
293 string16::npos, string16(), true, false, true, 294 string16::npos, string16(), GURL(), true, false, true,
294 AutocompleteInput::ALL_MATCHES)); 295 AutocompleteInput::ALL_MATCHES));
295 location_bar->AcceptInput(); 296 location_bar->AcceptInput();
296 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 297 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
297 } 298 }
298 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698