OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/sql/connection.h" | 5 #include "app/sql/connection.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 118 matching lines...) Loading... |
129 URLRow url_info1(url1); | 129 URLRow url_info1(url1); |
130 url_info1.set_title(UTF8ToUTF16("Google")); | 130 url_info1.set_title(UTF8ToUTF16("Google")); |
131 url_info1.set_visit_count(4); | 131 url_info1.set_visit_count(4); |
132 url_info1.set_typed_count(2); | 132 url_info1.set_typed_count(2); |
133 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 133 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
134 url_info1.set_hidden(false); | 134 url_info1.set_hidden(false); |
135 URLID url_id = AddURL(url_info1); | 135 URLID url_id = AddURL(url_info1); |
136 ASSERT_TRUE(url_id != 0); | 136 ASSERT_TRUE(url_id != 0); |
137 | 137 |
138 // Add a keyword visit. | 138 // Add a keyword visit. |
139 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit"))); | 139 TemplateURLID keyword_id = 100; |
| 140 string16 keyword = UTF8ToUTF16("visit"); |
| 141 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, keyword_id, keyword)); |
140 | 142 |
141 // Make sure we get it back. | 143 // Make sure we get it back. |
142 std::vector<KeywordSearchTermVisit> matches; | 144 std::vector<KeywordSearchTermVisit> matches; |
143 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); | 145 GetMostRecentKeywordSearchTerms(keyword_id, keyword, 10, &matches); |
144 ASSERT_EQ(1U, matches.size()); | 146 ASSERT_EQ(1U, matches.size()); |
145 ASSERT_EQ(UTF8ToUTF16("visit"), matches[0].term); | 147 ASSERT_EQ(keyword, matches[0].term); |
| 148 |
| 149 KeywordSearchTermRow keyword_search_term_row; |
| 150 ASSERT_TRUE(GetKeywordSearchTermRow(url_id, &keyword_search_term_row)); |
| 151 EXPECT_EQ(keyword_id, keyword_search_term_row.keyword_id); |
| 152 EXPECT_EQ(url_id, keyword_search_term_row.url_id); |
| 153 EXPECT_EQ(keyword, keyword_search_term_row.term); |
146 | 154 |
147 // Delete the keyword visit. | 155 // Delete the keyword visit. |
148 DeleteAllSearchTermsForKeyword(1); | 156 DeleteAllSearchTermsForKeyword(keyword_id); |
149 | 157 |
150 // Make sure we don't get it back when querying. | 158 // Make sure we don't get it back when querying. |
151 matches.clear(); | 159 matches.clear(); |
152 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); | 160 GetMostRecentKeywordSearchTerms(keyword_id, keyword, 10, &matches); |
153 ASSERT_EQ(0U, matches.size()); | 161 ASSERT_EQ(0U, matches.size()); |
| 162 |
| 163 ASSERT_FALSE(GetKeywordSearchTermRow(url_id, &keyword_search_term_row)); |
154 } | 164 } |
155 | 165 |
156 // Make sure deleting a URL also deletes a keyword visit. | 166 // Make sure deleting a URL also deletes a keyword visit. |
157 TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) { | 167 TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) { |
158 const GURL url1("http://www.google.com/"); | 168 const GURL url1("http://www.google.com/"); |
159 URLRow url_info1(url1); | 169 URLRow url_info1(url1); |
160 url_info1.set_title(UTF8ToUTF16("Google")); | 170 url_info1.set_title(UTF8ToUTF16("Google")); |
161 url_info1.set_visit_count(4); | 171 url_info1.set_visit_count(4); |
162 url_info1.set_typed_count(2); | 172 url_info1.set_typed_count(2); |
163 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 173 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
164 url_info1.set_hidden(false); | 174 url_info1.set_hidden(false); |
165 URLID url_id = AddURL(url_info1); | 175 URLID url_id = AddURL(url_info1); |
166 ASSERT_TRUE(url_id != 0); | 176 ASSERT_TRUE(url_id != 0); |
167 | 177 |
168 // Add a keyword visit. | 178 // Add a keyword visit. |
169 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit"))); | 179 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit"))); |
170 | 180 |
171 // Delete the url. | 181 // Delete the url. |
172 ASSERT_TRUE(DeleteURLRow(url_id)); | 182 ASSERT_TRUE(DeleteURLRow(url_id)); |
173 | 183 |
174 // Make sure the keyword visit was deleted. | 184 // Make sure the keyword visit was deleted. |
175 std::vector<KeywordSearchTermVisit> matches; | 185 std::vector<KeywordSearchTermVisit> matches; |
176 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); | 186 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); |
177 ASSERT_EQ(0U, matches.size()); | 187 ASSERT_EQ(0U, matches.size()); |
178 } | 188 } |
179 | 189 |
180 } // namespace history | 190 } // namespace history |
OLD | NEW |