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

Side by Side Diff: chrome/browser/search_engines/template_url_service_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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }; 117 };
118 118
119 TestSearchTermsData::TestSearchTermsData(const char* google_base_url) 119 TestSearchTermsData::TestSearchTermsData(const char* google_base_url)
120 : google_base_url_(google_base_url) { 120 : google_base_url_(google_base_url) {
121 } 121 }
122 122
123 std::string TestSearchTermsData::GoogleBaseURLValue() const { 123 std::string TestSearchTermsData::GoogleBaseURLValue() const {
124 return google_base_url_; 124 return google_base_url_;
125 } 125 }
126 126
127
128 // QueryHistoryCallbackImpl ---------------------------------------------------
129
130 struct QueryHistoryCallbackImpl {
131 QueryHistoryCallbackImpl() : success(false) {}
132
133 void Callback(HistoryService::Handle handle,
134 bool success,
135 const history::URLRow* row,
136 history::VisitVector* visits) {
137 this->success = success;
138 if (row)
139 this->row = *row;
140 if (visits)
141 this->visits = *visits;
142 }
143
144 bool success;
145 history::URLRow row;
146 history::VisitVector visits;
147 };
148
127 }; // namespace 149 }; // namespace
128 150
129 151
130 // TemplateURLServiceTest ----------------------------------------------------- 152 // TemplateURLServiceTest -----------------------------------------------------
131 153
132 class TemplateURLServiceTest : public testing::Test { 154 class TemplateURLServiceTest : public testing::Test {
133 public: 155 public:
134 TemplateURLServiceTest(); 156 TemplateURLServiceTest();
135 157
136 // testing::Test 158 // testing::Test
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 test_util_.SetGoogleBaseURL(GURL("http://google.fr/")); 1033 test_util_.SetGoogleBaseURL(GURL("http://google.fr/"));
1012 ASSERT_EQ(manual, model()->GetTemplateURLForHost("google.de")); 1034 ASSERT_EQ(manual, model()->GetTemplateURLForHost("google.de"));
1013 EXPECT_EQ("google.de", manual->url_ref().GetHost()); 1035 EXPECT_EQ("google.de", manual->url_ref().GetHost());
1014 EXPECT_EQ(ASCIIToUTF16("google.de"), manual->keyword()); 1036 EXPECT_EQ(ASCIIToUTF16("google.de"), manual->keyword());
1015 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.fr")); 1037 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.fr"));
1016 EXPECT_TRUE(model()->GetTemplateURLForHost("google.co.uk") == NULL); 1038 EXPECT_TRUE(model()->GetTemplateURLForHost("google.co.uk") == NULL);
1017 EXPECT_EQ("google.fr", t_url->url_ref().GetHost()); 1039 EXPECT_EQ("google.fr", t_url->url_ref().GetHost());
1018 EXPECT_EQ(ASCIIToUTF16("google.fr"), t_url->keyword()); 1040 EXPECT_EQ(ASCIIToUTF16("google.fr"), t_url->keyword());
1019 } 1041 }
1020 1042
1021 struct QueryHistoryCallbackImpl {
1022 QueryHistoryCallbackImpl() : success(false) {}
1023
1024 void Callback(HistoryService::Handle handle,
1025 bool success,
1026 const history::URLRow* row,
1027 history::VisitVector* visits) {
1028 this->success = success;
1029 if (row)
1030 this->row = *row;
1031 if (visits)
1032 this->visits = *visits;
1033 }
1034
1035 bool success;
1036 history::URLRow row;
1037 history::VisitVector visits;
1038 };
1039
1040 // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for 1043 // Make sure TemplateURLService generates a KEYWORD_GENERATED visit for
1041 // KEYWORD visits. 1044 // KEYWORD visits.
1042 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { 1045 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) {
1043 test_util_.VerifyLoad(); 1046 test_util_.VerifyLoad();
1044 test_util_.profile()->CreateHistoryService(true, false); 1047 test_util_.profile()->CreateHistoryService(true, false);
1045 1048
1046 // Create a keyword. 1049 // Create a keyword.
1047 TemplateURL* t_url = AddKeywordWithDate("keyword", "keyword", 1050 TemplateURL* t_url = AddKeywordWithDate("keyword", "keyword",
1048 "http://foo.com/foo?query={searchTerms}", "http://sugg1", "http://icon1", 1051 "http://foo.com/foo?query={searchTerms}", "http://sugg1", "http://icon1",
1049 true, "UTF-8;UTF-16", base::Time::Now(), base::Time::Now()); 1052 true, "UTF-8;UTF-16", base::Time::Now(), base::Time::Now());
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1422
1420 // Reload the model to verify it was actually saved to the database and 1423 // Reload the model to verify it was actually saved to the database and
1421 // assigned a new GUID when brought back. 1424 // assigned a new GUID when brought back.
1422 test_util_.ResetModel(true); 1425 test_util_.ResetModel(true);
1423 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1426 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1424 const TemplateURL* loaded_url = 1427 const TemplateURL* loaded_url =
1425 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1428 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1426 ASSERT_TRUE(loaded_url != NULL); 1429 ASSERT_TRUE(loaded_url != NULL);
1427 ASSERT_FALSE(loaded_url->sync_guid().empty()); 1430 ASSERT_FALSE(loaded_url->sync_guid().empty());
1428 } 1431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698