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

Side by Side Diff: chrome/browser/history/text_database_manager_unittest.cc

Issue 18758: Port some unit tests from chrome/browser/ (Closed)
Patch Set: port the tests Created 11 years, 10 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
OLDNEW
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/message_loop.h" 6 #include "base/message_loop.h"
7 #include "chrome/browser/history/text_database_manager.h" 7 #include "chrome/browser/history/text_database_manager.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using base::Time; 10 using base::Time;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return file_util::CreateNewTempDirectory(L"TestSearchTest", &dir_); 42 return file_util::CreateNewTempDirectory(L"TestSearchTest", &dir_);
43 } 43 }
44 44
45 protected: 45 protected:
46 void SetUp() { 46 void SetUp() {
47 } 47 }
48 48
49 void TearDown() { 49 void TearDown() {
50 file_util::Delete(dir_, true); 50 file_util::Delete(dir_, true);
51 } 51 }
52 52
53 MessageLoop message_loop_; 53 MessageLoop message_loop_;
54 54
55 // Directory containing the databases. 55 // Directory containing the databases.
56 std::wstring dir_; 56 std::wstring dir_;
57 }; 57 };
58 58
59 // This provides a simple implementation of a URL+VisitDatabase using an 59 // This provides a simple implementation of a URL+VisitDatabase using an
60 // in-memory sqlite connection. The text database manager expects to be able to 60 // in-memory sqlite connection. The text database manager expects to be able to
61 // update the visit database to keep in sync. 61 // update the visit database to keep in sync.
62 class InMemDB : public URLDatabase, public VisitDatabase { 62 class InMemDB : public URLDatabase, public VisitDatabase {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 TimeTicks expire_time = TimeTicks::Now() + TimeDelta::FromDays(1); 333 TimeTicks expire_time = TimeTicks::Now() + TimeDelta::FromDays(1);
334 manager.FlushOldChangesForTime(expire_time); 334 manager.FlushOldChangesForTime(expire_time);
335 335
336 // Add the title. We should be able to query based on that. The title in the 336 // Add the title. We should be able to query based on that. The title in the
337 // URL row we set above should not come into the picture. 337 // URL row we set above should not come into the picture.
338 manager.AddPageTitle(url, L"Some unique title"); 338 manager.AddPageTitle(url, L"Some unique title");
339 Time first_time_searched; 339 Time first_time_searched;
340 QueryOptions options; 340 QueryOptions options;
341 std::vector<TextDatabase::Match> results; 341 std::vector<TextDatabase::Match> results;
342 manager.GetTextMatches(L"unique", options, &results, &first_time_searched); 342 manager.GetTextMatches(L"unique", options, &results, &first_time_searched);
343 EXPECT_EQ(1, results.size()); 343 EXPECT_EQ(1U, results.size());
344 manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched); 344 manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched);
345 EXPECT_EQ(0, results.size()); 345 EXPECT_EQ(0U, results.size());
346 346
347 // Now add the body, which should be queryable. 347 // Now add the body, which should be queryable.
348 manager.AddPageContents(url, L"Very awesome body"); 348 manager.AddPageContents(url, L"Very awesome body");
349 manager.GetTextMatches(L"awesome", options, &results, &first_time_searched); 349 manager.GetTextMatches(L"awesome", options, &results, &first_time_searched);
350 EXPECT_EQ(1, results.size()); 350 EXPECT_EQ(1U, results.size());
351 351
352 // Adding the body will actually copy the title from the URL table rather 352 // Adding the body will actually copy the title from the URL table rather
353 // than the previously indexed row (we made them not match above). This isn't 353 // than the previously indexed row (we made them not match above). This isn't
354 // necessarily what we want, but it's how it's implemented, and we don't want 354 // necessarily what we want, but it's how it's implemented, and we don't want
355 // to regress it. 355 // to regress it.
356 manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched); 356 manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched);
357 EXPECT_EQ(1, results.size()); 357 EXPECT_EQ(1U, results.size());
358 } 358 }
359 359
360 // Tests that changes get properly committed to disk. 360 // Tests that changes get properly committed to disk.
361 TEST_F(TextDatabaseManagerTest, Writing) { 361 TEST_F(TextDatabaseManagerTest, Writing) {
362 ASSERT_TRUE(Init()); 362 ASSERT_TRUE(Init());
363 363
364 QueryOptions options; 364 QueryOptions options;
365 std::vector<TextDatabase::Match> results; 365 std::vector<TextDatabase::Match> results;
366 Time first_time_searched; 366 Time first_time_searched;
367 367
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); 510 EXPECT_TRUE(ResultsHaveURL(results, kURL2));
511 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); 511 EXPECT_TRUE(ResultsHaveURL(results, kURL1));
512 512
513 // Try to query some more, there should be no results. 513 // Try to query some more, there should be no results.
514 options.end_time = first_time_searched; 514 options.end_time = first_time_searched;
515 manager.GetTextMatches(L"FOO", options, &results, &first_time_searched); 515 manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
516 EXPECT_EQ(0U, results.size()); 516 EXPECT_EQ(0U, results.size());
517 } 517 }
518 518
519 } // namespace history 519 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/starred_url_database_unittest.cc ('k') | chrome/browser/history/url_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698