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 <cstdio> | 5 #include <cstdio> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return master_->Init(); | 99 return master_->Init(); |
100 } | 100 } |
101 | 101 |
102 // May be called multiple times (some tests will do this to clear things, | 102 // May be called multiple times (some tests will do this to clear things, |
103 // and TearDown will do this to make sure eveything is shiny before quitting. | 103 // and TearDown will do this to make sure eveything is shiny before quitting. |
104 void ClearDB() { | 104 void ClearDB() { |
105 if (master_.get()) | 105 if (master_.get()) |
106 master_.reset(NULL); | 106 master_.reset(NULL); |
107 | 107 |
108 if (history_service_.get()) { | 108 if (history_service_.get()) { |
109 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask); | 109 history_service_->SetOnBackendDestroyTask(MessageLoop::QuitClosure()); |
110 history_service_->Cleanup(); | 110 history_service_->Cleanup(); |
111 history_service_ = NULL; | 111 history_service_ = NULL; |
112 | 112 |
113 // Wait for the backend class to terminate before deleting the files and | 113 // Wait for the backend class to terminate before deleting the files and |
114 // moving to the next test. Note: if this never terminates, somebody is | 114 // moving to the next test. Note: if this never terminates, somebody is |
115 // probably leaking a reference to the history backend, so it never calls | 115 // probably leaking a reference to the history backend, so it never calls |
116 // our destroy task. | 116 // our destroy task. |
117 MessageLoop::current()->Run(); | 117 MessageLoop::current()->Run(); |
118 } | 118 } |
119 } | 119 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 master_->AddURL(TestURL(g_test_count)); | 395 master_->AddURL(TestURL(g_test_count)); |
396 std::set<GURL> deleted_urls; | 396 std::set<GURL> deleted_urls; |
397 deleted_urls.insert(TestURL(g_test_count)); | 397 deleted_urls.insert(TestURL(g_test_count)); |
398 master_->DeleteURLs(deleted_urls); | 398 master_->DeleteURLs(deleted_urls); |
399 | 399 |
400 // Wait for the rebuild to complete. The task will terminate the message | 400 // Wait for the rebuild to complete. The task will terminate the message |
401 // loop when the rebuild is done. There's no chance that the rebuild will | 401 // loop when the rebuild is done. There's no chance that the rebuild will |
402 // complete before we set the task because the rebuild completion message | 402 // complete before we set the task because the rebuild completion message |
403 // is posted to the message loop; until we Run() it, rebuild can not | 403 // is posted to the message loop; until we Run() it, rebuild can not |
404 // complete. | 404 // complete. |
405 master_->set_rebuild_complete_task(new MessageLoop::QuitTask); | 405 master_->set_rebuild_complete_task(MessageLoop::QuitClosure()); |
406 MessageLoop::current()->Run(); | 406 MessageLoop::current()->Run(); |
407 | 407 |
408 // Test that all URLs were written to the database properly. | 408 // Test that all URLs were written to the database properly. |
409 Reload(); | 409 Reload(); |
410 | 410 |
411 // Make sure the extra one was *not* written (Reload won't test this). | 411 // Make sure the extra one was *not* written (Reload won't test this). |
412 EXPECT_FALSE(master_->IsVisited(TestURL(g_test_count))); | 412 EXPECT_FALSE(master_->IsVisited(TestURL(g_test_count))); |
413 } | 413 } |
414 | 414 |
415 // Test that importing a large number of URLs will work | 415 // Test that importing a large number of URLs will work |
416 TEST_F(VisitedLinkTest, BigImport) { | 416 TEST_F(VisitedLinkTest, BigImport) { |
417 ASSERT_TRUE(InitHistory()); | 417 ASSERT_TRUE(InitHistory()); |
418 ASSERT_TRUE(InitVisited(0, false)); | 418 ASSERT_TRUE(InitVisited(0, false)); |
419 | 419 |
420 // Before the table rebuilds, add a large number of URLs | 420 // Before the table rebuilds, add a large number of URLs |
421 int total_count = VisitedLinkMaster::kDefaultTableSize + 10; | 421 int total_count = VisitedLinkMaster::kDefaultTableSize + 10; |
422 for (int i = 0; i < total_count; i++) | 422 for (int i = 0; i < total_count; i++) |
423 master_->AddURL(TestURL(i)); | 423 master_->AddURL(TestURL(i)); |
424 | 424 |
425 // Wait for the rebuild to complete. | 425 // Wait for the rebuild to complete. |
426 master_->set_rebuild_complete_task(new MessageLoop::QuitTask); | 426 master_->set_rebuild_complete_task(MessageLoop::QuitClosure()); |
427 MessageLoop::current()->Run(); | 427 MessageLoop::current()->Run(); |
428 | 428 |
429 // Ensure that the right number of URLs are present | 429 // Ensure that the right number of URLs are present |
430 int used_count = master_->GetUsedCount(); | 430 int used_count = master_->GetUsedCount(); |
431 ASSERT_EQ(used_count, total_count); | 431 ASSERT_EQ(used_count, total_count); |
432 } | 432 } |
433 | 433 |
434 TEST_F(VisitedLinkTest, Listener) { | 434 TEST_F(VisitedLinkTest, Listener) { |
435 ASSERT_TRUE(InitHistory()); | 435 ASSERT_TRUE(InitHistory()); |
436 ASSERT_TRUE(InitVisited(0, true)); | 436 ASSERT_TRUE(InitVisited(0, true)); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 ChromeRenderViewHostTestHarness::SetUp(); | 584 ChromeRenderViewHostTestHarness::SetUp(); |
585 } | 585 } |
586 | 586 |
587 VisitCountingProfile* profile() const { | 587 VisitCountingProfile* profile() const { |
588 return static_cast<VisitCountingProfile*>(browser_context_.get()); | 588 return static_cast<VisitCountingProfile*>(browser_context_.get()); |
589 } | 589 } |
590 | 590 |
591 void WaitForCoalescense() { | 591 void WaitForCoalescense() { |
592 // Let the timer fire. | 592 // Let the timer fire. |
593 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 593 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
594 new MessageLoop::QuitTask(), 110); | 594 MessageLoop::QuitClosure(), 110); |
595 MessageLoop::current()->Run(); | 595 MessageLoop::current()->Run(); |
596 } | 596 } |
597 | 597 |
598 protected: | 598 protected: |
599 VisitedLinkRenderProcessHostFactory vc_rph_factory_; | 599 VisitedLinkRenderProcessHostFactory vc_rph_factory_; |
600 | 600 |
601 private: | 601 private: |
602 content::TestBrowserThread ui_thread_; | 602 content::TestBrowserThread ui_thread_; |
603 content::TestBrowserThread file_thread_; | 603 content::TestBrowserThread file_thread_; |
604 | 604 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 EXPECT_EQ(1, profile()->add_event_count()); | 720 EXPECT_EQ(1, profile()->add_event_count()); |
721 EXPECT_EQ(0, profile()->reset_event_count()); | 721 EXPECT_EQ(0, profile()->reset_event_count()); |
722 | 722 |
723 // Activate the tab. | 723 // Activate the tab. |
724 rvh()->WasRestored(); | 724 rvh()->WasRestored(); |
725 | 725 |
726 // We should have only one more reset event. | 726 // We should have only one more reset event. |
727 EXPECT_EQ(1, profile()->add_event_count()); | 727 EXPECT_EQ(1, profile()->add_event_count()); |
728 EXPECT_EQ(1, profile()->reset_event_count()); | 728 EXPECT_EQ(1, profile()->reset_event_count()); |
729 } | 729 } |
OLD | NEW |