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

Unified Diff: components/search_engines/search_host_to_urls_map_unittest.cc

Issue 2290503003: Remove use of stl_util in search_engines. (Closed)
Patch Set: ios for reals Created 4 years, 4 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
Index: components/search_engines/search_host_to_urls_map_unittest.cc
diff --git a/components/search_engines/search_host_to_urls_map_unittest.cc b/components/search_engines/search_host_to_urls_map_unittest.cc
index 9d29769a7d810d31400100936d4742089313ea62..eb04a98b151d6f358b3bae760e4c3d7576027b52 100644
--- a/components/search_engines/search_host_to_urls_map_unittest.cc
+++ b/components/search_engines/search_host_to_urls_map_unittest.cc
@@ -9,8 +9,10 @@
#include <memory>
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_service.h"
#include "testing/gtest/include/gtest/gtest.h"
typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
@@ -24,7 +26,7 @@ class SearchHostToURLsMapTest : public testing::Test {
protected:
std::unique_ptr<SearchHostToURLsMap> provider_map_;
- std::unique_ptr<TemplateURL> t_urls_[2];
+ TemplateURLService::OwnedTemplateURLVector template_urls_;
std::string host_;
DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMapTest);
@@ -35,15 +37,12 @@ void SearchHostToURLsMapTest::SetUp() {
host_ = "www.unittest.com";
TemplateURLData data;
data.SetURL("http://" + host_ + "/path1");
- t_urls_[0].reset(new TemplateURL(data));
+ template_urls_.push_back(base::MakeUnique<TemplateURL>(data));
data.SetURL("http://" + host_ + "/path2");
- t_urls_[1].reset(new TemplateURL(data));
- std::vector<TemplateURL*> template_urls;
- template_urls.push_back(t_urls_[0].get());
- template_urls.push_back(t_urls_[1].get());
+ template_urls_.push_back(base::MakeUnique<TemplateURL>(data));
provider_map_.reset(new SearchHostToURLsMap);
- provider_map_->Init(template_urls, SearchTermsData());
+ provider_map_->Init(template_urls_, SearchTermsData());
}
TEST_F(SearchHostToURLsMapTest, Add) {
@@ -57,10 +56,10 @@ TEST_F(SearchHostToURLsMapTest, Add) {
}
TEST_F(SearchHostToURLsMapTest, Remove) {
- provider_map_->Remove(t_urls_[0].get());
+ provider_map_->Remove(template_urls_[0].get());
const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
- ASSERT_EQ(t_urls_[1].get(), found_url);
+ ASSERT_EQ(template_urls_[1].get(), found_url);
const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_);
ASSERT_TRUE(urls != NULL);
@@ -68,14 +67,15 @@ TEST_F(SearchHostToURLsMapTest, Remove) {
int url_count = 0;
for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
url_count++;
- ASSERT_EQ(t_urls_[1].get(), *i);
+ ASSERT_EQ(template_urls_[1].get(), *i);
}
ASSERT_EQ(1, url_count);
}
TEST_F(SearchHostToURLsMapTest, GetTemplateURLForKnownHost) {
const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
- ASSERT_TRUE(found_url == t_urls_[0].get() || found_url == t_urls_[1].get());
+ ASSERT_TRUE(found_url == template_urls_[0].get() ||
+ found_url == template_urls_[1].get());
}
TEST_F(SearchHostToURLsMapTest, GetTemplateURLForUnknownHost) {
@@ -88,19 +88,19 @@ TEST_F(SearchHostToURLsMapTest, GetURLsForKnownHost) {
const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_);
ASSERT_TRUE(urls != NULL);
- bool found_urls[arraysize(t_urls_)] = { false };
+ std::map<size_t, bool> found_urls;
Peter Kasting 2016/08/31 04:12:56 Wow, this function is a mess. Seems like everythi
Avi (use Gerrit) 2016/09/01 00:34:27 Done.
- for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
+ for (auto i = urls->begin(); i != urls->end(); ++i) {
const TemplateURL* url = *i;
- for (size_t i = 0; i < arraysize(found_urls); ++i) {
- if (url == t_urls_[i].get()) {
+ for (size_t i = 0; i < template_urls_.size(); ++i) {
+ if (url == template_urls_[i].get()) {
found_urls[i] = true;
break;
}
}
}
- for (size_t i = 0; i < arraysize(found_urls); ++i)
+ for (size_t i = 0; i < template_urls_.size(); ++i)
ASSERT_TRUE(found_urls[i]);
}

Powered by Google App Engine
This is Rietveld 408576698