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

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

Issue 2290503003: Remove use of stl_util in search_engines. (Closed)
Patch Set: ios for reals Created 4 years, 3 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/scoped_observer.h" 11 #include "base/scoped_observer.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/history/history_service_factory.h" 20 #include "chrome/browser/history/history_service_factory.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ASSERT_TRUE(model); 269 ASSERT_TRUE(model);
269 270
270 search_test_utils::WaitForTemplateURLServiceToLoad(model); 271 search_test_utils::WaitForTemplateURLServiceToLoad(model);
271 272
272 ASSERT_TRUE(model->loaded()); 273 ASSERT_TRUE(model->loaded());
273 274
274 TemplateURLData data; 275 TemplateURLData data;
275 data.SetShortName(ASCIIToUTF16(kSearchShortName)); 276 data.SetShortName(ASCIIToUTF16(kSearchShortName));
276 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); 277 data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
277 data.SetURL(kSearchURL); 278 data.SetURL(kSearchURL);
278 TemplateURL* template_url = new TemplateURL(data); 279 std::unique_ptr<TemplateURL> template_url_ptr =
279 model->Add(template_url); 280 base::MakeUnique<TemplateURL>(data);
281 TemplateURL* template_url = template_url_ptr.get();
282 model->Add(std::move(template_url_ptr));
Peter Kasting 2016/08/31 04:12:56 Nit: Just use the old code and add a WrapUnique()
Avi (use Gerrit) 2016/09/01 00:34:26 fixed
280 model->SetUserSelectedDefaultSearchProvider(template_url); 283 model->SetUserSelectedDefaultSearchProvider(template_url);
281 284
282 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); 285 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
283 model->Add(new TemplateURL(data)); 286 model->Add(base::MakeUnique<TemplateURL>(data));
284 287
285 // Remove built-in template urls, like google.com, bing.com etc., as they 288 // Remove built-in template urls, like google.com, bing.com etc., as they
286 // may appear as autocomplete suggests and interfere with our tests. 289 // may appear as autocomplete suggests and interfere with our tests.
287 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); 290 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs();
288 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin(); 291 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin();
289 i != urls.end(); 292 i != urls.end();
290 ++i) { 293 ++i) {
291 if ((*i)->prepopulate_id() != 0) 294 if ((*i)->prepopulate_id() != 0)
292 model->Remove(*i); 295 model->Remove(*i);
293 } 296 }
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 TemplateURLService* template_url_service = 634 TemplateURLService* template_url_service =
632 TemplateURLServiceFactory::GetForProfile(profile); 635 TemplateURLServiceFactory::GetForProfile(profile);
633 636
634 // Add a non-substituting keyword. This ensures the popup will have a 637 // Add a non-substituting keyword. This ensures the popup will have a
635 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we 638 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we
636 // can set "abc" as temporary text in the omnibox. 639 // can set "abc" as temporary text in the omnibox.
637 TemplateURLData data; 640 TemplateURLData data;
638 data.SetShortName(ASCIIToUTF16("abc")); 641 data.SetShortName(ASCIIToUTF16("abc"));
639 data.SetKeyword(ASCIIToUTF16(kSearchText)); 642 data.SetKeyword(ASCIIToUTF16(kSearchText));
640 data.SetURL("http://abc.com/"); 643 data.SetURL("http://abc.com/");
641 template_url_service->Add(new TemplateURL(data)); 644 template_url_service->Add(base::MakeUnique<TemplateURL>(data));
642 645
643 // Send "ab", so that an "abc" entry appears in the popup. 646 // Send "ab", so that an "abc" entry appears in the popup.
644 const ui::KeyboardCode kSearchTextPrefixKeys[] = { 647 const ui::KeyboardCode kSearchTextPrefixKeys[] = {
645 ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN 648 ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN
646 }; 649 };
647 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys)); 650 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys));
648 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 651 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
649 ASSERT_TRUE(popup_model->IsOpen()); 652 ASSERT_TRUE(popup_model->IsOpen());
650 653
651 // Arrow down to the "abc" entry in the popup. 654 // Arrow down to the "abc" entry in the popup.
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 Profile* profile = browser()->profile(); 1110 Profile* profile = browser()->profile();
1108 TemplateURLService* template_url_service = 1111 TemplateURLService* template_url_service =
1109 TemplateURLServiceFactory::GetForProfile(profile); 1112 TemplateURLServiceFactory::GetForProfile(profile);
1110 1113
1111 // Add a non-default substituting keyword. 1114 // Add a non-default substituting keyword.
1112 TemplateURLData data; 1115 TemplateURLData data;
1113 data.SetShortName(ASCIIToUTF16("Search abc")); 1116 data.SetShortName(ASCIIToUTF16("Search abc"));
1114 data.SetKeyword(ASCIIToUTF16(kSearchText)); 1117 data.SetKeyword(ASCIIToUTF16(kSearchText));
1115 data.SetURL("http://abc.com/{searchTerms}"); 1118 data.SetURL("http://abc.com/{searchTerms}");
1116 TemplateURL* template_url = new TemplateURL(data); 1119 TemplateURL* template_url = new TemplateURL(data);
1117 template_url_service->Add(template_url); 1120 template_url_service->Add(base::WrapUnique(template_url));
1118 1121
1119 omnibox_view->SetUserText(base::string16()); 1122 omnibox_view->SetUserText(base::string16());
1120 1123
1121 // Non-default substituting keyword shouldn't be matched by default. 1124 // Non-default substituting keyword shouldn't be matched by default.
1122 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 1125 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1123 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1126 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1124 ASSERT_TRUE(popup_model->IsOpen()); 1127 ASSERT_TRUE(popup_model->IsOpen());
1125 1128
1126 // Check if the default match result is Search Primary Provider. 1129 // Check if the default match result is Search Primary Provider.
1127 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1130 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1128 popup_model->result().default_match()->type); 1131 popup_model->result().default_match()->type);
1129 ASSERT_EQ(kSearchTextURL, 1132 ASSERT_EQ(kSearchTextURL,
1130 popup_model->result().default_match()->destination_url.spec()); 1133 popup_model->result().default_match()->destination_url.spec());
1131 1134
1132 omnibox_view->SetUserText(base::string16()); 1135 omnibox_view->SetUserText(base::string16());
1133 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1136 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1134 ASSERT_FALSE(popup_model->IsOpen()); 1137 ASSERT_FALSE(popup_model->IsOpen());
1135 1138
1136 // Try a non-substituting keyword. 1139 // Try a non-substituting keyword.
1137 template_url_service->Remove(template_url); 1140 template_url_service->Remove(template_url);
1138 data.SetShortName(ASCIIToUTF16("abc")); 1141 data.SetShortName(ASCIIToUTF16("abc"));
1139 data.SetURL("http://abc.com/"); 1142 data.SetURL("http://abc.com/");
1140 template_url_service->Add(new TemplateURL(data)); 1143 template_url_service->Add(base::MakeUnique<TemplateURL>(data));
1141 1144
1142 // We always allow exact matches for non-substituting keywords. 1145 // We always allow exact matches for non-substituting keywords.
1143 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 1146 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1144 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1147 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1145 ASSERT_TRUE(popup_model->IsOpen()); 1148 ASSERT_TRUE(popup_model->IsOpen());
1146 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD, 1149 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD,
1147 popup_model->result().default_match()->type); 1150 popup_model->result().default_match()->type);
1148 ASSERT_EQ("http://abc.com/", 1151 ASSERT_EQ("http://abc.com/",
1149 popup_model->result().default_match()->destination_url.spec()); 1152 popup_model->result().default_match()->destination_url.spec());
1150 } 1153 }
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 1991
1989 // Now Shift+Right should do nothing, and Shift+Left should reduce. 1992 // Now Shift+Right should do nothing, and Shift+Left should reduce.
1990 // At the end, so Shift+Right should do nothing. 1993 // At the end, so Shift+Right should do nothing.
1991 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); 1994 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN));
1992 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); 1995 EXPECT_EQ(2u, GetSelectionSize(omnibox_view));
1993 1996
1994 // And Left should reduce by one character. 1997 // And Left should reduce by one character.
1995 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); 1998 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN));
1996 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); 1999 EXPECT_EQ(1u, GetSelectionSize(omnibox_view));
1997 } 2000 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698