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

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

Issue 10458077: When the Google base URL changes and causes keyword updates, save those to the database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(NULL, 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 provider_map_->Remove(t_urls_[0].get()); 58 UIThreadSearchTermsData search_terms_data(NULL);
59 provider_map_->Remove(t_urls_[0].get(), search_terms_data);
59 60
60 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); 61 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
61 ASSERT_EQ(t_urls_[1].get(), found_url); 62 ASSERT_EQ(t_urls_[1].get(), found_url);
62 63
63 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_); 64 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host_);
64 ASSERT_TRUE(urls != NULL); 65 ASSERT_TRUE(urls != NULL);
65 66
66 int url_count = 0; 67 int url_count = 0;
67 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { 68 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
68 url_count++; 69 url_count++;
69 ASSERT_EQ(t_urls_[1].get(), *i); 70 ASSERT_EQ(t_urls_[1].get(), *i);
70 } 71 }
71 ASSERT_EQ(1, url_count); 72 ASSERT_EQ(1, url_count);
72 } 73 }
73 74
74 TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) {
75 UIThreadSearchTermsData search_terms_data(NULL);
76 std::string google_base_url = "google.com";
77 search_terms_data.SetGoogleBaseURL("http://" + google_base_url +"/");
78
79 // Add in a url with the templated Google base url.
80 TemplateURLData data;
81 data.SetURL("{google:baseURL}?q={searchTerms}");
82 TemplateURL new_t_url(NULL, data);
83 provider_map_->Add(&new_t_url, search_terms_data);
84 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url));
85
86 // Now change the Google base url and verify the result.
87 std::string new_google_base_url = "google.co.uk";
88 search_terms_data.SetGoogleBaseURL("http://" + new_google_base_url +"/");
89 provider_map_->UpdateGoogleBaseURLs(search_terms_data);
90 ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(
91 new_google_base_url));
92 search_terms_data.SetGoogleBaseURL(std::string());
93 }
94
95 TEST_F(SearchHostToURLsMapTest, GetTemplateURLForKnownHost) { 75 TEST_F(SearchHostToURLsMapTest, GetTemplateURLForKnownHost) {
96 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_); 76 const TemplateURL* found_url = provider_map_->GetTemplateURLForHost(host_);
97 ASSERT_TRUE(found_url == t_urls_[0].get() || found_url == t_urls_[1].get()); 77 ASSERT_TRUE(found_url == t_urls_[0].get() || found_url == t_urls_[1].get());
98 } 78 }
99 79
100 TEST_F(SearchHostToURLsMapTest, GetTemplateURLForUnknownHost) { 80 TEST_F(SearchHostToURLsMapTest, GetTemplateURLForUnknownHost) {
101 const TemplateURL* found_url = 81 const TemplateURL* found_url =
102 provider_map_->GetTemplateURLForHost("a" + host_); 82 provider_map_->GetTemplateURLForHost("a" + host_);
103 ASSERT_TRUE(found_url == NULL); 83 ASSERT_TRUE(found_url == NULL);
104 } 84 }
(...skipping 16 matching lines...) Expand all
121 101
122 for (size_t i = 0; i < arraysize(found_urls); ++i) 102 for (size_t i = 0; i < arraysize(found_urls); ++i)
123 ASSERT_TRUE(found_urls[i]); 103 ASSERT_TRUE(found_urls[i]);
124 } 104 }
125 105
126 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) { 106 TEST_F(SearchHostToURLsMapTest, GetURLsForUnknownHost) {
127 const SearchHostToURLsMap::TemplateURLSet* urls = 107 const SearchHostToURLsMap::TemplateURLSet* urls =
128 provider_map_->GetURLsForHost("a" + host_); 108 provider_map_->GetURLsForHost("a" + host_);
129 ASSERT_TRUE(urls == NULL); 109 ASSERT_TRUE(urls == NULL);
130 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698