OLD | NEW |
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 13 matching lines...) Expand all Loading... |
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 TemplateURLData data; | 32 TemplateURLData data; |
33 data.SetURL("http://" + host_ + "/path1"); | 33 data.SetURL("http://" + host_ + "/path1"); |
34 t_urls_[0].reset(new TemplateURL(data)); | 34 t_urls_[0].reset(new TemplateURL(NULL, data)); |
35 data.SetURL("http://" + host_ + "/path2"); | 35 data.SetURL("http://" + host_ + "/path2"); |
36 t_urls_[1].reset(new TemplateURL(data)); | 36 t_urls_[1].reset(new TemplateURL(NULL, 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 TemplateURLData data; | 48 TemplateURLData data; |
49 data.SetURL("http://" + new_host + "/"); | 49 data.SetURL("http://" + new_host + "/"); |
50 TemplateURL new_t_url(data); | 50 TemplateURL new_t_url(NULL, data); |
51 UIThreadSearchTermsData search_terms_data; | 51 UIThreadSearchTermsData search_terms_data; |
52 provider_map_->Add(&new_t_url, search_terms_data); | 52 provider_map_->Add(&new_t_url, search_terms_data); |
53 | 53 |
54 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); | 54 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); |
55 } | 55 } |
56 | 56 |
57 TEST_F(SearchHostToURLsMapTest, Remove) { | 57 TEST_F(SearchHostToURLsMapTest, Remove) { |
58 provider_map_->Remove(t_urls_[0].get()); | 58 provider_map_->Remove(t_urls_[0].get()); |
59 | 59 |
60 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); | 60 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); |
(...skipping 11 matching lines...) Expand all Loading... |
72 } | 72 } |
73 | 73 |
74 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { | 74 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { |
75 UIThreadSearchTermsData search_terms_data; | 75 UIThreadSearchTermsData search_terms_data; |
76 std::string google_base_url = "google.com"; | 76 std::string google_base_url = "google.com"; |
77 search_terms_data.SetGoogleBaseURL("http://" + google_base_url +"/"); | 77 search_terms_data.SetGoogleBaseURL("http://" + google_base_url +"/"); |
78 | 78 |
79 // Add in a url with the templated Google base url. | 79 // Add in a url with the templated Google base url. |
80 TemplateURLData data; | 80 TemplateURLData data; |
81 data.SetURL("{google:baseURL}?q={searchTerms}"); | 81 data.SetURL("{google:baseURL}?q={searchTerms}"); |
82 TemplateURL new_t_url(data); | 82 TemplateURL new_t_url(NULL, data); |
83 provider_map_->Add(&new_t_url, search_terms_data); | 83 provider_map_->Add(&new_t_url, search_terms_data); |
84 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); | 84 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); |
85 | 85 |
86 // Now change the Google base url and verify the result. | 86 // Now change the Google base url and verify the result. |
87 std::string new_google_base_url = "google.co.uk"; | 87 std::string new_google_base_url = "google.co.uk"; |
88 search_terms_data.SetGoogleBaseURL("http://" + new_google_base_url +"/"); | 88 search_terms_data.SetGoogleBaseURL("http://" + new_google_base_url +"/"); |
89 provider_map_->UpdateGoogleBaseURLs(search_terms_data); | 89 provider_map_->UpdateGoogleBaseURLs(search_terms_data); |
90 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost( | 90 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost( |
91 new_google_base_url)); | 91 new_google_base_url)); |
92 search_terms_data.SetGoogleBaseURL(std::string()); | 92 search_terms_data.SetGoogleBaseURL(std::string()); |
(...skipping 28 matching lines...) Expand all Loading... |
121 | 121 |
122 for (size_t i = 0; i < arraysize(found_urls); ++i) | 122 for (size_t i = 0; i < arraysize(found_urls); ++i) |
123 ASSERT_TRUE(found_urls[i]); | 123 ASSERT_TRUE(found_urls[i]); |
124 } | 124 } |
125 | 125 |
126 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { | 126 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { |
127 const SearchHostToURLsMap::TemplateURLSet* urls = | 127 const SearchHostToURLsMap::TemplateURLSet* urls = |
128 provider_map_->GetURLsForHost("a" + host_); | 128 provider_map_->GetURLsForHost("a" + host_); |
129 ASSERT_TRUE(urls == NULL); | 129 ASSERT_TRUE(urls == NULL); |
130 } | 130 } |
OLD | NEW |