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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 10173001: Add a Profile* member to TemplateURL. This makes some invocations of ReplaceSearchTerms() a bit le… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, 257 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
258 content::Source<AutocompleteController>(controller)); 258 content::Source<AutocompleteController>(controller));
259 259
260 while (!HasFailure() && !controller->done()) 260 while (!HasFailure() && !controller->done())
261 ui_test_utils::RunMessageLoop(); 261 ui_test_utils::RunMessageLoop();
262 262
263 ASSERT_TRUE(controller->done()); 263 ASSERT_TRUE(controller->done());
264 } 264 }
265 265
266 void SetupSearchEngine() { 266 void SetupSearchEngine() {
267 Profile* profile = browser()->profile();
267 TemplateURLService* model = 268 TemplateURLService* model =
268 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 269 TemplateURLServiceFactory::GetForProfile(profile);
269 ASSERT_TRUE(model); 270 ASSERT_TRUE(model);
270 271
271 if (!model->loaded()) { 272 if (!model->loaded()) {
272 content::NotificationRegistrar registrar; 273 content::NotificationRegistrar registrar;
273 registrar.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 274 registrar.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
274 content::Source<TemplateURLService>(model)); 275 content::Source<TemplateURLService>(model));
275 model->Load(); 276 model->Load();
276 ui_test_utils::RunMessageLoop(); 277 ui_test_utils::RunMessageLoop();
277 } 278 }
278 279
279 ASSERT_TRUE(model->loaded()); 280 ASSERT_TRUE(model->loaded());
280 // Remove built-in template urls, like google.com, bing.com etc., as they 281 // Remove built-in template urls, like google.com, bing.com etc., as they
281 // may appear as autocomplete suggests and interfere with our tests. 282 // may appear as autocomplete suggests and interfere with our tests.
282 model->SetDefaultSearchProvider(NULL); 283 model->SetDefaultSearchProvider(NULL);
283 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs(); 284 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs();
284 for (TemplateURLService::TemplateURLVector::const_iterator 285 for (TemplateURLService::TemplateURLVector::const_iterator
285 i = builtins.begin(); i != builtins.end(); ++i) 286 i = builtins.begin(); i != builtins.end(); ++i)
286 model->Remove(*i); 287 model->Remove(*i);
287 288
288 TemplateURLData data; 289 TemplateURLData data;
289 data.short_name = ASCIIToUTF16(kSearchShortName); 290 data.short_name = ASCIIToUTF16(kSearchShortName);
290 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); 291 data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
291 data.SetURL(kSearchURL); 292 data.SetURL(kSearchURL);
292 TemplateURL* template_url = new TemplateURL(data); 293 TemplateURL* template_url = new TemplateURL(profile, data);
293 model->Add(template_url); 294 model->Add(template_url);
294 model->SetDefaultSearchProvider(template_url); 295 model->SetDefaultSearchProvider(template_url);
295 296
296 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); 297 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
297 model->Add(new TemplateURL(data)); 298 model->Add(new TemplateURL(profile, data));
298 } 299 }
299 300
300 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { 301 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
301 Profile* profile = browser()->profile(); 302 Profile* profile = browser()->profile();
302 HistoryService* history_service = 303 HistoryService* history_service =
303 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 304 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
304 ASSERT_TRUE(history_service); 305 ASSERT_TRUE(history_service);
305 306
306 if (!history_service->BackendLoaded()) { 307 if (!history_service->BackendLoaded()) {
307 content::NotificationRegistrar registrar; 308 content::NotificationRegistrar registrar;
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 ASSERT_EQ(search_keyword2, omnibox_view->model()->keyword()); 933 ASSERT_EQ(search_keyword2, omnibox_view->model()->keyword());
933 ASSERT_TRUE(omnibox_view->GetText().empty()); 934 ASSERT_TRUE(omnibox_view->GetText().empty());
934 } 935 }
935 936
936 void NonSubstitutingKeywordTest() { 937 void NonSubstitutingKeywordTest() {
937 OmniboxView* omnibox_view = NULL; 938 OmniboxView* omnibox_view = NULL;
938 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 939 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
939 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model(); 940 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
940 ASSERT_TRUE(popup_model); 941 ASSERT_TRUE(popup_model);
941 942
943 Profile* profile = browser()->profile();
942 TemplateURLService* template_url_service = 944 TemplateURLService* template_url_service =
943 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 945 TemplateURLServiceFactory::GetForProfile(profile);
944 946
945 // Add a non-default substituting keyword. 947 // Add a non-default substituting keyword.
946 TemplateURLData data; 948 TemplateURLData data;
947 data.short_name = ASCIIToUTF16("Search abc"); 949 data.short_name = ASCIIToUTF16("Search abc");
948 data.SetKeyword(ASCIIToUTF16(kSearchText)); 950 data.SetKeyword(ASCIIToUTF16(kSearchText));
949 data.SetURL("http://abc.com/{searchTerms}"); 951 data.SetURL("http://abc.com/{searchTerms}");
950 TemplateURL* template_url = new TemplateURL(data); 952 TemplateURL* template_url = new TemplateURL(profile, data);
951 template_url_service->Add(template_url); 953 template_url_service->Add(template_url);
952 954
953 omnibox_view->SetUserText(string16()); 955 omnibox_view->SetUserText(string16());
954 956
955 // Non-default substituting keyword shouldn't be matched by default. 957 // Non-default substituting keyword shouldn't be matched by default.
956 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 958 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
957 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 959 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
958 ASSERT_TRUE(popup_model->IsOpen()); 960 ASSERT_TRUE(popup_model->IsOpen());
959 961
960 // Check if the default match result is Search Primary Provider. 962 // Check if the default match result is Search Primary Provider.
961 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 963 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
962 popup_model->result().default_match()->type); 964 popup_model->result().default_match()->type);
963 ASSERT_EQ(kSearchTextURL, 965 ASSERT_EQ(kSearchTextURL,
964 popup_model->result().default_match()->destination_url.spec()); 966 popup_model->result().default_match()->destination_url.spec());
965 967
966 omnibox_view->SetUserText(string16()); 968 omnibox_view->SetUserText(string16());
967 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 969 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
968 ASSERT_FALSE(popup_model->IsOpen()); 970 ASSERT_FALSE(popup_model->IsOpen());
969 971
970 // Try a non-substituting keyword. 972 // Try a non-substituting keyword.
971 template_url_service->Remove(template_url); 973 template_url_service->Remove(template_url);
972 data.short_name = ASCIIToUTF16("abc"); 974 data.short_name = ASCIIToUTF16("abc");
973 data.SetURL("http://abc.com/"); 975 data.SetURL("http://abc.com/");
974 template_url_service->Add(new TemplateURL(data)); 976 template_url_service->Add(new TemplateURL(profile, data));
975 977
976 // We always allow exact matches for non-substituting keywords. 978 // We always allow exact matches for non-substituting keywords.
977 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 979 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
978 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 980 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
979 ASSERT_TRUE(popup_model->IsOpen()); 981 ASSERT_TRUE(popup_model->IsOpen());
980 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD, 982 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD,
981 popup_model->result().default_match()->type); 983 popup_model->result().default_match()->type);
982 ASSERT_EQ("http://abc.com/", 984 ASSERT_EQ("http://abc.com/",
983 popup_model->result().default_match()->destination_url.spec()); 985 popup_model->result().default_match()->destination_url.spec());
984 } 986 }
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 1476
1475 // Paste text. 1477 // Paste text.
1476 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1478 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1477 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1479 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1478 ASSERT_TRUE(popup_model->IsOpen()); 1480 ASSERT_TRUE(popup_model->IsOpen());
1479 1481
1480 // Inline autocomplete shouldn't be triggered. 1482 // Inline autocomplete shouldn't be triggered.
1481 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1483 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1482 } 1484 }
1483 #endif 1485 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698