Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 const std::string& keyword, | 35 const std::string& keyword, |
| 36 TemplateURLID id) { | 36 TemplateURLID id) { |
| 37 return base::MakeUnique<TemplateURL>( | 37 return base::MakeUnique<TemplateURL>( |
| 38 *CreatePrepopulateTemplateURLData(prepopulate_id, keyword, id)); | 38 *CreatePrepopulateTemplateURLData(prepopulate_id, keyword, id)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 }; // namespace | 41 }; // namespace |
| 42 | 42 |
| 43 TEST(TemplateURLServiceUtilTest, RemoveDuplicatePrepopulateIDs) { | 43 TEST(TemplateURLServiceUtilTest, RemoveDuplicatePrepopulateIDs) { |
| 44 ScopedVector<TemplateURLData> prepopulated_turls; | 44 ScopedVector<TemplateURLData> prepopulated_turls; |
| 45 TemplateURLService::TemplateURLVector local_turls; | 45 TemplateURLService::OwnedTemplateURLVector local_turls; |
| 46 base::STLElementDeleter<TemplateURLService::TemplateURLVector> | |
| 47 local_turls_deleter(&local_turls); | |
| 48 | 46 |
| 49 prepopulated_turls.push_back( | 47 prepopulated_turls.push_back( |
| 50 CreatePrepopulateTemplateURLData(1, "winner4", 1).release()); | 48 CreatePrepopulateTemplateURLData(1, "winner4", 1)); |
| 51 prepopulated_turls.push_back( | 49 prepopulated_turls.push_back(CreatePrepopulateTemplateURLData(2, "xxx", 2)); |
| 52 CreatePrepopulateTemplateURLData(2, "xxx", 2).release()); | 50 prepopulated_turls.push_back(CreatePrepopulateTemplateURLData(3, "yyy", 3)); |
| 53 prepopulated_turls.push_back( | |
| 54 CreatePrepopulateTemplateURLData(3, "yyy", 3).release()); | |
| 55 | 51 |
| 56 // Create a sets of different TURLs grouped by prepopulate ID. Each group | 52 // Create a sets of different TURLs grouped by prepopulate ID. Each group |
| 57 // will test a different heuristic of RemoveDuplicatePrepopulateIDs. | 53 // will test a different heuristic of RemoveDuplicatePrepopulateIDs. |
| 58 // Ignored set - These should be left alone as they do not have valid | 54 // Ignored set - These should be left alone as they do not have valid |
| 59 // prepopulate IDs. | 55 // prepopulate IDs. |
| 60 local_turls.push_back( | 56 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner1", 4)); |
| 61 CreatePrepopulateTemplateURL(0, "winner1", 4).release()); | 57 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner2", 5)); |
| 62 local_turls.push_back( | 58 local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner3", 6)); |
| 63 CreatePrepopulateTemplateURL(0, "winner2", 5).release()); | |
| 64 local_turls.push_back( | |
| 65 CreatePrepopulateTemplateURL(0, "winner3", 6).release()); | |
| 66 size_t num_non_prepopulated_urls = local_turls.size(); | 59 size_t num_non_prepopulated_urls = local_turls.size(); |
| 67 | 60 |
| 68 // Keyword match set - Prefer the one that matches the keyword of the | 61 // Keyword match set - Prefer the one that matches the keyword of the |
| 69 // prepopulate ID. | 62 // prepopulate ID. |
| 70 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser1", 7).release()); | 63 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser1", 7)); |
| 71 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser2", 8).release()); | 64 local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser2", 8)); |
| 72 local_turls.push_back( | 65 local_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 9)); |
| 73 CreatePrepopulateTemplateURL(1, "winner4", 9).release()); | |
| 74 | 66 |
| 75 // Default set - Prefer the default search engine over all other criteria. | 67 // Default set - Prefer the default search engine over all other criteria. |
| 76 // The last one is the default. It will be passed as the | 68 // The last one is the default. It will be passed as the |
| 77 // default_search_provider parameter to RemoveDuplicatePrepopulateIDs. | 69 // default_search_provider parameter to RemoveDuplicatePrepopulateIDs. |
| 78 local_turls.push_back( | 70 local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser3", 10)); |
| 79 CreatePrepopulateTemplateURL(2, "loser3", 10).release()); | 71 local_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 11)); |
| 80 local_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 11).release()); | 72 std::unique_ptr<TemplateURL> default_turl_ptr = |
| 81 TemplateURL* default_turl = | 73 CreatePrepopulateTemplateURL(2, "winner5", 12); |
| 82 CreatePrepopulateTemplateURL(2, "winner5", 12).release(); | 74 TemplateURL* default_turl = default_turl_ptr.get(); |
| 83 local_turls.push_back(default_turl); | 75 local_turls.push_back(std::move(default_turl_ptr)); |
|
Peter Kasting
2016/09/01 08:21:39
Nit: Shorter:
local_turls.push_back(CreatePrepo
Avi (use Gerrit)
2016/09/01 15:14:47
Done.
| |
| 84 | 76 |
| 85 // ID set - Prefer the lowest TemplateURLID if the keywords don't match and if | 77 // ID set - Prefer the lowest TemplateURLID if the keywords don't match and if |
| 86 // none are the default. | 78 // none are the default. |
| 87 local_turls.push_back( | 79 local_turls.push_back(CreatePrepopulateTemplateURL(3, "winner6", 13)); |
| 88 CreatePrepopulateTemplateURL(3, "winner6", 13).release()); | 80 local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser5", 14)); |
| 89 local_turls.push_back( | 81 local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser6", 15)); |
| 90 CreatePrepopulateTemplateURL(3, "loser5", 14).release()); | |
| 91 local_turls.push_back( | |
| 92 CreatePrepopulateTemplateURL(3, "loser6", 15).release()); | |
| 93 | 82 |
| 94 RemoveDuplicatePrepopulateIDs(NULL, prepopulated_turls, default_turl, | 83 RemoveDuplicatePrepopulateIDs(nullptr, prepopulated_turls, default_turl, |
| 95 &local_turls, SearchTermsData(), NULL); | 84 &local_turls, SearchTermsData(), nullptr); |
| 96 | 85 |
| 97 // Verify that the expected local TURLs survived the process. | 86 // Verify that the expected local TURLs survived the process. |
| 98 EXPECT_EQ(local_turls.size(), | 87 EXPECT_EQ(local_turls.size(), |
| 99 prepopulated_turls.size() + num_non_prepopulated_urls); | 88 prepopulated_turls.size() + num_non_prepopulated_urls); |
| 100 for (TemplateURLService::TemplateURLVector::const_iterator itr = | 89 for (const auto& turl : local_turls) { |
| 101 local_turls.begin(); itr != local_turls.end(); ++itr) { | 90 EXPECT_TRUE(base::StartsWith(turl->keyword(), base::ASCIIToUTF16("winner"), |
| 102 EXPECT_TRUE(base::StartsWith((*itr)->keyword(), | |
| 103 base::ASCIIToUTF16("winner"), | |
| 104 base::CompareCase::SENSITIVE)); | 91 base::CompareCase::SENSITIVE)); |
| 105 } | 92 } |
| 106 } | 93 } |
| OLD | NEW |