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

Side by Side Diff: chrome/browser/search_engines/template_url_service_util_unittest.cc

Issue 10409002: Make prepopulated-TemplateURL-de-duper heuristic smarter. Instead of blindly preserving the first U… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: merge to TOT + fixes Created 8 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/search_engines/template_url.h"
8 #include "chrome/browser/search_engines/template_url_service.h"
9 #include "chrome/browser/search_engines/util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 // Creates a TemplateURL with default values except for the prepopulate ID,
15 // keyword and TemplateURLID. Only use this in tests if your tests do not
16 // care about other fields. The caller is the owner of this TemplateURL.
17 TemplateURL* CreatePrepopulateTemplateURL(int prepopulate_id,
18 const std::string& keyword,
19 TemplateURLID id) {
20 TemplateURLData data;
21 data.prepopulate_id = prepopulate_id;
22 data.SetKeyword(ASCIIToUTF16(keyword));
23 data.id = id;
24 return new TemplateURL(NULL, data);
25 }
26
27 }; // namespace
28
29 TEST(TemplateURLServiceUtilTest, RemoveDuplicatePrepopulateIDs) {
30 std::vector<TemplateURL*> prepopulated_turls;
31 TemplateURLService::TemplateURLVector local_turls;
32
33 prepopulated_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 1));
34 prepopulated_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 2));
35 prepopulated_turls.push_back(CreatePrepopulateTemplateURL(3, "yyy", 3));
36
37 // Create a sets of different TURLs grouped by prepopulate ID. Each group
38 // will test a different heuristic of RemoveDuplicatePrepopulateIDs.
39 // Ignored set - These should be left alone as they do not have valid
40 // prepopulate IDs.
41 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner1", 4));
42 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner2", 5));
43 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner3", 6));
44
45 // Keyword match set - Prefer the one that matches the keyword of the
46 // prepopulate ID.
47 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser1", 7));
48 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser2", 8));
49 local_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 9));
50
51 // Default set - Prefer the default search engine over all other criteria.
52 // The last one is the default. It will be passed as the
53 // default_search_provider parameter to RemoveDuplicatePrepopulateIDs.
54 local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser3", 10));
55 local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser4", 11));
56 TemplateURL* default_turl = CreatePrepopulateTemplateURL(2, "winner5", 12);
57 local_turls.push_back(default_turl);
58
59 // ID set - Prefer the lowest TemplateURLID if the keywords don't match and if
60 // none are the default.
61 local_turls.push_back(CreatePrepopulateTemplateURL(3, "winner6", 13));
62 local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser5", 14));
63 local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser6", 15));
64
65 testing::TestRemoveDuplicatePrepopulateIDs(NULL, prepopulated_turls,
66 default_turl, &local_turls, NULL);
67
68 // Verify that the expected local TURLs survived the process.
69 for (TemplateURLService::TemplateURLVector::const_iterator itr =
70 local_turls.begin(); itr != local_turls.end(); ++itr) {
71 EXPECT_TRUE(StartsWith((*itr)->keyword(), ASCIIToUTF16("winner"), true));
72 }
73
74 // Manually clean up, since we own all the remaining TURLs.
75 for (std::vector<TemplateURL*>::iterator itr = prepopulated_turls.begin();
76 itr != prepopulated_turls.end(); ++itr)
77 delete *itr;
78 for (TemplateURLService::TemplateURLVector::iterator itr =
79 local_turls.begin(); itr != local_turls.end(); ++itr)
80 delete *itr;
81 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/util.h » ('j') | chrome/browser/search_engines/util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698