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

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

Issue 9982018: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us to eliminate t… (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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 ASSERT_TRUE(model->loaded()); 279 ASSERT_TRUE(model->loaded());
280 // Remove built-in template urls, like google.com, bing.com etc., as they 280 // Remove built-in template urls, like google.com, bing.com etc., as they
281 // may appear as autocomplete suggests and interfere with our tests. 281 // may appear as autocomplete suggests and interfere with our tests.
282 model->SetDefaultSearchProvider(NULL); 282 model->SetDefaultSearchProvider(NULL);
283 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs(); 283 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs();
284 for (TemplateURLService::TemplateURLVector::const_iterator 284 for (TemplateURLService::TemplateURLVector::const_iterator
285 i = builtins.begin(); i != builtins.end(); ++i) 285 i = builtins.begin(); i != builtins.end(); ++i)
286 model->Remove(*i); 286 model->Remove(*i);
287 287
288 TemplateURL* template_url = new TemplateURL(); 288 TemplateURLData data;
289 template_url->SetURL(kSearchURL); 289 data.short_name = ASCIIToUTF16(kSearchShortName);
290 template_url->set_keyword(ASCIIToUTF16(kSearchKeyword)); 290 data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
291 template_url->set_short_name(ASCIIToUTF16(kSearchShortName)); 291 data.SetURL(kSearchURL);
292 TemplateURL* template_url = new TemplateURL(data);
292 model->Add(template_url); 293 model->Add(template_url);
293 model->SetDefaultSearchProvider(template_url); 294 model->SetDefaultSearchProvider(template_url);
294 295
295 TemplateURL* second_url = new TemplateURL(); 296 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
296 second_url->SetURL(kSearchURL); 297 model->Add(new TemplateURL(data));
297 second_url->set_keyword(ASCIIToUTF16(kSearchKeyword2));
298 second_url->set_short_name(ASCIIToUTF16(kSearchShortName));
299 model->Add(second_url);
300 } 298 }
301 299
302 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { 300 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
303 Profile* profile = browser()->profile(); 301 Profile* profile = browser()->profile();
304 HistoryService* history_service = 302 HistoryService* history_service =
305 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 303 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
306 ASSERT_TRUE(history_service); 304 ASSERT_TRUE(history_service);
307 305
308 if (!history_service->BackendLoaded()) { 306 if (!history_service->BackendLoaded()) {
309 content::NotificationRegistrar registrar; 307 content::NotificationRegistrar registrar;
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 void NonSubstitutingKeywordTest() { 936 void NonSubstitutingKeywordTest() {
939 OmniboxView* omnibox_view = NULL; 937 OmniboxView* omnibox_view = NULL;
940 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 938 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
941 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model(); 939 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
942 ASSERT_TRUE(popup_model); 940 ASSERT_TRUE(popup_model);
943 941
944 TemplateURLService* template_url_service = 942 TemplateURLService* template_url_service =
945 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 943 TemplateURLServiceFactory::GetForProfile(browser()->profile());
946 944
947 // Add a non-default substituting keyword. 945 // Add a non-default substituting keyword.
948 TemplateURL* template_url = new TemplateURL(); 946 TemplateURLData data;
949 template_url->SetURL("http://abc.com/{searchTerms}"); 947 data.short_name = ASCIIToUTF16("Search abc");
950 template_url->set_keyword(UTF8ToUTF16(kSearchText)); 948 data.SetKeyword(ASCIIToUTF16(kSearchText));
951 template_url->set_short_name(UTF8ToUTF16("Search abc")); 949 data.SetURL("http://abc.com/{searchTerms}");
950 TemplateURL* template_url = new TemplateURL(data);
952 template_url_service->Add(template_url); 951 template_url_service->Add(template_url);
953 952
954 omnibox_view->SetUserText(string16()); 953 omnibox_view->SetUserText(string16());
955 954
956 // Non-default substituting keyword shouldn't be matched by default. 955 // Non-default substituting keyword shouldn't be matched by default.
957 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 956 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
958 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 957 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
959 ASSERT_TRUE(popup_model->IsOpen()); 958 ASSERT_TRUE(popup_model->IsOpen());
960 959
961 // Check if the default match result is Search Primary Provider. 960 // Check if the default match result is Search Primary Provider.
962 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 961 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
963 popup_model->result().default_match()->type); 962 popup_model->result().default_match()->type);
964 ASSERT_EQ(kSearchTextURL, 963 ASSERT_EQ(kSearchTextURL,
965 popup_model->result().default_match()->destination_url.spec()); 964 popup_model->result().default_match()->destination_url.spec());
966 965
967 omnibox_view->SetUserText(string16()); 966 omnibox_view->SetUserText(string16());
968 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 967 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
969 ASSERT_FALSE(popup_model->IsOpen()); 968 ASSERT_FALSE(popup_model->IsOpen());
970 969
971 // Try a non-substituting keyword. 970 // Try a non-substituting keyword.
972 template_url_service->Remove(template_url); 971 template_url_service->Remove(template_url);
973 template_url = new TemplateURL(); 972 data.short_name = ASCIIToUTF16("abc");
974 template_url->SetURL("http://abc.com/"); 973 data.SetURL("http://abc.com/");
975 template_url->set_keyword(UTF8ToUTF16(kSearchText)); 974 template_url_service->Add(new TemplateURL(data));
976 template_url->set_short_name(UTF8ToUTF16("abc"));
977 template_url_service->Add(template_url);
978 975
979 // We always allow exact matches for non-substituting keywords. 976 // We always allow exact matches for non-substituting keywords.
980 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 977 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
981 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 978 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
982 ASSERT_TRUE(popup_model->IsOpen()); 979 ASSERT_TRUE(popup_model->IsOpen());
983 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD, 980 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD,
984 popup_model->result().default_match()->type); 981 popup_model->result().default_match()->type);
985 ASSERT_EQ("http://abc.com/", 982 ASSERT_EQ("http://abc.com/",
986 popup_model->result().default_match()->destination_url.spec()); 983 popup_model->result().default_match()->destination_url.spec());
987 } 984 }
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 1474
1478 // Paste text. 1475 // Paste text.
1479 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1476 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1480 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1477 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1481 ASSERT_TRUE(popup_model->IsOpen()); 1478 ASSERT_TRUE(popup_model->IsOpen());
1482 1479
1483 // Inline autocomplete shouldn't be triggered. 1480 // Inline autocomplete shouldn't be triggered.
1484 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1481 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1485 } 1482 }
1486 #endif 1483 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698