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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/search_engines/util.h » ('j') | chrome/browser/search_engines/util.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/template_url_service_util_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_service_util_unittest.cc b/chrome/browser/search_engines/template_url_service_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0dc2323af2d7ad2b3f3564228e4e1af7ce337301
--- /dev/null
+++ b/chrome/browser/search_engines/template_url_service_util_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Creates a TemplateURL with default values except for the prepopulate ID,
+// keyword and TemplateURLID. Only use this in tests if your tests do not
+// care about other fields. The caller is the owner of this TemplateURL.
+TemplateURL* CreatePrepopulateTemplateURL(int prepopulate_id,
+ const std::string& keyword,
+ TemplateURLID id) {
+ TemplateURLData data;
+ data.prepopulate_id = prepopulate_id;
+ data.SetKeyword(ASCIIToUTF16(keyword));
+ data.id = id;
+ return new TemplateURL(NULL, data);
+}
+
+}; // namespace
+
+TEST(TemplateURLServiceUtilTest, RemoveDuplicatePrepopulateIDs) {
+ std::vector<TemplateURL*> prepopulated_turls;
+ TemplateURLService::TemplateURLVector local_turls;
+
+ prepopulated_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 1));
+ prepopulated_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 2));
+ prepopulated_turls.push_back(CreatePrepopulateTemplateURL(3, "yyy", 3));
+
+ // Create a sets of different TURLs grouped by prepopulate ID. Each group
+ // will test a different heuristic of RemoveDuplicatePrepopulateIDs.
+ // Ignored set - These should be left alone as they do not have valid
+ // prepopulate IDs.
+ local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner1", 4));
+ local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner2", 5));
+ local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner3", 6));
+
+ // Keyword match set - Prefer the one that matches the keyword of the
+ // prepopulate ID.
+ local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser1", 7));
+ local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser2", 8));
+ local_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 9));
+
+ // Default set - Prefer the default search engine over all other criteria.
+ // The last one is the default. It will be passed as the
+ // default_search_provider parameter to RemoveDuplicatePrepopulateIDs.
+ local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser3", 10));
+ local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser4", 11));
+ TemplateURL* default_turl = CreatePrepopulateTemplateURL(2, "winner5", 12);
+ local_turls.push_back(default_turl);
+
+ // ID set - Prefer the lowest TemplateURLID if the keywords don't match and if
+ // none are the default.
+ local_turls.push_back(CreatePrepopulateTemplateURL(3, "winner6", 13));
+ local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser5", 14));
+ local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser6", 15));
+
+ testing::TestRemoveDuplicatePrepopulateIDs(NULL, prepopulated_turls,
+ default_turl, &local_turls, NULL);
+
+ // Verify that the expected local TURLs survived the process.
+ for (TemplateURLService::TemplateURLVector::const_iterator itr =
+ local_turls.begin(); itr != local_turls.end(); ++itr) {
+ EXPECT_TRUE(StartsWith((*itr)->keyword(), ASCIIToUTF16("winner"), true));
+ }
+
+ // Manually clean up, since we own all the remaining TURLs.
+ for (std::vector<TemplateURL*>::iterator itr = prepopulated_turls.begin();
+ itr != prepopulated_turls.end(); ++itr)
+ delete *itr;
+ for (TemplateURLService::TemplateURLVector::iterator itr =
+ local_turls.begin(); itr != local_turls.end(); ++itr)
+ delete *itr;
+}
« 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