[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/browsing_data_remover.h" |
| 6 | |
| 7 | #include "base/message_loop.h" |
| 8 | #include "chrome/browser/history/history.h" |
| 9 | #include "chrome/test/testing_profile.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | class BrowsingDataRemoverTest : public testing::Test, |
| 15 | public BrowsingDataRemover::Observer { |
| 16 | public: |
| 17 | BrowsingDataRemoverTest() |
| 18 | : query_url_success_(false) { |
| 19 | } |
| 20 | virtual ~BrowsingDataRemoverTest() {} |
| 21 | |
| 22 | protected: |
| 23 | // Returns true, if the given URL exists in the history service. |
| 24 | bool QueryURL(HistoryService* history_service, const GURL& url) { |
| 25 | history_service->QueryURL( |
| 26 | url, |
| 27 | true, |
| 28 | &consumer_, |
| 29 | NewCallback(this, &BrowsingDataRemoverTest::SaveResultAndQuit)); |
| 30 | MessageLoop::current()->Run(); |
| 31 | return query_url_success_; |
| 32 | } |
| 33 | |
| 34 | // BrowsingDataRemover::Observer implementation. |
| 35 | virtual void OnBrowsingDataRemoverDone() { |
| 36 | MessageLoop::current()->Quit(); |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | // Callback for HistoryService::QueryURL. |
| 41 | void SaveResultAndQuit(HistoryService::Handle, |
| 42 | bool success, |
| 43 | const history::URLRow*, |
| 44 | history::VisitVector*) { |
| 45 | query_url_success_ = success; |
| 46 | MessageLoop::current()->Quit(); |
| 47 | } |
| 48 | |
| 49 | MessageLoopForUI message_loop_; |
| 50 | |
| 51 | // For history requests. |
| 52 | CancelableRequestConsumer consumer_; |
| 53 | bool query_url_success_; |
| 54 | }; |
| 55 | |
| 56 | TEST_F(BrowsingDataRemoverTest, RemoveAllHistory) { |
| 57 | TestingProfile profile; |
| 58 | profile.CreateHistoryService(true, false); |
| 59 | HistoryService* history = |
| 60 | profile.GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 61 | GURL test_url("http://test.com/"); |
| 62 | history->AddPage(test_url, history::SOURCE_BROWSED); |
| 63 | ASSERT_TRUE(QueryURL(history, test_url)); |
| 64 | |
| 65 | BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 66 | &profile, BrowsingDataRemover::EVERYTHING, base::Time::Now()); |
| 67 | remover->AddObserver(this); |
| 68 | |
| 69 | // BrowsingDataRemover deletes itself when it completes. |
| 70 | remover->Remove(BrowsingDataRemover::REMOVE_HISTORY); |
| 71 | MessageLoop::current()->Run(); |
| 72 | |
| 73 | EXPECT_FALSE(QueryURL(history, test_url)); |
| 74 | |
| 75 | profile.DestroyHistoryService(); |
| 76 | } |
| 77 | |
| 78 | } // namespace |