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

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

Issue 10021008: Reland r131019: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 7 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
8 #include "chrome/browser/search_engines/search_terms_data.h" 8 #include "chrome/browser/search_engines/search_terms_data.h"
9 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 11 matching lines...) Expand all
22 scoped_ptr<SearchHostToURLsMap> provider_map_; 22 scoped_ptr<SearchHostToURLsMap> provider_map_;
23 scoped_ptr<TemplateURL> t_urls_[2]; 23 scoped_ptr<TemplateURL> t_urls_[2];
24 std::string host_; 24 std::string host_;
25 25
26 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMapTest); 26 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMapTest);
27 }; 27 };
28 28
29 void SearchHostToURLsMapTest::SetUp() { 29 void SearchHostToURLsMapTest::SetUp() {
30 // Add some entries to the search host map. 30 // Add some entries to the search host map.
31 host_ = "www.unittest.com"; 31 host_ = "www.unittest.com";
32 t_urls_[0].reset(new TemplateURL()); 32 TemplateURLData data;
33 t_urls_[0]->SetURL("http://" + host_ + "/path1"); 33 data.SetURL("http://" + host_ + "/path1");
34 t_urls_[1].reset(new TemplateURL()); 34 t_urls_[0].reset(new TemplateURL(data));
35 t_urls_[1]->SetURL("http://" + host_ + "/path2"); 35 data.SetURL("http://" + host_ + "/path2");
36 36 t_urls_[1].reset(new TemplateURL(data));
37 std::vector<const TemplateURL*> template_urls; 37 std::vector<const TemplateURL*> template_urls;
38 template_urls.push_back(t_urls_[0].get()); 38 template_urls.push_back(t_urls_[0].get());
39 template_urls.push_back(t_urls_[1].get()); 39 template_urls.push_back(t_urls_[1].get());
40 40
41 provider_map_.reset(new SearchHostToURLsMap); 41 provider_map_.reset(new SearchHostToURLsMap);
42 UIThreadSearchTermsData search_terms_data; 42 UIThreadSearchTermsData search_terms_data;
43 provider_map_->Init(template_urls, search_terms_data); 43 provider_map_->Init(template_urls, search_terms_data);
44 } 44 }
45 45
46 TEST_F(SearchHostToURLsMapTest, Add) { 46 TEST_F(SearchHostToURLsMapTest, Add) {
47 std::string new_host = "example.com"; 47 std::string new_host = "example.com";
48 TemplateURL new_t_url; 48 TemplateURLData data;
49 new_t_url.SetURL("http://" + new_host + "/"); 49 data.SetURL("http://" + new_host + "/");
50 TemplateURL new_t_url(data);
50 UIThreadSearchTermsData search_terms_data; 51 UIThreadSearchTermsData search_terms_data;
51 provider_map_->Add(&new_t_url, search_terms_data); 52 provider_map_->Add(&new_t_url, search_terms_data);
52 53
53 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); 54 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host));
54 } 55 }
55 56
56 TEST_F(SearchHostToURLsMapTest, Remove) { 57 TEST_F(SearchHostToURLsMapTest, Remove) {
57 provider_map_->Remove(t_urls_[0].get()); 58 provider_map_->Remove(t_urls_[0].get());
58 59
59 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); 60 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
60 ASSERT_EQ(t_urls_[1].get(), found_url); 61 ASSERT_EQ(t_urls_[1].get(), found_url);
61 62
62 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_); 63 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_);
63 ASSERT_TRUE(urls != NULL); 64 ASSERT_TRUE(urls != NULL);
64 65
65 int url_count = 0; 66 int url_count = 0;
66 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { 67 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
67 url_count++; 68 url_count++;
68 ASSERT_EQ(t_urls_[1].get(), *i); 69 ASSERT_EQ(t_urls_[1].get(), *i);
69 } 70 }
70 ASSERT_EQ(1, url_count); 71 ASSERT_EQ(1, url_count);
71 } 72 }
72 73
73 TEST_F(SearchHostToURLsMapTest, Update) {
74 std::string new_host = "example.com";
75 TemplateURL new_values;
76 new_values.SetURL("http://" + new_host + "/");
77
78 UIThreadSearchTermsData search_terms_data;
79 provider_map_->Update(t_urls_[0].get(), new_values, search_terms_data);
80
81 ASSERT_EQ(t_urls_[0].get(), provider_map_->GetTemplateURLForHost(new_host));
82 ASSERT_EQ(t_urls_[1].get(), provider_map_->GetTemplateURLForHost(host_));
83 }
84
85 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { 74 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) {
86 UIThreadSearchTermsData search_terms_data; 75 UIThreadSearchTermsData search_terms_data;
87 std::string google_base_url = "google.com"; 76 std::string google_base_url = "google.com";
88 search_terms_data.SetGoogleBaseURL( 77 search_terms_data.SetGoogleBaseURL(
89 new std::string("http://" + google_base_url +"/")); 78 new std::string("http://" + google_base_url +"/"));
90 79
91 // Add in a url with the templated Google base url. 80 // Add in a url with the templated Google base url.
92 TemplateURL new_t_url; 81 TemplateURLData data;
93 new_t_url.SetURL("{google:baseURL}?q={searchTerms}"); 82 data.SetURL("{google:baseURL}?q={searchTerms}");
83 TemplateURL new_t_url(data);
94 provider_map_->Add(&new_t_url, search_terms_data); 84 provider_map_->Add(&new_t_url, search_terms_data);
95 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); 85 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url));
96 86
97 // Now change the Google base url and verify the result. 87 // Now change the Google base url and verify the result.
98 std::string new_google_base_url = "google.co.uk"; 88 std::string new_google_base_url = "google.co.uk";
99 search_terms_data.SetGoogleBaseURL( 89 search_terms_data.SetGoogleBaseURL(
100 new std::string("http://" + new_google_base_url +"/")); 90 new std::string("http://" + new_google_base_url +"/"));
101 provider_map_->UpdateGoogleBaseURLs(search_terms_data); 91 provider_map_->UpdateGoogleBaseURLs(search_terms_data);
102 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost( 92 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(
103 new_google_base_url)); 93 new_google_base_url));
(...skipping 29 matching lines...) Expand all
133 123
134 for (size_t i = 0; i < arraysize(found_urls); ++i) 124 for (size_t i = 0; i < arraysize(found_urls); ++i)
135 ASSERT_TRUE(found_urls[i]); 125 ASSERT_TRUE(found_urls[i]);
136 } 126 }
137 127
138 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { 128 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) {
139 const SearchHostToURLsMap::TemplateURLSet* urls = 129 const SearchHostToURLsMap::TemplateURLSet* urls =
140 provider_map_->GetURLsForHost("a" + host_); 130 provider_map_->GetURLsForHost("a" + host_);
141 ASSERT_TRUE(urls == NULL); 131 ASSERT_TRUE(urls == NULL);
142 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698