| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/history/text_database.h" | 9 #include "chrome/browser/history/text_database.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 options.begin_time = Time::FromInternalValue(0); | 195 options.begin_time = Time::FromInternalValue(0); |
| 196 | 196 |
| 197 std::vector<TextDatabase::Match> results; | 197 std::vector<TextDatabase::Match> results; |
| 198 Time first_time_searched; | 198 Time first_time_searched; |
| 199 TextDatabase::URLSet unique_urls; | 199 TextDatabase::URLSet unique_urls; |
| 200 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, | 200 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, |
| 201 &first_time_searched); | 201 &first_time_searched); |
| 202 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; | 202 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; |
| 203 | 203 |
| 204 // All 3 sites should be returned in order. | 204 // All 3 sites should be returned in order. |
| 205 ASSERT_EQ(3, results.size()); | 205 ASSERT_EQ(3U, results.size()); |
| 206 EXPECT_EQ(GURL(kURL1), results[2].url); | 206 EXPECT_EQ(GURL(kURL1), results[2].url); |
| 207 EXPECT_EQ(GURL(kURL2), results[1].url); | 207 EXPECT_EQ(GURL(kURL2), results[1].url); |
| 208 EXPECT_EQ(GURL(kURL3), results[0].url); | 208 EXPECT_EQ(GURL(kURL3), results[0].url); |
| 209 | 209 |
| 210 // Verify the info on those results. | 210 // Verify the info on those results. |
| 211 EXPECT_TRUE(Time::FromInternalValue(kTime1) == results[2].time); | 211 EXPECT_TRUE(Time::FromInternalValue(kTime1) == results[2].time); |
| 212 EXPECT_TRUE(Time::FromInternalValue(kTime2) == results[1].time); | 212 EXPECT_TRUE(Time::FromInternalValue(kTime2) == results[1].time); |
| 213 EXPECT_TRUE(Time::FromInternalValue(kTime3) == results[0].time); | 213 EXPECT_TRUE(Time::FromInternalValue(kTime3) == results[0].time); |
| 214 | 214 |
| 215 EXPECT_EQ(UTF8ToWide(std::string(kTitle1)), results[2].title); | 215 EXPECT_EQ(UTF8ToWide(std::string(kTitle1)), results[2].title); |
| 216 EXPECT_EQ(UTF8ToWide(std::string(kTitle2)), results[1].title); | 216 EXPECT_EQ(UTF8ToWide(std::string(kTitle2)), results[1].title); |
| 217 EXPECT_EQ(UTF8ToWide(std::string(kTitle3)), results[0].title); | 217 EXPECT_EQ(UTF8ToWide(std::string(kTitle3)), results[0].title); |
| 218 | 218 |
| 219 // Should have no matches in the title. | 219 // Should have no matches in the title. |
| 220 EXPECT_EQ(0, results[0].title_match_positions.size()); | 220 EXPECT_EQ(0U, results[0].title_match_positions.size()); |
| 221 EXPECT_EQ(0, results[1].title_match_positions.size()); | 221 EXPECT_EQ(0U, results[1].title_match_positions.size()); |
| 222 EXPECT_EQ(0, results[2].title_match_positions.size()); | 222 EXPECT_EQ(0U, results[2].title_match_positions.size()); |
| 223 | 223 |
| 224 // We don't want to be dependent on the exact snippet algorithm, but we know | 224 // We don't want to be dependent on the exact snippet algorithm, but we know |
| 225 // since we searched for "COUNTTAG" which occurs at the beginning of each | 225 // since we searched for "COUNTTAG" which occurs at the beginning of each |
| 226 // document, that each snippet should start with that. | 226 // document, that each snippet should start with that. |
| 227 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[0].snippet.text()), | 227 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[0].snippet.text()), |
| 228 "COUNTTAG", false)); | 228 "COUNTTAG", false)); |
| 229 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[1].snippet.text()), | 229 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[1].snippet.text()), |
| 230 "COUNTTAG", false)); | 230 "COUNTTAG", false)); |
| 231 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[2].snippet.text()), | 231 EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[2].snippet.text()), |
| 232 "COUNTTAG", false)); | 232 "COUNTTAG", false)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 options.end_time = Time::FromInternalValue(kTime3); | 246 options.end_time = Time::FromInternalValue(kTime3); |
| 247 | 247 |
| 248 std::vector<TextDatabase::Match> results; | 248 std::vector<TextDatabase::Match> results; |
| 249 Time first_time_searched; | 249 Time first_time_searched; |
| 250 TextDatabase::URLSet unique_urls; | 250 TextDatabase::URLSet unique_urls; |
| 251 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, | 251 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, |
| 252 &first_time_searched); | 252 &first_time_searched); |
| 253 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; | 253 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; |
| 254 | 254 |
| 255 // The first and second should have been returned. | 255 // The first and second should have been returned. |
| 256 EXPECT_EQ(2, results.size()); | 256 EXPECT_EQ(2U, results.size()); |
| 257 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); | 257 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); |
| 258 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); | 258 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); |
| 259 EXPECT_FALSE(ResultsHaveURL(results, kURL3)); | 259 EXPECT_FALSE(ResultsHaveURL(results, kURL3)); |
| 260 EXPECT_EQ(kTime1, first_time_searched.ToInternalValue()); | 260 EXPECT_EQ(kTime1, first_time_searched.ToInternalValue()); |
| 261 | 261 |
| 262 // --------------------------------------------------------------------------- | 262 // --------------------------------------------------------------------------- |
| 263 // Do a query where there isn't a result on the begin boundary, so we can | 263 // Do a query where there isn't a result on the begin boundary, so we can |
| 264 // test that the first time searched is set to the minimum time considered | 264 // test that the first time searched is set to the minimum time considered |
| 265 // instead of the min value. | 265 // instead of the min value. |
| 266 options.begin_time = Time::FromInternalValue((kTime2 - kTime1) / 2 + kTime1); | 266 options.begin_time = Time::FromInternalValue((kTime2 - kTime1) / 2 + kTime1); |
| 267 options.end_time = Time::FromInternalValue(kTime3 + 1); | 267 options.end_time = Time::FromInternalValue(kTime3 + 1); |
| 268 results.clear(); // GetTextMatches does *not* clear the results. | 268 results.clear(); // GetTextMatches does *not* clear the results. |
| 269 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, | 269 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, |
| 270 &first_time_searched); | 270 &first_time_searched); |
| 271 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; | 271 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; |
| 272 EXPECT_EQ(options.begin_time.ToInternalValue(), | 272 EXPECT_EQ(options.begin_time.ToInternalValue(), |
| 273 first_time_searched.ToInternalValue()); | 273 first_time_searched.ToInternalValue()); |
| 274 | 274 |
| 275 // Should have two results, the second and third. | 275 // Should have two results, the second and third. |
| 276 EXPECT_EQ(2, results.size()); | 276 EXPECT_EQ(2U, results.size()); |
| 277 EXPECT_FALSE(ResultsHaveURL(results, kURL1)); | 277 EXPECT_FALSE(ResultsHaveURL(results, kURL1)); |
| 278 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); | 278 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); |
| 279 EXPECT_TRUE(ResultsHaveURL(results, kURL3)); | 279 EXPECT_TRUE(ResultsHaveURL(results, kURL3)); |
| 280 | 280 |
| 281 // No results should also set the first_time_searched. | 281 // No results should also set the first_time_searched. |
| 282 options.begin_time = Time::FromInternalValue(kTime3 + 1); | 282 options.begin_time = Time::FromInternalValue(kTime3 + 1); |
| 283 options.end_time = Time::FromInternalValue(kTime3 * 100); | 283 options.end_time = Time::FromInternalValue(kTime3 * 100); |
| 284 results.clear(); | 284 results.clear(); |
| 285 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, | 285 db->GetTextMatches("COUNTTAG", options, &results, &unique_urls, |
| 286 &first_time_searched); | 286 &first_time_searched); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 304 options.max_count = 1; | 304 options.max_count = 1; |
| 305 | 305 |
| 306 std::vector<TextDatabase::Match> results; | 306 std::vector<TextDatabase::Match> results; |
| 307 Time first_time_searched; | 307 Time first_time_searched; |
| 308 TextDatabase::URLSet unique_urls; | 308 TextDatabase::URLSet unique_urls; |
| 309 db->GetTextMatches("google", options, &results, &unique_urls, | 309 db->GetTextMatches("google", options, &results, &unique_urls, |
| 310 &first_time_searched); | 310 &first_time_searched); |
| 311 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; | 311 EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; |
| 312 | 312 |
| 313 // There should be one result, the most recent one. | 313 // There should be one result, the most recent one. |
| 314 EXPECT_EQ(1, results.size()); | 314 EXPECT_EQ(1U, results.size()); |
| 315 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); | 315 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); |
| 316 | 316 |
| 317 // The max time considered should be the date of the returned item. | 317 // The max time considered should be the date of the returned item. |
| 318 EXPECT_EQ(kTime2, first_time_searched.ToInternalValue()); | 318 EXPECT_EQ(kTime2, first_time_searched.ToInternalValue()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace history | 321 } // namespace history |
| OLD | NEW |