Chromium Code Reviews| 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/history/text_database_manager.h" | 9 #include "chrome/browser/history/text_database_manager.h" |
| 10 #include "chrome/browser/history/visit_database.h" | 10 #include "chrome/browser/history/visit_database.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 const char* kBody2 = "FOO two."; | 28 const char* kBody2 = "FOO two."; |
| 29 | 29 |
| 30 const char* kURL3 = "http://www.google.com/zxcv"; | 30 const char* kURL3 = "http://www.google.com/zxcv"; |
| 31 const char* kTitle3 = "Google C"; | 31 const char* kTitle3 = "Google C"; |
| 32 const char* kBody3 = "FOO drei"; | 32 const char* kBody3 = "FOO drei"; |
| 33 | 33 |
| 34 const char* kURL4 = "http://www.google.com/hjkl"; | 34 const char* kURL4 = "http://www.google.com/hjkl"; |
| 35 const char* kTitle4 = "Google D"; | 35 const char* kTitle4 = "Google D"; |
| 36 const char* kBody4 = "FOO lalala four."; | 36 const char* kBody4 = "FOO lalala four."; |
| 37 | 37 |
| 38 const char* kURL5 = "http://www.google.com/uiop"; | 38 const char* kURL5 = "http://www.google.com/uiop"; |
|
mrossetti
2012/02/09 00:27:03
Again I might suggest adding an URL with at least
Patrick Dubroy
2012/02/09 14:47:00
Done.
| |
| 39 const char* kTitle5 = "Google cinq"; | 39 const char* kTitle5 = "Google cinq"; |
| 40 const char* kBody5 = "FOO page one."; | 40 const char* kBody5 = "FOO page one. Including: punctuation."; |
| 41 | 41 |
| 42 // This provides a simple implementation of a URL+VisitDatabase using an | 42 // This provides a simple implementation of a URL+VisitDatabase using an |
| 43 // in-memory sqlite connection. The text database manager expects to be able to | 43 // in-memory sqlite connection. The text database manager expects to be able to |
| 44 // update the visit database to keep in sync. | 44 // update the visit database to keep in sync. |
| 45 class InMemDB : public URLDatabase, public VisitDatabase { | 45 class InMemDB : public URLDatabase, public VisitDatabase { |
| 46 public: | 46 public: |
| 47 InMemDB() { | 47 InMemDB() { |
| 48 EXPECT_TRUE(db_.OpenInMemory()); | 48 EXPECT_TRUE(db_.OpenInMemory()); |
| 49 CreateURLTable(false); | 49 CreateURLTable(false); |
| 50 InitVisitTable(); | 50 InitVisitTable(); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 EXPECT_TRUE(first_time_searched <= times[0]); | 527 EXPECT_TRUE(first_time_searched <= times[0]); |
| 528 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); | 528 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); |
| 529 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); | 529 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); |
| 530 | 530 |
| 531 // Try to query some more, there should be no results. | 531 // Try to query some more, there should be no results. |
| 532 options.end_time = first_time_searched; | 532 options.end_time = first_time_searched; |
| 533 manager.GetTextMatches(foo, options, &results, &first_time_searched); | 533 manager.GetTextMatches(foo, options, &results, &first_time_searched); |
| 534 EXPECT_EQ(0U, results.size()); | 534 EXPECT_EQ(0U, results.size()); |
| 535 } | 535 } |
| 536 | 536 |
| 537 TEST_F(TextDatabaseManagerTest, Query) { | |
| 538 ASSERT_TRUE(Init()); | |
| 539 | |
| 540 QueryOptions options; | |
| 541 std::vector<TextDatabase::Match> results; | |
| 542 Time first_time_searched; | |
| 543 | |
| 544 InMemDB visit_db; | |
| 545 | |
| 546 TextDatabaseManager manager(dir_, &visit_db, &visit_db); | |
| 547 ASSERT_TRUE(manager.Init(NULL)); | |
| 548 | |
| 549 std::vector<Time> times; | |
| 550 AddAllPages(manager, &visit_db, ×); | |
| 551 | |
| 552 // Try a multi-word query. | |
| 553 manager.GetTextMatches(UTF8ToUTF16("FOO drei"), options, | |
|
mrossetti
2012/02/09 00:27:03
Use ASCIIToUTF16 instead of UTF8ToUTF16 when you h
Patrick Dubroy
2012/02/09 14:47:00
Done.
| |
| 554 &results, &first_time_searched); | |
| 555 EXPECT_EQ(1U, results.size()); | |
| 556 results.clear(); | |
| 557 | |
| 558 // Try a quoted query that should match every URL. | |
| 559 manager.GetTextMatches(UTF8ToUTF16("\"google.com\""), options, | |
| 560 &results, &first_time_searched); | |
| 561 EXPECT_EQ(6U, results.size()); | |
| 562 results.clear(); | |
| 563 | |
| 564 // Try a quoted query that should match the body. | |
| 565 manager.GetTextMatches(UTF8ToUTF16("\"Including: punctuation.\""), options, | |
| 566 &results, &first_time_searched); | |
| 567 EXPECT_EQ(1U, results.size()); | |
| 568 results.clear(); | |
| 569 | |
| 570 // Ensure that punctuation is not ignored in quoted strings. | |
| 571 manager.GetTextMatches(UTF8ToUTF16("\"Including punctuation\""), options, | |
| 572 &results, &first_time_searched); | |
| 573 EXPECT_EQ(0U, results.size()); | |
| 574 results.clear(); | |
| 575 } | |
| 576 | |
| 537 } // namespace history | 577 } // namespace history |
| OLD | NEW |