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

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

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thread safe handling of Profiles Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/test/base/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 13 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
13 14
14 // Basic functionality for the SearchHostToURLsMap tests. 15 // Basic functionality for the SearchHostToURLsMap tests.
15 class SearchHostToURLsMapTest : public testing::Test { 16 class SearchHostToURLsMapTest : public testing::Test {
16 public: 17 public:
17 SearchHostToURLsMapTest() {} 18 SearchHostToURLsMapTest() {}
18 19
19 virtual void SetUp(); 20 virtual void SetUp();
20 virtual void TearDown() { 21 virtual void TearDown() {
21 TemplateURLRef::SetGoogleBaseURL(NULL); 22 TemplateURLRef::SetGoogleBaseURL(NULL);
22 } 23 }
23 24
24 protected: 25 protected:
25 void SetGoogleBaseURL(const std::string& base_url) const { 26 void SetGoogleBaseURL(const std::string& base_url) const {
26 TemplateURLRef::SetGoogleBaseURL(new std::string(base_url)); 27 TemplateURLRef::SetGoogleBaseURL(new std::string(base_url));
27 } 28 }
28 29
29 scoped_ptr<SearchHostToURLsMap> provider_map_; 30 scoped_ptr<SearchHostToURLsMap> provider_map_;
30 TemplateURL t_urls_[2]; 31 TemplateURL t_urls_[2];
31 std::string host_; 32 std::string host_;
33 TestingProfile profile_;
Peter Kasting 2011/08/10 20:54:06 You don't need this. None of the SearchHostToURLs
32 34
33 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMapTest); 35 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMapTest);
34 }; 36 };
35 37
36 void SearchHostToURLsMapTest::SetUp() { 38 void SearchHostToURLsMapTest::SetUp() {
37 // Add some entries to the search host map. 39 // Add some entries to the search host map.
38 host_ = "www.unittest.com"; 40 host_ = "www.unittest.com";
39 t_urls_[0].SetURL("http://" + host_ + "/path1", 0, 0); 41 t_urls_[0].SetURL("http://" + host_ + "/path1", 0, 0);
40 t_urls_[1].SetURL("http://" + host_ + "/path2", 0, 0); 42 t_urls_[1].SetURL("http://" + host_ + "/path2", 0, 0);
41 43
42 std::vector<const TemplateURL*> template_urls; 44 std::vector<const TemplateURL*> template_urls;
43 template_urls.push_back(&t_urls_[0]); 45 template_urls.push_back(&t_urls_[0]);
44 template_urls.push_back(&t_urls_[1]); 46 template_urls.push_back(&t_urls_[1]);
45 47
46 provider_map_.reset(new SearchHostToURLsMap); 48 provider_map_.reset(new SearchHostToURLsMap);
47 UIThreadSearchTermsData search_terms_data; 49 UIThreadSearchTermsData search_terms_data(&profile_);
48 provider_map_->Init(template_urls, search_terms_data); 50 provider_map_->Init(template_urls, search_terms_data);
49 } 51 }
50 52
51 TEST_F(SearchHostToURLsMapTest, Add) { 53 TEST_F(SearchHostToURLsMapTest, Add) {
52 std::string new_host = "example.com"; 54 std::string new_host = "example.com";
53 TemplateURL new_t_url; 55 TemplateURL new_t_url;
54 new_t_url.SetURL("http://" + new_host + "/", 0, 0); 56 new_t_url.SetURL("http://" + new_host + "/", 0, 0);
55 UIThreadSearchTermsData search_terms_data; 57 UIThreadSearchTermsData search_terms_data(&profile_);
56 provider_map_->Add(&new_t_url, search_terms_data); 58 provider_map_->Add(&new_t_url, search_terms_data);
57 59
58 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host)); 60 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host));
59 } 61 }
60 62
61 TEST_F(SearchHostToURLsMapTest, Remove) { 63 TEST_F(SearchHostToURLsMapTest, Remove) {
62 provider_map_->Remove(&t_urls_[0]); 64 provider_map_->Remove(&t_urls_[0], &profile_);
63 65
64 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); 66 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
65 ASSERT_TRUE(found_url == &t_urls_[1]); 67 ASSERT_TRUE(found_url == &t_urls_[1]);
66 68
67 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_); 69 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_);
68 ASSERT_TRUE(urls != NULL); 70 ASSERT_TRUE(urls != NULL);
69 71
70 int url_count = 0; 72 int url_count = 0;
71 for (TemplateURLSet::const_iterator i = urls->begin(); 73 for (TemplateURLSet::const_iterator i = urls->begin();
72 i != urls->end(); ++i) { 74 i != urls->end(); ++i) {
73 url_count++; 75 url_count++;
74 ASSERT_TRUE(*i == &t_urls_[1]); 76 ASSERT_TRUE(*i == &t_urls_[1]);
75 } 77 }
76 ASSERT_EQ(1, url_count); 78 ASSERT_EQ(1, url_count);
77 } 79 }
78 80
79 TEST_F(SearchHostToURLsMapTest, Update) { 81 TEST_F(SearchHostToURLsMapTest, Update) {
80 std::string new_host = "example.com"; 82 std::string new_host = "example.com";
81 TemplateURL new_values; 83 TemplateURL new_values;
82 new_values.SetURL("http://" + new_host + "/", 0, 0); 84 new_values.SetURL("http://" + new_host + "/", 0, 0);
83 85
84 UIThreadSearchTermsData search_terms_data; 86 UIThreadSearchTermsData search_terms_data(&profile_);
85 provider_map_->Update(&t_urls_[0], new_values, search_terms_data); 87 provider_map_->Update(&t_urls_[0], new_values, search_terms_data, &profile_);
86 88
87 ASSERT_EQ(&t_urls_[0], provider_map_->GetTemplateURLForHost(new_host)); 89 ASSERT_EQ(&t_urls_[0], provider_map_->GetTemplateURLForHost(new_host));
88 ASSERT_EQ(&t_urls_[1], provider_map_->GetTemplateURLForHost(host_)); 90 ASSERT_EQ(&t_urls_[1], provider_map_->GetTemplateURLForHost(host_));
89 } 91 }
90 92
91 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) { 93 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) {
92 UIThreadSearchTermsData search_terms_data; 94 UIThreadSearchTermsData search_terms_data(&profile_);
93 std::string google_base_url = "google.com"; 95 std::string google_base_url = "google.com";
94 SetGoogleBaseURL("http://" + google_base_url +"/"); 96 SetGoogleBaseURL("http://" + google_base_url +"/");
95 97
96 // Add in a url with the templated Google base url. 98 // Add in a url with the templated Google base url.
97 TemplateURL new_t_url; 99 TemplateURL new_t_url;
98 new_t_url.SetURL("{google:baseURL}?q={searchTerms}", 0, 0); 100 new_t_url.SetURL("{google:baseURL}?q={searchTerms}", 0, 0);
99 provider_map_->Add(&new_t_url, search_terms_data); 101 provider_map_->Add(&new_t_url, search_terms_data);
100 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url)); 102 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url));
101 103
102 // Now change the Google base url and verify the result. 104 // Now change the Google base url and verify the result.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 138 }
137 139
138 for (size_t i = 0; i < arraysize(found_urls); ++i) 140 for (size_t i = 0; i < arraysize(found_urls); ++i)
139 ASSERT_TRUE(found_urls[i]); 141 ASSERT_TRUE(found_urls[i]);
140 } 142 }
141 143
142 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { 144 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) {
143 const TemplateURLSet* urls = provider_map_->GetURLsForHost("a" + host_); 145 const TemplateURLSet* urls = provider_map_->GetURLsForHost("a" + host_);
144 ASSERT_TRUE(urls == NULL); 146 ASSERT_TRUE(urls == NULL);
145 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698