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

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

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 TemplateURLServiceFactory::GetForProfile(browser()->profile())); 76 TemplateURLServiceFactory::GetForProfile(browser()->profile()));
77 77
78 LocationBar* location_bar = GetLocationBar(browser()); 78 LocationBar* location_bar = GetLocationBar(browser());
79 AutocompleteController* autocomplete_controller = 79 AutocompleteController* autocomplete_controller =
80 GetAutocompleteController(browser()); 80 GetAutocompleteController(browser());
81 81
82 // Test that our extension's keyword is suggested to us when we partially type 82 // Test that our extension's keyword is suggested to us when we partially type
83 // it. 83 // it.
84 { 84 {
85 autocomplete_controller->Start( 85 autocomplete_controller->Start(
86 ASCIIToUTF16("keywor"), string16(), true, false, true, 86 AutocompleteInput(ASCIIToUTF16("keywor"), string16::npos, string16(),
87 AutocompleteInput::ALL_MATCHES); 87 true, false, true, AutocompleteInput::ALL_MATCHES));
88 WaitForAutocompleteDone(autocomplete_controller); 88 WaitForAutocompleteDone(autocomplete_controller);
89 EXPECT_TRUE(autocomplete_controller->done()); 89 EXPECT_TRUE(autocomplete_controller->done());
90 90
91 // Now, peek into the controller to see if it has the results we expect. 91 // Now, peek into the controller to see if it has the results we expect.
92 // First result should be to search for what was typed, second should be to 92 // First result should be to search for what was typed, second should be to
93 // enter "extension keyword" mode. 93 // enter "extension keyword" mode.
94 const AutocompleteResult& result = autocomplete_controller->result(); 94 const AutocompleteResult& result = autocomplete_controller->result();
95 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); 95 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result);
96 AutocompleteMatch match = result.match_at(0); 96 AutocompleteMatch match = result.match_at(0);
97 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 97 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
98 EXPECT_FALSE(match.deletable); 98 EXPECT_FALSE(match.deletable);
99 99
100 match = result.match_at(1); 100 match = result.match_at(1);
101 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword); 101 EXPECT_EQ(ASCIIToUTF16("keyword"), match.keyword);
102 } 102 }
103 103
104 // Test that our extension can send suggestions back to us. 104 // Test that our extension can send suggestions back to us.
105 { 105 {
106 autocomplete_controller->Start( 106 autocomplete_controller->Start(
107 ASCIIToUTF16("keyword suggestio"), string16(), true, false, true, 107 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos,
108 AutocompleteInput::ALL_MATCHES); 108 string16(), true, false, true,
109 AutocompleteInput::ALL_MATCHES));
109 WaitForAutocompleteDone(autocomplete_controller); 110 WaitForAutocompleteDone(autocomplete_controller);
110 EXPECT_TRUE(autocomplete_controller->done()); 111 EXPECT_TRUE(autocomplete_controller->done());
111 112
112 // Now, peek into the controller to see if it has the results we expect. 113 // Now, peek into the controller to see if it has the results we expect.
113 // First result should be to invoke the keyword with what we typed, 2-4 114 // First result should be to invoke the keyword with what we typed, 2-4
114 // should be to invoke with suggestions from the extension, and the last 115 // should be to invoke with suggestions from the extension, and the last
115 // should be to search for what we typed. 116 // should be to search for what we typed.
116 const AutocompleteResult& result = autocomplete_controller->result(); 117 const AutocompleteResult& result = autocomplete_controller->result();
117 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); 118 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result);
118 119
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 207
207 // Quickly type another query and accept it before getting suggestions back 208 // Quickly type another query and accept it before getting suggestions back
208 // for the query. The popup will close after accepting input - ensure that it 209 // for the query. The popup will close after accepting input - ensure that it
209 // does not reopen when the extension returns its suggestions. 210 // does not reopen when the extension returns its suggestions.
210 ResultCatcher catcher; 211 ResultCatcher catcher;
211 212
212 // TODO: Rather than send this second request by talking to the controller 213 // TODO: Rather than send this second request by talking to the controller
213 // directly, figure out how to send it via the proper calls to 214 // directly, figure out how to send it via the proper calls to
214 // location_bar or location_bar->(). 215 // location_bar or location_bar->().
215 autocomplete_controller->Start( 216 autocomplete_controller->Start(
216 ASCIIToUTF16("keyword command"), string16(), true, false, true, 217 AutocompleteInput(ASCIIToUTF16("keyword command"), string16::npos,
217 AutocompleteInput::ALL_MATCHES); 218 string16(), true, false, true,
219 AutocompleteInput::ALL_MATCHES));
218 location_bar->AcceptInput(); 220 location_bar->AcceptInput();
219 WaitForAutocompleteDone(autocomplete_controller); 221 WaitForAutocompleteDone(autocomplete_controller);
220 EXPECT_TRUE(autocomplete_controller->done()); 222 EXPECT_TRUE(autocomplete_controller->done());
221 // This checks that the keyword provider (via javascript) 223 // This checks that the keyword provider (via javascript)
222 // gets told to navigate to the string "command". 224 // gets told to navigate to the string "command".
223 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 225 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
224 EXPECT_FALSE(popup_model->IsOpen()); 226 EXPECT_FALSE(popup_model->IsOpen());
225 } 227 }
226 228
227 // Tests that we get suggestions from and send input to the incognito context 229 // Tests that we get suggestions from and send input to the incognito context
(...skipping 17 matching lines...) Expand all
245 ui_test_utils::WaitForTemplateURLServiceToLoad( 247 ui_test_utils::WaitForTemplateURLServiceToLoad(
246 TemplateURLServiceFactory::GetForProfile(browser()->profile())); 248 TemplateURLServiceFactory::GetForProfile(browser()->profile()));
247 249
248 LocationBar* location_bar = GetLocationBar(incognito_browser); 250 LocationBar* location_bar = GetLocationBar(incognito_browser);
249 AutocompleteController* autocomplete_controller = 251 AutocompleteController* autocomplete_controller =
250 GetAutocompleteController(incognito_browser); 252 GetAutocompleteController(incognito_browser);
251 253
252 // Test that we get the incognito-specific suggestions. 254 // Test that we get the incognito-specific suggestions.
253 { 255 {
254 autocomplete_controller->Start( 256 autocomplete_controller->Start(
255 ASCIIToUTF16("keyword suggestio"), string16(), true, false, true, 257 AutocompleteInput(ASCIIToUTF16("keyword suggestio"), string16::npos,
256 AutocompleteInput::ALL_MATCHES); 258 string16(), true, false, true,
259 AutocompleteInput::ALL_MATCHES));
257 WaitForAutocompleteDone(autocomplete_controller); 260 WaitForAutocompleteDone(autocomplete_controller);
258 EXPECT_TRUE(autocomplete_controller->done()); 261 EXPECT_TRUE(autocomplete_controller->done());
259 262
260 // First result should be to invoke the keyword with what we typed, 2-4 263 // First result should be to invoke the keyword with what we typed, 2-4
261 // should be to invoke with suggestions from the extension, and the last 264 // should be to invoke with suggestions from the extension, and the last
262 // should be to search for what we typed. 265 // should be to search for what we typed.
263 const AutocompleteResult& result = autocomplete_controller->result(); 266 const AutocompleteResult& result = autocomplete_controller->result();
264 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); 267 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result);
265 ASSERT_FALSE(result.match_at(0).keyword.empty()); 268 ASSERT_FALSE(result.match_at(0).keyword.empty());
266 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), 269 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"),
267 result.match_at(3).fill_into_edit); 270 result.match_at(3).fill_into_edit);
268 } 271 }
269 272
270 // Test that our input is sent to the incognito context. The test will do a 273 // Test that our input is sent to the incognito context. The test will do a
271 // text comparison and succeed only if "command incognito" is sent to the 274 // text comparison and succeed only if "command incognito" is sent to the
272 // incognito context. 275 // incognito context.
273 { 276 {
274 ResultCatcher catcher; 277 ResultCatcher catcher;
275 autocomplete_controller->Start( 278 autocomplete_controller->Start(
276 ASCIIToUTF16("keyword command incognito"), string16(), 279 AutocompleteInput(ASCIIToUTF16("keyword command incognito"),
277 true, false, true, AutocompleteInput::ALL_MATCHES); 280 string16::npos, string16(), true, false, true,
281 AutocompleteInput::ALL_MATCHES));
278 location_bar->AcceptInput(); 282 location_bar->AcceptInput();
279 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 283 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
280 } 284 }
281 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698