OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 26 matching lines...) Expand all Loading... |
37 // Add some entries to the search host map. | 37 // Add some entries to the search host map. |
38 host_ = "www.unittest.com"; | 38 host_ = "www.unittest.com"; |
39 t_urls_[0].SetURL("http://" + host_ + "/path1", 0, 0); | 39 t_urls_[0].SetURL("http://" + host_ + "/path1", 0, 0); |
40 t_urls_[1].SetURL("http://" + host_ + "/path2", 0, 0); | 40 t_urls_[1].SetURL("http://" + host_ + "/path2", 0, 0); |
41 | 41 |
42 std::vector<const TemplateURL*> template_urls; | 42 std::vector<const TemplateURL*> template_urls; |
43 template_urls.push_back(&t_urls_[0]); | 43 template_urls.push_back(&t_urls_[0]); |
44 template_urls.push_back(&t_urls_[1]); | 44 template_urls.push_back(&t_urls_[1]); |
45 | 45 |
46 provider_map_.reset(new SearchHostToURLsMap); | 46 provider_map_.reset(new SearchHostToURLsMap); |
47 UIThreadSearchTermsData search_terms_data; | 47 UIThreadSearchTermsData search_terms_data(NULL); |
48 provider_map_->Init(template_urls, search_terms_data); | 48 provider_map_->Init(template_urls, search_terms_data); |
49 } | 49 } |
50 | 50 |
51 TEST_F(SearchHostToURLsMapTest, Add) { | 51 TEST_F(SearchHostToURLsMapTest, Add) { |
52 std::string new_host = "example.com"; | 52 std::string new_host = "example.com"; |
53 TemplateURL new_t_url; | 53 TemplateURL new_t_url; |
54 new_t_url.SetURL("http://" + new_host + "/", 0, 0); | 54 new_t_url.SetURL("http://" + new_host + "/", 0, 0); |
55 UIThreadSearchTermsData search_terms_data; | 55 UIThreadSearchTermsData search_terms_data(NULL); |
56 provider_map_->Add(&new_t_url, search_terms_data); | 56 provider_map_->Add(&new_t_url, search_terms_data); |
57 | 57 |
58 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); | 58 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); |
59 } | 59 } |
60 | 60 |
61 TEST_F(SearchHostToURLsMapTest, Remove) { | 61 TEST_F(SearchHostToURLsMapTest, Remove) { |
62 provider_map_->Remove(&t_urls_[0]); | 62 provider_map_->Remove(&t_urls_[0]); |
63 | 63 |
64 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); | 64 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); |
65 ASSERT_TRUE(found_url == &t_urls_[1]); | 65 ASSERT_TRUE(found_url == &t_urls_[1]); |
66 | 66 |
67 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_); | 67 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_); |
68 ASSERT_TRUE(urls != NULL); | 68 ASSERT_TRUE(urls != NULL); |
69 | 69 |
70 int url_count = 0; | 70 int url_count = 0; |
71 for (TemplateURLSet::const_iterator i = urls->begin(); | 71 for (TemplateURLSet::const_iterator i = urls->begin(); |
72 i != urls->end(); ++i) { | 72 i != urls->end(); ++i) { |
73 url_count++; | 73 url_count++; |
74 ASSERT_TRUE(*i == &t_urls_[1]); | 74 ASSERT_TRUE(*i == &t_urls_[1]); |
75 } | 75 } |
76 ASSERT_EQ(1, url_count); | 76 ASSERT_EQ(1, url_count); |
77 } | 77 } |
78 | 78 |
79 TEST_F(SearchHostToURLsMapTest, Update) { | 79 TEST_F(SearchHostToURLsMapTest, Update) { |
80 std::string new_host = "example.com"; | 80 std::string new_host = "example.com"; |
81 TemplateURL new_values; | 81 TemplateURL new_values; |
82 new_values.SetURL("http://" + new_host + "/", 0, 0); | 82 new_values.SetURL("http://" + new_host + "/", 0, 0); |
83 | 83 |
84 UIThreadSearchTermsData search_terms_data; | 84 UIThreadSearchTermsData search_terms_data(NULL); |
85 provider_map_->Update(&t_urls_[0], new_values, search_terms_data); | 85 provider_map_->Update(&t_urls_[0], new_values, search_terms_data); |
86 | 86 |
87 ASSERT_EQ(&t_urls_[0], provider_map_->GetTemplateURLForHost(new_host)); | 87 ASSERT_EQ(&t_urls_[0], provider_map_->GetTemplateURLForHost(new_host)); |
88 ASSERT_EQ(&t_urls_[1], provider_map_->GetTemplateURLForHost(host_)); | 88 ASSERT_EQ(&t_urls_[1], provider_map_->GetTemplateURLForHost(host_)); |
89 } | 89 } |
90 | 90 |
91 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { | 91 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { |
92 UIThreadSearchTermsData search_terms_data; | 92 UIThreadSearchTermsData search_terms_data(NULL); |
93 std::string google_base_url = "google.com"; | 93 std::string google_base_url = "google.com"; |
94 SetGoogleBaseURL("http://" + google_base_url +"/"); | 94 SetGoogleBaseURL("http://" + google_base_url +"/"); |
95 | 95 |
96 // Add in a url with the templated Google base url. | 96 // Add in a url with the templated Google base url. |
97 TemplateURL new_t_url; | 97 TemplateURL new_t_url; |
98 new_t_url.SetURL("{google:baseURL}?q={searchTerms}", 0, 0); | 98 new_t_url.SetURL("{google:baseURL}?q={searchTerms}", 0, 0); |
99 provider_map_->Add(&new_t_url, search_terms_data); | 99 provider_map_->Add(&new_t_url, search_terms_data); |
100 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); | 100 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); |
101 | 101 |
102 // Now change the Google base url and verify the result. | 102 // Now change the Google base url and verify the result. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 for (size_t i = 0; i < arraysize(found_urls); ++i) | 138 for (size_t i = 0; i < arraysize(found_urls); ++i) |
139 ASSERT_TRUE(found_urls[i]); | 139 ASSERT_TRUE(found_urls[i]); |
140 } | 140 } |
141 | 141 |
142 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { | 142 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { |
143 const TemplateURLSet* urls = provider_map_->GetURLsForHost("a" + host_); | 143 const TemplateURLSet* urls = provider_map_->GetURLsForHost("a" + host_); |
144 ASSERT_TRUE(urls == NULL); | 144 ASSERT_TRUE(urls == NULL); |
145 } | 145 } |
OLD | NEW |