OLD | NEW |
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 <stdio.h> | |
6 | |
7 #include <fstream> | 5 #include <fstream> |
8 #include <string> | |
9 #include <vector> | |
10 | 6 |
11 #include "base/file_path.h" | 7 #include "base/file_path.h" |
12 #include "base/file_util.h" | 8 #include "base/file_util.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string16.h" |
15 #include "base/string_util.h" | 11 #include "base/string_util.h" |
16 #include "base/time.h" | |
17 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/history/in_memory_database.h" | 13 #include "chrome/browser/history/in_memory_database.h" |
19 #include "chrome/browser/history/in_memory_url_index.h" | 14 #include "chrome/browser/history/in_memory_url_index.h" |
| 15 #include "chrome/browser/history/in_memory_url_index_types.h" |
20 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
21 #include "sql/connection.h" | |
22 #include "sql/statement.h" | |
23 #include "sql/transaction.h" | 17 #include "sql/transaction.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
25 | 19 |
26 // The test version of the history url database table ('url') is contained in | 20 // The test version of the history url database table ('url') is contained in |
27 // a database file created from a text file('url_history_provider_test.db.txt'). | 21 // a database file created from a text file('url_history_provider_test.db.txt'). |
28 // The only difference between this table and a live 'urls' table from a | 22 // The only difference between this table and a live 'urls' table from a |
29 // profile is that the last_visit_time column in the test table contains a | 23 // profile is that the last_visit_time column in the test table contains a |
30 // number specifying the number of days relative to 'today' to which the | 24 // number specifying the number of days relative to 'today' to which the |
31 // absolute time should be set during the test setup stage. | 25 // absolute time should be set during the test setup stage. |
32 // | 26 // |
(...skipping 19 matching lines...) Expand all Loading... |
52 // Convenience function to create a URLRow with basic data for |url|, |title|, | 46 // Convenience function to create a URLRow with basic data for |url|, |title|, |
53 // |visit_count|, and |typed_count|. |last_visit_ago| gives the number of | 47 // |visit_count|, and |typed_count|. |last_visit_ago| gives the number of |
54 // days from now to set the URL's last_visit. | 48 // days from now to set the URL's last_visit. |
55 URLRow MakeURLRow(const char* url, | 49 URLRow MakeURLRow(const char* url, |
56 const char* title, | 50 const char* title, |
57 int visit_count, | 51 int visit_count, |
58 int last_visit_ago, | 52 int last_visit_ago, |
59 int typed_count); | 53 int typed_count); |
60 | 54 |
61 // Convenience functions for easily creating vectors of search terms. | 55 // Convenience functions for easily creating vectors of search terms. |
62 InMemoryURLIndex::String16Vector Make1Term(const char* term) const; | 56 String16Vector Make1Term(const char* term) const; |
63 InMemoryURLIndex::String16Vector Make2Terms(const char* term_1, | 57 String16Vector Make2Terms(const char* term_1, const char* term_2) const; |
64 const char* term_2) const; | |
65 | 58 |
66 // Validates that the given |term| is contained in |cache| and that it is | 59 // Validates that the given |term| is contained in |cache| and that it is |
67 // marked as in-use. | 60 // marked as in-use. |
68 void CheckTerm(const InMemoryURLIndex::SearchTermCacheMap& cache, | 61 void CheckTerm(const InMemoryURLIndex::SearchTermCacheMap& cache, |
69 string16 term) const; | 62 string16 term) const; |
70 | 63 |
71 scoped_ptr<InMemoryURLIndex> url_index_; | 64 scoped_ptr<InMemoryURLIndex> url_index_; |
72 }; | 65 }; |
73 | 66 |
74 void InMemoryURLIndexTest::SetUp() { | 67 void InMemoryURLIndexTest::SetUp() { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 int typed_count) { | 131 int typed_count) { |
139 URLRow row(GURL(url), 0); | 132 URLRow row(GURL(url), 0); |
140 row.set_title(UTF8ToUTF16(title)); | 133 row.set_title(UTF8ToUTF16(title)); |
141 row.set_visit_count(visit_count); | 134 row.set_visit_count(visit_count); |
142 row.set_typed_count(typed_count); | 135 row.set_typed_count(typed_count); |
143 row.set_last_visit(base::Time::NowFromSystemTime() - | 136 row.set_last_visit(base::Time::NowFromSystemTime() - |
144 base::TimeDelta::FromDays(last_visit_ago)); | 137 base::TimeDelta::FromDays(last_visit_ago)); |
145 return row; | 138 return row; |
146 } | 139 } |
147 | 140 |
148 InMemoryURLIndex::String16Vector InMemoryURLIndexTest::Make1Term( | 141 String16Vector InMemoryURLIndexTest::Make1Term(const char* term) const { |
149 const char* term) const { | 142 String16Vector original_terms; |
150 InMemoryURLIndex::String16Vector terms; | 143 original_terms.push_back(UTF8ToUTF16(term)); |
151 terms.push_back(UTF8ToUTF16(term)); | 144 return original_terms; |
152 return terms; | |
153 } | 145 } |
154 | 146 |
155 InMemoryURLIndex::String16Vector InMemoryURLIndexTest::Make2Terms( | 147 String16Vector InMemoryURLIndexTest::Make2Terms(const char* term_1, |
156 const char* term_1, | 148 const char* term_2) const { |
157 const char* term_2) const { | 149 String16Vector original_terms; |
158 InMemoryURLIndex::String16Vector terms; | 150 original_terms.push_back(UTF8ToUTF16(term_1)); |
159 terms.push_back(UTF8ToUTF16(term_1)); | 151 original_terms.push_back(UTF8ToUTF16(term_2)); |
160 terms.push_back(UTF8ToUTF16(term_2)); | 152 return original_terms; |
161 return terms; | |
162 } | 153 } |
163 | 154 |
164 void InMemoryURLIndexTest::CheckTerm( | 155 void InMemoryURLIndexTest::CheckTerm( |
165 const InMemoryURLIndex::SearchTermCacheMap& cache, | 156 const InMemoryURLIndex::SearchTermCacheMap& cache, |
166 string16 term) const { | 157 string16 term) const { |
167 InMemoryURLIndex::SearchTermCacheMap::const_iterator cache_iter( | 158 InMemoryURLIndex::SearchTermCacheMap::const_iterator cache_iter( |
168 cache.find(term)); | 159 cache.find(term)); |
169 ASSERT_NE(cache.end(), cache_iter) | 160 ASSERT_NE(cache.end(), cache_iter) |
170 << "Cache does not contain '" << term << "' but should."; | 161 << "Cache does not contain '" << term << "' but should."; |
171 InMemoryURLIndex::SearchTermCacheItem cache_item = cache_iter->second; | 162 InMemoryURLIndex::SearchTermCacheItem cache_item = cache_iter->second; |
172 EXPECT_TRUE(cache_item.used_) | 163 EXPECT_TRUE(cache_item.used_) |
173 << "Cache item '" << term << "' should be marked as being in use."; | 164 << "Cache item '" << term << "' should be marked as being in use."; |
174 } | 165 } |
175 | 166 |
| 167 // Helper function which compares two maps for equivalence. The maps' values |
| 168 // are associative containers and their contents are compared as well. |
| 169 template<typename T> |
| 170 void ExpectMapOfContainersIdentical(const T& expected, const T& actual) { |
| 171 ASSERT_EQ(expected.size(), actual.size()); |
| 172 for (typename T::const_iterator expected_iter = expected.begin(); |
| 173 expected_iter != expected.end(); ++expected_iter) { |
| 174 typename T::const_iterator actual_iter = actual.find(expected_iter->first); |
| 175 ASSERT_NE(actual.end(), actual_iter); |
| 176 typename T::mapped_type const& expected_values(expected_iter->second); |
| 177 typename T::mapped_type const& actual_values(actual_iter->second); |
| 178 ASSERT_EQ(expected_values.size(), actual_values.size()); |
| 179 for (typename T::mapped_type::const_iterator set_iter = |
| 180 expected_values.begin(); set_iter != expected_values.end(); ++set_iter) |
| 181 EXPECT_EQ(actual_values.count(*set_iter), |
| 182 expected_values.count(*set_iter)); |
| 183 } |
| 184 } |
| 185 |
| 186 //------------------------------------------------------------------------------ |
| 187 |
176 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { | 188 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { |
177 protected: | 189 protected: |
178 FilePath::StringType TestDBName() const; | 190 FilePath::StringType TestDBName() const; |
179 }; | 191 }; |
180 | 192 |
181 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { | 193 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { |
182 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); | 194 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); |
183 } | 195 } |
184 | 196 |
185 class ExpandedInMemoryURLIndexTest : public InMemoryURLIndexTest { | 197 class ExpandedInMemoryURLIndexTest : public InMemoryURLIndexTest { |
(...skipping 24 matching lines...) Expand all Loading... |
210 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { | 222 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { |
211 // Verify that the database contains the expected number of items, which | 223 // Verify that the database contains the expected number of items, which |
212 // is the pre-filtered count, i.e. all of the items. | 224 // is the pre-filtered count, i.e. all of the items. |
213 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); | 225 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); |
214 EXPECT_TRUE(statement); | 226 EXPECT_TRUE(statement); |
215 uint64 row_count = 0; | 227 uint64 row_count = 0; |
216 while (statement.Step()) ++row_count; | 228 while (statement.Step()) ++row_count; |
217 EXPECT_EQ(1U, row_count); | 229 EXPECT_EQ(1U, row_count); |
218 url_index_.reset(new InMemoryURLIndex(FilePath())); | 230 url_index_.reset(new InMemoryURLIndex(FilePath())); |
219 url_index_->Init(this, "en,ja,hi,zh"); | 231 url_index_->Init(this, "en,ja,hi,zh"); |
220 EXPECT_EQ(1, url_index_->history_item_count_); | 232 URLIndexPrivateData& private_data(*(url_index_->private_data_)); |
221 | 233 |
222 // history_info_map_ should have the same number of items as were filtered. | 234 // history_info_map_ should have the same number of items as were filtered. |
223 EXPECT_EQ(1U, url_index_->history_info_map_.size()); | 235 EXPECT_EQ(1U, private_data.history_info_map_.size()); |
224 EXPECT_EQ(35U, url_index_->char_word_map_.size()); | 236 EXPECT_EQ(35U, private_data.char_word_map_.size()); |
225 EXPECT_EQ(17U, url_index_->word_map_.size()); | 237 EXPECT_EQ(17U, private_data.word_map_.size()); |
226 } | 238 } |
227 | 239 |
228 TEST_F(InMemoryURLIndexTest, Retrieval) { | 240 TEST_F(InMemoryURLIndexTest, Retrieval) { |
229 url_index_.reset(new InMemoryURLIndex(FilePath())); | 241 url_index_.reset(new InMemoryURLIndex(FilePath())); |
230 url_index_->Init(this, "en,ja,hi,zh"); | 242 url_index_->Init(this, "en,ja,hi,zh"); |
231 // The term will be lowercased by the search. | 243 // The term will be lowercased by the search. |
232 | 244 |
233 // See if a very specific term gives a single result. | 245 // See if a very specific term gives a single result. |
234 ScoredHistoryMatches matches = | 246 ScoredHistoryMatches matches = |
235 url_index_->HistoryItemsForTerms(Make1Term("DrudgeReport")); | 247 url_index_->HistoryItemsForTerms(Make1Term("DrudgeReport")); |
(...skipping 16 matching lines...) Expand all Loading... |
252 ASSERT_EQ(1U, matches.size()); | 264 ASSERT_EQ(1U, matches.size()); |
253 // The results should have a very high score. | 265 // The results should have a very high score. |
254 EXPECT_GT(matches[0].raw_score, 900); | 266 EXPECT_GT(matches[0].raw_score, 900); |
255 EXPECT_EQ(32, matches[0].url_info.id()); | 267 EXPECT_EQ(32, matches[0].url_info.id()); |
256 EXPECT_EQ("https://nearlyperfectresult.com/", | 268 EXPECT_EQ("https://nearlyperfectresult.com/", |
257 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 269 matches[0].url_info.url().spec()); // Note: URL gets lowercased. |
258 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), | 270 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), |
259 matches[0].url_info.title()); | 271 matches[0].url_info.title()); |
260 | 272 |
261 // Search which should result in very poor result. | 273 // Search which should result in very poor result. |
262 InMemoryURLIndex::String16Vector terms; | 274 String16Vector original_terms; |
263 terms.push_back(ASCIIToUTF16("z")); | 275 original_terms.push_back(ASCIIToUTF16("z")); |
264 terms.push_back(ASCIIToUTF16("y")); | 276 original_terms.push_back(ASCIIToUTF16("y")); |
265 terms.push_back(ASCIIToUTF16("x")); | 277 original_terms.push_back(ASCIIToUTF16("x")); |
266 matches = url_index_->HistoryItemsForTerms(terms); | 278 matches = url_index_->HistoryItemsForTerms(original_terms); |
267 ASSERT_EQ(1U, matches.size()); | 279 ASSERT_EQ(1U, matches.size()); |
268 // The results should have a poor score. | 280 // The results should have a poor score. |
269 EXPECT_LT(matches[0].raw_score, 500); | 281 EXPECT_LT(matches[0].raw_score, 500); |
270 EXPECT_EQ(33, matches[0].url_info.id()); | 282 EXPECT_EQ(33, matches[0].url_info.id()); |
271 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", | 283 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", |
272 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 284 matches[0].url_info.url().spec()); // Note: URL gets lowercased. |
273 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), | 285 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), |
274 matches[0].url_info.title()); | 286 matches[0].url_info.title()); |
275 | 287 |
276 // Search which will match at the end of an URL with encoded characters. | 288 // Search which will match at the end of an URL with encoded characters. |
(...skipping 12 matching lines...) Expand all Loading... |
289 | 301 |
290 // A search for 'working' should not short-circuit. | 302 // A search for 'working' should not short-circuit. |
291 matches = url_index_->HistoryItemsForTerms(Make1Term("working")); | 303 matches = url_index_->HistoryItemsForTerms(Make1Term("working")); |
292 EXPECT_EQ(1U, matches.size()); | 304 EXPECT_EQ(1U, matches.size()); |
293 } | 305 } |
294 | 306 |
295 TEST_F(InMemoryURLIndexTest, TitleSearch) { | 307 TEST_F(InMemoryURLIndexTest, TitleSearch) { |
296 url_index_.reset(new InMemoryURLIndex(FilePath())); | 308 url_index_.reset(new InMemoryURLIndex(FilePath())); |
297 url_index_->Init(this, "en,ja,hi,zh"); | 309 url_index_->Init(this, "en,ja,hi,zh"); |
298 // Signal if someone has changed the test DB. | 310 // Signal if someone has changed the test DB. |
299 EXPECT_EQ(27U, url_index_->history_info_map_.size()); | 311 EXPECT_EQ(27U, url_index_->private_data_->history_info_map_.size()); |
300 InMemoryURLIndex::String16Vector terms; | 312 String16Vector original_terms; |
301 | 313 |
302 // Ensure title is being searched. | 314 // Ensure title is being searched. |
303 terms.push_back(ASCIIToUTF16("MORTGAGE")); | 315 original_terms.push_back(ASCIIToUTF16("MORTGAGE")); |
304 terms.push_back(ASCIIToUTF16("RATE")); | 316 original_terms.push_back(ASCIIToUTF16("RATE")); |
305 terms.push_back(ASCIIToUTF16("DROPS")); | 317 original_terms.push_back(ASCIIToUTF16("DROPS")); |
306 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms); | 318 ScoredHistoryMatches matches = |
| 319 url_index_->HistoryItemsForTerms(original_terms); |
307 ASSERT_EQ(1U, matches.size()); | 320 ASSERT_EQ(1U, matches.size()); |
308 | 321 |
309 // Verify that we got back the result we expected. | 322 // Verify that we got back the result we expected. |
310 EXPECT_EQ(1, matches[0].url_info.id()); | 323 EXPECT_EQ(1, matches[0].url_info.id()); |
311 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 324 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", |
312 matches[0].url_info.url().spec()); | 325 matches[0].url_info.url().spec()); |
313 EXPECT_EQ(ASCIIToUTF16( | 326 EXPECT_EQ(ASCIIToUTF16( |
314 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 327 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), |
315 matches[0].url_info.title()); | 328 matches[0].url_info.title()); |
316 } | 329 } |
317 | 330 |
| 331 TEST_F(InMemoryURLIndexTest, TitleChange) { |
| 332 url_index_.reset(new InMemoryURLIndex(FilePath())); |
| 333 url_index_->Init(this, "en,ja,hi,zh"); |
| 334 |
| 335 // Verify current title terms retrieves desired item. |
| 336 String16Vector original_terms; |
| 337 original_terms.push_back(ASCIIToUTF16("lebronomics")); |
| 338 original_terms.push_back(ASCIIToUTF16("could")); |
| 339 original_terms.push_back(ASCIIToUTF16("high")); |
| 340 original_terms.push_back(ASCIIToUTF16("taxes")); |
| 341 original_terms.push_back(ASCIIToUTF16("influence")); |
| 342 ScoredHistoryMatches matches = |
| 343 url_index_->HistoryItemsForTerms(original_terms); |
| 344 ASSERT_EQ(1U, matches.size()); |
| 345 |
| 346 // Verify that we got back the result we expected. |
| 347 const URLID expected_id = 3; |
| 348 EXPECT_EQ(expected_id, matches[0].url_info.id()); |
| 349 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", |
| 350 matches[0].url_info.url().spec()); |
| 351 EXPECT_EQ(ASCIIToUTF16( |
| 352 "LeBronomics: Could High Taxes Influence James' Team Decision?"), |
| 353 matches[0].url_info.title()); |
| 354 URLRow old_row(matches[0].url_info); |
| 355 |
| 356 // Verify new title terms retrieves nothing. |
| 357 String16Vector new_terms; |
| 358 new_terms.push_back(ASCIIToUTF16("does")); |
| 359 new_terms.push_back(ASCIIToUTF16("eat")); |
| 360 new_terms.push_back(ASCIIToUTF16("oats")); |
| 361 new_terms.push_back(ASCIIToUTF16("little")); |
| 362 new_terms.push_back(ASCIIToUTF16("lambs")); |
| 363 new_terms.push_back(ASCIIToUTF16("ivy")); |
| 364 matches = url_index_->HistoryItemsForTerms(new_terms); |
| 365 ASSERT_EQ(0U, matches.size()); |
| 366 |
| 367 // Update the row. |
| 368 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); |
| 369 url_index_->UpdateURL(expected_id, old_row); |
| 370 |
| 371 // Verify we get the row using the new terms but not the original terms. |
| 372 matches = url_index_->HistoryItemsForTerms(new_terms); |
| 373 ASSERT_EQ(1U, matches.size()); |
| 374 EXPECT_EQ(expected_id, matches[0].url_info.id()); |
| 375 matches = url_index_->HistoryItemsForTerms(original_terms); |
| 376 ASSERT_EQ(0U, matches.size()); |
| 377 } |
| 378 |
318 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { | 379 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { |
319 url_index_.reset(new InMemoryURLIndex(FilePath())); | 380 url_index_.reset(new InMemoryURLIndex(FilePath())); |
320 url_index_->Init(this, "en,ja,hi,zh"); | 381 url_index_->Init(this, "en,ja,hi,zh"); |
321 | 382 |
322 // The presence of duplicate characters should succeed. Exercise by cycling | 383 // The presence of duplicate characters should succeed. Exercise by cycling |
323 // through a string with several duplicate characters. | 384 // through a string with several duplicate characters. |
324 ScoredHistoryMatches matches = | 385 ScoredHistoryMatches matches = |
325 url_index_->HistoryItemsForTerms(Make1Term("ABRA")); | 386 url_index_->HistoryItemsForTerms(Make1Term("ABRA")); |
326 ASSERT_EQ(1U, matches.size()); | 387 ASSERT_EQ(1U, matches.size()); |
327 EXPECT_EQ(28, matches[0].url_info.id()); | 388 EXPECT_EQ(28, matches[0].url_info.id()); |
(...skipping 10 matching lines...) Expand all Loading... |
338 | 399 |
339 matches = url_index_->HistoryItemsForTerms(Make1Term("ABRACADABR")); | 400 matches = url_index_->HistoryItemsForTerms(Make1Term("ABRACADABR")); |
340 ASSERT_EQ(1U, matches.size()); | 401 ASSERT_EQ(1U, matches.size()); |
341 EXPECT_EQ(28, matches[0].url_info.id()); | 402 EXPECT_EQ(28, matches[0].url_info.id()); |
342 | 403 |
343 matches = url_index_->HistoryItemsForTerms(Make1Term("ABRACA")); | 404 matches = url_index_->HistoryItemsForTerms(Make1Term("ABRACA")); |
344 ASSERT_EQ(1U, matches.size()); | 405 ASSERT_EQ(1U, matches.size()); |
345 EXPECT_EQ(28, matches[0].url_info.id()); | 406 EXPECT_EQ(28, matches[0].url_info.id()); |
346 } | 407 } |
347 | 408 |
348 TEST_F(InMemoryURLIndexTest, StaticFunctions) { | |
349 // Test WordVectorFromString16 | |
350 string16 string_a(ASCIIToUTF16("http://www.google.com/ frammy the brammy")); | |
351 InMemoryURLIndex::String16Vector string_vec = | |
352 InMemoryURLIndex::WordVectorFromString16(string_a, false); | |
353 ASSERT_EQ(7U, string_vec.size()); | |
354 // See if we got the words we expected. | |
355 EXPECT_EQ(UTF8ToUTF16("http"), string_vec[0]); | |
356 EXPECT_EQ(UTF8ToUTF16("www"), string_vec[1]); | |
357 EXPECT_EQ(UTF8ToUTF16("google"), string_vec[2]); | |
358 EXPECT_EQ(UTF8ToUTF16("com"), string_vec[3]); | |
359 EXPECT_EQ(UTF8ToUTF16("frammy"), string_vec[4]); | |
360 EXPECT_EQ(UTF8ToUTF16("the"), string_vec[5]); | |
361 EXPECT_EQ(UTF8ToUTF16("brammy"), string_vec[6]); | |
362 | |
363 string_vec = InMemoryURLIndex::WordVectorFromString16(string_a, true); | |
364 ASSERT_EQ(5U, string_vec.size()); | |
365 EXPECT_EQ(UTF8ToUTF16("http://"), string_vec[0]); | |
366 EXPECT_EQ(UTF8ToUTF16("www.google.com/"), string_vec[1]); | |
367 EXPECT_EQ(UTF8ToUTF16("frammy"), string_vec[2]); | |
368 EXPECT_EQ(UTF8ToUTF16("the"), string_vec[3]); | |
369 EXPECT_EQ(UTF8ToUTF16("brammy"), string_vec[4]); | |
370 | |
371 // Test WordSetFromString16 | |
372 string16 string_b(ASCIIToUTF16( | |
373 "http://web.google.com/search Google Web Search")); | |
374 InMemoryURLIndex::String16Set string_set = | |
375 InMemoryURLIndex::WordSetFromString16(string_b); | |
376 EXPECT_EQ(5U, string_set.size()); | |
377 // See if we got the words we expected. | |
378 EXPECT_TRUE(string_set.find(UTF8ToUTF16("com")) != string_set.end()); | |
379 EXPECT_TRUE(string_set.find(UTF8ToUTF16("google")) != string_set.end()); | |
380 EXPECT_TRUE(string_set.find(UTF8ToUTF16("http")) != string_set.end()); | |
381 EXPECT_TRUE(string_set.find(UTF8ToUTF16("search")) != string_set.end()); | |
382 EXPECT_TRUE(string_set.find(UTF8ToUTF16("web")) != string_set.end()); | |
383 | |
384 // Test SortAndDeoverlap | |
385 TermMatches matches_a; | |
386 matches_a.push_back(TermMatch(1, 13, 10)); | |
387 matches_a.push_back(TermMatch(2, 23, 10)); | |
388 matches_a.push_back(TermMatch(3, 3, 10)); | |
389 matches_a.push_back(TermMatch(4, 40, 5)); | |
390 TermMatches matches_b = InMemoryURLIndex::SortAndDeoverlap(matches_a); | |
391 // Nothing should have been eliminated. | |
392 EXPECT_EQ(matches_a.size(), matches_b.size()); | |
393 // The order should now be 3, 1, 2, 4. | |
394 EXPECT_EQ(3, matches_b[0].term_num); | |
395 EXPECT_EQ(1, matches_b[1].term_num); | |
396 EXPECT_EQ(2, matches_b[2].term_num); | |
397 EXPECT_EQ(4, matches_b[3].term_num); | |
398 matches_a.push_back(TermMatch(5, 18, 10)); | |
399 matches_a.push_back(TermMatch(6, 38, 5)); | |
400 matches_b = InMemoryURLIndex::SortAndDeoverlap(matches_a); | |
401 // Two matches should have been eliminated. | |
402 EXPECT_EQ(matches_a.size() - 2, matches_b.size()); | |
403 // The order should now be 3, 1, 2, 6. | |
404 EXPECT_EQ(3, matches_b[0].term_num); | |
405 EXPECT_EQ(1, matches_b[1].term_num); | |
406 EXPECT_EQ(2, matches_b[2].term_num); | |
407 EXPECT_EQ(6, matches_b[3].term_num); | |
408 | |
409 // Test MatchTermInString | |
410 TermMatches matches_c = InMemoryURLIndex::MatchTermInString( | |
411 UTF8ToUTF16("x"), UTF8ToUTF16("axbxcxdxex fxgx/hxixjx.kx"), 123); | |
412 ASSERT_EQ(11U, matches_c.size()); | |
413 const size_t expected_offsets[] = { 1, 3, 5, 7, 9, 12, 14, 17, 19, 21, 24 }; | |
414 for (int i = 0; i < 11; ++i) | |
415 EXPECT_EQ(expected_offsets[i], matches_c[i].offset); | |
416 } | |
417 | |
418 TEST_F(InMemoryURLIndexTest, OffsetsAndTermMatches) { | |
419 // Test OffsetsFromTermMatches | |
420 history::TermMatches matches_a; | |
421 matches_a.push_back(history::TermMatch(1, 1, 2)); | |
422 matches_a.push_back(history::TermMatch(2, 4, 3)); | |
423 matches_a.push_back(history::TermMatch(3, 9, 1)); | |
424 matches_a.push_back(history::TermMatch(3, 10, 1)); | |
425 matches_a.push_back(history::TermMatch(4, 14, 5)); | |
426 std::vector<size_t> offsets = | |
427 InMemoryURLIndex::OffsetsFromTermMatches(matches_a); | |
428 const size_t expected_offsets_a[] = {1, 4, 9, 10, 14}; | |
429 ASSERT_EQ(offsets.size(), arraysize(expected_offsets_a)); | |
430 for (size_t i = 0; i < offsets.size(); ++i) | |
431 EXPECT_EQ(expected_offsets_a[i], offsets[i]); | |
432 | |
433 // Test ReplaceOffsetsInTermMatches | |
434 offsets[2] = string16::npos; | |
435 history::TermMatches matches_b = | |
436 InMemoryURLIndex::ReplaceOffsetsInTermMatches(matches_a, offsets); | |
437 const size_t expected_offsets_b[] = {1, 4, 10, 14}; | |
438 ASSERT_EQ(arraysize(expected_offsets_b), matches_b.size()); | |
439 for (size_t i = 0; i < matches_b.size(); ++i) | |
440 EXPECT_EQ(expected_offsets_b[i], matches_b[i].offset); | |
441 } | |
442 | |
443 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { | 409 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { |
444 // Verify that match results for previously typed characters are retained | 410 // Verify that match results for previously typed characters are retained |
445 // (in the term_char_word_set_cache_) and reused, if possible, in future | 411 // (in the term_char_word_set_cache_) and reused, if possible, in future |
446 // autocompletes. | 412 // autocompletes. |
447 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter; | 413 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter; |
448 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem; | 414 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem; |
449 | 415 |
450 url_index_.reset(new InMemoryURLIndex(FilePath())); | 416 url_index_.reset(new InMemoryURLIndex(FilePath())); |
451 url_index_->Init(this, "en,ja,hi,zh"); | 417 url_index_->Init(this, "en,ja,hi,zh"); |
452 | 418 |
453 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_); | 419 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_); |
454 | 420 |
455 // The cache should be empty at this point. | 421 // The cache should be empty at this point. |
456 EXPECT_EQ(0U, cache.size()); | 422 EXPECT_EQ(0U, cache.size()); |
457 | 423 |
458 // Now simulate typing search terms into the omnibox and check the state of | 424 // Now simulate typing search terms into the omnibox and check the state of |
459 // the cache as each item is 'typed'. | 425 // the cache as each item is 'typed'. |
460 | 426 |
461 // Simulate typing "r" giving "r" in the simulated omnibox. The results for | 427 // Simulate typing "r" giving "r" in the simulated omnibox. The results for |
462 // 'r' will be not cached because it is only 1 character long. | 428 // 'r' will be not cached because it is only 1 character long. |
463 InMemoryURLIndex::String16Vector terms; | 429 String16Vector original_terms; |
464 string16 term_r = ASCIIToUTF16("r"); | 430 string16 term_r = ASCIIToUTF16("r"); |
465 terms.push_back(term_r); | 431 original_terms.push_back(term_r); |
466 url_index_->HistoryItemsForTerms(terms); | 432 url_index_->HistoryItemsForTerms(original_terms); |
467 EXPECT_EQ(0U, cache.size()); | 433 EXPECT_EQ(0U, cache.size()); |
468 | 434 |
469 // Simulate typing "re" giving "r re" in the simulated omnibox. | 435 // Simulate typing "re" giving "r re" in the simulated omnibox. |
470 string16 term_re = ASCIIToUTF16("re"); | 436 string16 term_re = ASCIIToUTF16("re"); |
471 terms.push_back(term_re); | 437 original_terms.push_back(term_re); |
472 // 're' should be cached at this point but not 'r' as it is a single | 438 // 're' should be cached at this point but not 'r' as it is a single |
473 // character. | 439 // character. |
474 ASSERT_EQ(2U, terms.size()); | 440 ASSERT_EQ(2U, original_terms.size()); |
475 url_index_->HistoryItemsForTerms(terms); | 441 url_index_->HistoryItemsForTerms(original_terms); |
476 ASSERT_EQ(1U, cache.size()); | 442 ASSERT_EQ(1U, cache.size()); |
477 CheckTerm(cache, term_re); | 443 CheckTerm(cache, term_re); |
478 | 444 |
479 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. | 445 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. |
480 string16 term_reco = ASCIIToUTF16("reco"); | 446 string16 term_reco = ASCIIToUTF16("reco"); |
481 terms.push_back(term_reco); | 447 original_terms.push_back(term_reco); |
482 // 're' and 'reco' should be cached at this point but not 'r' as it is a | 448 // 're' and 'reco' should be cached at this point but not 'r' as it is a |
483 // single character. | 449 // single character. |
484 url_index_->HistoryItemsForTerms(terms); | 450 url_index_->HistoryItemsForTerms(original_terms); |
485 ASSERT_EQ(2U, cache.size()); | 451 ASSERT_EQ(2U, cache.size()); |
486 CheckTerm(cache, term_re); | 452 CheckTerm(cache, term_re); |
487 CheckTerm(cache, term_reco); | 453 CheckTerm(cache, term_reco); |
488 | 454 |
489 terms.clear(); // Simulate pressing <ESC>. | 455 original_terms.clear(); // Simulate pressing <ESC>. |
490 | 456 |
491 // Simulate typing "mort". | 457 // Simulate typing "mort". |
492 string16 term_mort = ASCIIToUTF16("mort"); | 458 string16 term_mort = ASCIIToUTF16("mort"); |
493 terms.push_back(term_mort); | 459 original_terms.push_back(term_mort); |
494 // Since we now have only one search term, the cached results for 're' and | 460 // Since we now have only one search term, the cached results for 're' and |
495 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). | 461 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). |
496 url_index_->HistoryItemsForTerms(terms); | 462 url_index_->HistoryItemsForTerms(original_terms); |
497 ASSERT_EQ(1U, cache.size()); | 463 ASSERT_EQ(1U, cache.size()); |
498 CheckTerm(cache, term_mort); | 464 CheckTerm(cache, term_mort); |
499 | 465 |
500 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. | 466 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. |
501 terms.push_back(term_reco); | 467 original_terms.push_back(term_reco); |
502 url_index_->HistoryItemsForTerms(terms); | 468 url_index_->HistoryItemsForTerms(original_terms); |
503 ASSERT_EQ(2U, cache.size()); | 469 ASSERT_EQ(2U, cache.size()); |
504 CheckTerm(cache, term_mort); | 470 CheckTerm(cache, term_mort); |
505 CheckTerm(cache, term_reco); | 471 CheckTerm(cache, term_reco); |
506 | 472 |
507 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. | 473 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. |
508 terms.resize(terms.size() - 1); | 474 original_terms.resize(original_terms.size() - 1); |
509 string16 term_rec = ASCIIToUTF16("rec"); | 475 string16 term_rec = ASCIIToUTF16("rec"); |
510 terms.push_back(term_rec); | 476 original_terms.push_back(term_rec); |
511 url_index_->HistoryItemsForTerms(terms); | 477 url_index_->HistoryItemsForTerms(original_terms); |
512 ASSERT_EQ(2U, cache.size()); | 478 ASSERT_EQ(2U, cache.size()); |
513 CheckTerm(cache, term_mort); | 479 CheckTerm(cache, term_mort); |
514 CheckTerm(cache, term_rec); | 480 CheckTerm(cache, term_rec); |
515 } | 481 } |
516 | 482 |
517 TEST_F(InMemoryURLIndexTest, Scoring) { | 483 TEST_F(InMemoryURLIndexTest, Scoring) { |
518 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); | 484 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); |
519 // Test scores based on position. | 485 // Test scores based on position. |
520 ScoredHistoryMatch scored_a( | 486 ScoredHistoryMatch scored_a( |
521 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc"))); | 487 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc"))); |
(...skipping 23 matching lines...) Expand all Loading... |
545 // Test scores based on typed_count. | 511 // Test scores based on typed_count. |
546 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); | 512 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); |
547 ScoredHistoryMatch scored_h( | 513 ScoredHistoryMatch scored_h( |
548 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc"))); | 514 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc"))); |
549 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); | 515 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); |
550 } | 516 } |
551 | 517 |
552 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 518 TEST_F(InMemoryURLIndexTest, AddNewRows) { |
553 url_index_.reset(new InMemoryURLIndex(FilePath())); | 519 url_index_.reset(new InMemoryURLIndex(FilePath())); |
554 url_index_->Init(this, "en,ja,hi,zh"); | 520 url_index_->Init(this, "en,ja,hi,zh"); |
555 InMemoryURLIndex::String16Vector terms; | 521 String16Vector original_terms; |
556 | 522 |
557 // Verify that the row we're going to add does not already exist. | 523 // Verify that the row we're going to add does not already exist. |
558 URLID new_row_id = 87654321; | 524 URLID new_row_id = 87654321; |
559 // Newly created URLRows get a last_visit time of 'right now' so it should | 525 // Newly created URLRows get a last_visit time of 'right now' so it should |
560 // qualify as a quick result candidate. | 526 // qualify as a quick result candidate. |
561 terms.push_back(ASCIIToUTF16("brokeandalone")); | 527 original_terms.push_back(ASCIIToUTF16("brokeandalone")); |
562 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty()); | 528 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty()); |
563 | 529 |
564 // Add a new row. | 530 // Add a new row. |
565 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id); | 531 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id); |
566 new_row.set_last_visit(base::Time::Now()); | 532 new_row.set_last_visit(base::Time::Now()); |
567 url_index_->UpdateURL(new_row_id, new_row); | 533 url_index_->UpdateURL(new_row_id, new_row); |
568 | 534 |
569 // Verify that we can retrieve it. | 535 // Verify that we can retrieve it. |
570 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size()); | 536 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size()); |
571 | 537 |
572 // Add it again just to be sure that is harmless. | 538 // Add it again just to be sure that is harmless. |
573 url_index_->UpdateURL(new_row_id, new_row); | 539 url_index_->UpdateURL(new_row_id, new_row); |
574 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size()); | 540 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size()); |
575 } | 541 } |
576 | 542 |
577 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 543 TEST_F(InMemoryURLIndexTest, DeleteRows) { |
578 url_index_.reset(new InMemoryURLIndex(FilePath())); | 544 url_index_.reset(new InMemoryURLIndex(FilePath())); |
579 url_index_->Init(this, "en,ja,hi,zh"); | 545 url_index_->Init(this, "en,ja,hi,zh"); |
580 InMemoryURLIndex::String16Vector terms; | 546 String16Vector original_terms; |
581 | 547 |
582 // Make sure we actually get an existing result. | 548 // Make sure we actually get an existing result. |
583 terms.push_back(ASCIIToUTF16("DrudgeReport")); | 549 original_terms.push_back(ASCIIToUTF16("DrudgeReport")); |
584 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms); | 550 ScoredHistoryMatches matches = |
| 551 url_index_->HistoryItemsForTerms(original_terms); |
585 ASSERT_EQ(1U, matches.size()); | 552 ASSERT_EQ(1U, matches.size()); |
586 | 553 |
587 // Determine the row id for that result, delete that id, then search again. | 554 // Determine the row id for that result, delete that id, then search again. |
588 url_index_->DeleteURL(matches[0].url_info.id()); | 555 url_index_->DeleteURL(matches[0].url_info.id()); |
589 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty()); | 556 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty()); |
590 } | 557 } |
591 | 558 |
592 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 559 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { |
593 struct TestData { | 560 struct TestData { |
594 const std::string url_spec; | 561 const std::string url_spec; |
595 const bool expected_is_whitelisted; | 562 const bool expected_is_whitelisted; |
596 } data[] = { | 563 } data[] = { |
597 // URLs with whitelisted schemes. | 564 // URLs with whitelisted schemes. |
598 { "about:histograms", true }, | 565 { "about:histograms", true }, |
599 { "chrome://settings", true }, | 566 { "chrome://settings", true }, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 657 |
691 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { | 658 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { |
692 // Save the cache to a protobuf, restore it, and compare the results. | 659 // Save the cache to a protobuf, restore it, and compare the results. |
693 url_index_.reset(new InMemoryURLIndex(FilePath())); | 660 url_index_.reset(new InMemoryURLIndex(FilePath())); |
694 InMemoryURLIndex& url_index(*(url_index_.get())); | 661 InMemoryURLIndex& url_index(*(url_index_.get())); |
695 url_index.Init(this, "en,ja,hi,zh"); | 662 url_index.Init(this, "en,ja,hi,zh"); |
696 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; | 663 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; |
697 url_index.SavePrivateData(&index_cache); | 664 url_index.SavePrivateData(&index_cache); |
698 | 665 |
699 // Capture our private data so we can later compare for equality. | 666 // Capture our private data so we can later compare for equality. |
700 int history_item_count(url_index.history_item_count_); | 667 URLIndexPrivateData& private_data(*(url_index_->private_data_)); |
701 InMemoryURLIndex::String16Vector word_list(url_index.word_list_); | 668 String16Vector word_list(private_data.word_list_); |
702 InMemoryURLIndex::WordMap word_map(url_index.word_map_); | 669 WordMap word_map(private_data.word_map_); |
703 InMemoryURLIndex::CharWordIDMap char_word_map(url_index.char_word_map_); | 670 CharWordIDMap char_word_map(private_data.char_word_map_); |
704 InMemoryURLIndex::WordIDHistoryMap word_id_history_map( | 671 WordIDHistoryMap word_id_history_map(private_data.word_id_history_map_); |
705 url_index.word_id_history_map_); | 672 HistoryIDWordMap history_id_word_map(private_data.history_id_word_map_); |
706 InMemoryURLIndex::HistoryInfoMap history_info_map( | 673 HistoryInfoMap history_info_map(private_data.history_info_map_); |
707 url_index.history_info_map_); | |
708 | 674 |
709 // Prove that there is really something there. | 675 // Prove that there is really something there. |
710 EXPECT_GT(url_index.history_item_count_, 0); | 676 EXPECT_FALSE(private_data.word_list_.empty()); |
711 EXPECT_FALSE(url_index.word_list_.empty()); | 677 // available_words_ will already be empty since we have freshly built the |
712 EXPECT_FALSE(url_index.word_map_.empty()); | 678 // data set for this test. |
713 EXPECT_FALSE(url_index.char_word_map_.empty()); | 679 EXPECT_TRUE(private_data.available_words_.empty()); |
714 EXPECT_FALSE(url_index.word_id_history_map_.empty()); | 680 EXPECT_FALSE(private_data.word_map_.empty()); |
715 EXPECT_FALSE(url_index.history_info_map_.empty()); | 681 EXPECT_FALSE(private_data.char_word_map_.empty()); |
| 682 EXPECT_FALSE(private_data.word_id_history_map_.empty()); |
| 683 EXPECT_FALSE(private_data.history_id_word_map_.empty()); |
| 684 EXPECT_FALSE(private_data.history_info_map_.empty()); |
716 | 685 |
717 // Clear and then prove it's clear. | 686 // Clear and then prove it's clear. |
718 url_index.ClearPrivateData(); | 687 url_index.ClearPrivateData(); |
719 EXPECT_EQ(0, url_index.history_item_count_); | 688 EXPECT_TRUE(private_data.word_list_.empty()); |
720 EXPECT_TRUE(url_index.word_list_.empty()); | 689 EXPECT_TRUE(private_data.available_words_.empty()); |
721 EXPECT_TRUE(url_index.word_map_.empty()); | 690 EXPECT_TRUE(private_data.word_map_.empty()); |
722 EXPECT_TRUE(url_index.char_word_map_.empty()); | 691 EXPECT_TRUE(private_data.char_word_map_.empty()); |
723 EXPECT_TRUE(url_index.word_id_history_map_.empty()); | 692 EXPECT_TRUE(private_data.word_id_history_map_.empty()); |
724 EXPECT_TRUE(url_index.history_info_map_.empty()); | 693 EXPECT_TRUE(private_data.history_id_word_map_.empty()); |
| 694 EXPECT_TRUE(private_data.history_info_map_.empty()); |
725 | 695 |
726 // Restore the cache. | 696 // Restore the cache. |
727 EXPECT_TRUE(url_index.RestorePrivateData(index_cache)); | 697 EXPECT_TRUE(url_index.RestorePrivateData(index_cache)); |
728 | 698 |
729 // Compare the restored and captured for equality. | 699 // Compare the restored and captured for equality. |
730 EXPECT_EQ(history_item_count, url_index.history_item_count_); | 700 EXPECT_EQ(word_list.size(), private_data.word_list_.size()); |
731 EXPECT_EQ(word_list.size(), url_index.word_list_.size()); | 701 EXPECT_EQ(word_map.size(), private_data.word_map_.size()); |
732 EXPECT_EQ(word_map.size(), url_index.word_map_.size()); | 702 EXPECT_EQ(char_word_map.size(), private_data.char_word_map_.size()); |
733 EXPECT_EQ(char_word_map.size(), url_index.char_word_map_.size()); | 703 EXPECT_EQ(word_id_history_map.size(), |
734 EXPECT_EQ(word_id_history_map.size(), url_index.word_id_history_map_.size()); | 704 private_data.word_id_history_map_.size()); |
735 EXPECT_EQ(history_info_map.size(), url_index.history_info_map_.size()); | 705 EXPECT_EQ(history_id_word_map.size(), |
| 706 private_data.history_id_word_map_.size()); |
| 707 EXPECT_EQ(history_info_map.size(), private_data.history_info_map_.size()); |
736 // WordList must be index-by-index equal. | 708 // WordList must be index-by-index equal. |
737 size_t count = word_list.size(); | 709 size_t count = word_list.size(); |
738 for (size_t i = 0; i < count; ++i) | 710 for (size_t i = 0; i < count; ++i) |
739 EXPECT_EQ(word_list[i], url_index.word_list_[i]); | 711 EXPECT_EQ(word_list[i], private_data.word_list_[i]); |
740 for (InMemoryURLIndex::CharWordIDMap::const_iterator expected = | 712 |
741 char_word_map.begin(); expected != char_word_map.end(); ++expected) { | 713 ExpectMapOfContainersIdentical(char_word_map, |
742 InMemoryURLIndex::CharWordIDMap::const_iterator actual = | 714 private_data.char_word_map_); |
743 url_index.char_word_map_.find(expected->first); | 715 ExpectMapOfContainersIdentical(word_id_history_map, |
744 ASSERT_TRUE(url_index.char_word_map_.end() != actual); | 716 private_data.word_id_history_map_); |
745 const InMemoryURLIndex::WordIDSet& expected_set(expected->second); | 717 ExpectMapOfContainersIdentical(history_id_word_map, |
746 const InMemoryURLIndex::WordIDSet& actual_set(actual->second); | 718 private_data.history_id_word_map_); |
747 ASSERT_EQ(expected_set.size(), actual_set.size()); | 719 |
748 for (InMemoryURLIndex::WordIDSet::const_iterator set_iter = | 720 for (HistoryInfoMap::const_iterator expected = history_info_map.begin(); |
749 expected_set.begin(); set_iter != expected_set.end(); ++set_iter) | 721 expected != history_info_map.end(); ++expected) { |
750 EXPECT_GT(actual_set.count(*set_iter), 0U); | 722 HistoryInfoMap::const_iterator actual = |
751 } | 723 private_data.history_info_map_.find(expected->first); |
752 for (InMemoryURLIndex::WordIDHistoryMap::const_iterator expected = | 724 ASSERT_FALSE(private_data.history_info_map_.end() == actual); |
753 word_id_history_map.begin(); expected != word_id_history_map.end(); | |
754 ++expected) { | |
755 InMemoryURLIndex::WordIDHistoryMap::const_iterator actual = | |
756 url_index.word_id_history_map_.find(expected->first); | |
757 ASSERT_TRUE(url_index.word_id_history_map_.end() != actual); | |
758 const InMemoryURLIndex::HistoryIDSet& expected_set(expected->second); | |
759 const InMemoryURLIndex::HistoryIDSet& actual_set(actual->second); | |
760 ASSERT_EQ(expected_set.size(), actual_set.size()); | |
761 for (InMemoryURLIndex::HistoryIDSet::const_iterator set_iter = | |
762 expected_set.begin(); set_iter != expected_set.end(); ++set_iter) | |
763 EXPECT_GT(actual_set.count(*set_iter), 0U); | |
764 } | |
765 for (InMemoryURLIndex::HistoryInfoMap::const_iterator expected = | |
766 history_info_map.begin(); expected != history_info_map.end(); | |
767 ++expected) { | |
768 InMemoryURLIndex::HistoryInfoMap::const_iterator actual = | |
769 url_index.history_info_map_.find(expected->first); | |
770 ASSERT_FALSE(url_index.history_info_map_.end() == actual); | |
771 const URLRow& expected_row(expected->second); | 725 const URLRow& expected_row(expected->second); |
772 const URLRow& actual_row(actual->second); | 726 const URLRow& actual_row(actual->second); |
773 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); | 727 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); |
774 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); | 728 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); |
775 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); | 729 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); |
776 EXPECT_EQ(expected_row.url(), actual_row.url()); | 730 EXPECT_EQ(expected_row.url(), actual_row.url()); |
777 } | 731 } |
778 } | 732 } |
779 | 733 |
780 } // namespace history | 734 } // namespace history |
OLD | NEW |