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/template_url.h" | 8 #include "chrome/browser/search_engines/template_url.h" |
9 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 9 #include "chrome/browser/search_engines/ui_thread_search_terms_data.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(NULL, data)); | 34 t_urls_[0].reset(new TemplateURL(data)); |
35 data.SetURL("http://" + host_ + "/path2"); | 35 data.SetURL("http://" + host_ + "/path2"); |
36 t_urls_[1].reset(new TemplateURL(NULL, data)); | 36 t_urls_[1].reset(new TemplateURL(data)); |
37 std::vector<TemplateURL*> template_urls; | 37 std::vector<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(NULL); | 42 UIThreadSearchTermsData search_terms_data(NULL); |
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(NULL, data); | 50 TemplateURL new_t_url(data); |
51 UIThreadSearchTermsData search_terms_data(NULL); | 51 UIThreadSearchTermsData search_terms_data(NULL); |
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 UIThreadSearchTermsData search_terms_data(NULL); | 58 UIThreadSearchTermsData search_terms_data(NULL); |
59 provider_map_->Remove(t_urls_[0].get(), search_terms_data); | 59 provider_map_->Remove(t_urls_[0].get(), search_terms_data); |
60 | 60 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 for (size_t i = 0; i < arraysize(found_urls); ++i) | 102 for (size_t i = 0; i < arraysize(found_urls); ++i) |
103 ASSERT_TRUE(found_urls[i]); | 103 ASSERT_TRUE(found_urls[i]); |
104 } | 104 } |
105 | 105 |
106 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { | 106 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { |
107 const SearchHostToURLsMap::TemplateURLSet* urls = | 107 const SearchHostToURLsMap::TemplateURLSet* urls = |
108 provider_map_->GetURLsForHost("a" + host_); | 108 provider_map_->GetURLsForHost("a" + host_); |
109 ASSERT_TRUE(urls == NULL); | 109 ASSERT_TRUE(urls == NULL); |
110 } | 110 } |
OLD | NEW |