diff options
-rw-r--r-- | chrome/browser/browsing_data_remover.cc | 19 | ||||
-rw-r--r-- | chrome/browser/browsing_data_remover_unittest.cc | 78 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
3 files changed, 90 insertions, 8 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index 8ae410b..e1de6f6 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -131,13 +131,15 @@ void BrowsingDataRemover::Remove(int remove_mask) { // Need to clear the host cache and accumulated speculative data, as it also // reveals some history. - waiting_for_clear_networking_history_ = true; - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod( - this, - &BrowsingDataRemover::ClearNetworkingHistory, - g_browser_process->io_thread())); + if (g_browser_process->io_thread()) { + waiting_for_clear_networking_history_ = true; + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod( + this, + &BrowsingDataRemover::ClearNetworkingHistory, + g_browser_process->io_thread())); + } // As part of history deletion we also delete the auto-generated keywords. TemplateURLModel* keywords_model = profile_->GetTemplateURLModel(); @@ -339,7 +341,8 @@ void BrowsingDataRemover::NotifyAndDeleteIfDone() { // cookies and passwords. Simplest just to always clear it. Must be cleared // after the cache, as cleaning up the disk cache exposes some of the history // in the NetLog. - g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); + if (g_browser_process->net_log()) + g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); removing_ = false; FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); diff --git a/chrome/browser/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data_remover_unittest.cc new file mode 100644 index 0000000..6e6f28f --- /dev/null +++ b/chrome/browser/browsing_data_remover_unittest.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/browsing_data_remover.h" + +#include "base/message_loop.h" +#include "chrome/browser/history/history.h" +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class BrowsingDataRemoverTest : public testing::Test, + public BrowsingDataRemover::Observer { + public: + BrowsingDataRemoverTest() + : query_url_success_(false) { + } + virtual ~BrowsingDataRemoverTest() {} + + protected: + // Returns true, if the given URL exists in the history service. + bool QueryURL(HistoryService* history_service, const GURL& url) { + history_service->QueryURL( + url, + true, + &consumer_, + NewCallback(this, &BrowsingDataRemoverTest::SaveResultAndQuit)); + MessageLoop::current()->Run(); + return query_url_success_; + } + + // BrowsingDataRemover::Observer implementation. + virtual void OnBrowsingDataRemoverDone() { + MessageLoop::current()->Quit(); + } + + private: + // Callback for HistoryService::QueryURL. + void SaveResultAndQuit(HistoryService::Handle, + bool success, + const history::URLRow*, + history::VisitVector*) { + query_url_success_ = success; + MessageLoop::current()->Quit(); + } + + MessageLoopForUI message_loop_; + + // For history requests. + CancelableRequestConsumer consumer_; + bool query_url_success_; +}; + +TEST_F(BrowsingDataRemoverTest, RemoveAllHistory) { + TestingProfile profile; + profile.CreateHistoryService(true, false); + HistoryService* history = + profile.GetHistoryService(Profile::EXPLICIT_ACCESS); + GURL test_url("http://test.com/"); + history->AddPage(test_url, history::SOURCE_BROWSED); + ASSERT_TRUE(QueryURL(history, test_url)); + + BrowsingDataRemover* remover = new BrowsingDataRemover( + &profile, BrowsingDataRemover::EVERYTHING, base::Time::Now()); + remover->AddObserver(this); + + // BrowsingDataRemover deletes itself when it completes. + remover->Remove(BrowsingDataRemover::REMOVE_HISTORY); + MessageLoop::current()->Run(); + + EXPECT_FALSE(QueryURL(history, test_url)); + + profile.DestroyHistoryService(); +} + +} // namespace diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 28f4bf3..c106ab0 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1276,6 +1276,7 @@ 'browser/browsing_data_file_system_helper_unittest.cc', 'browser/browsing_data_indexed_db_helper_unittest.cc', 'browser/browsing_data_local_storage_helper_unittest.cc', + 'browser/browsing_data_remover_unittest.cc', 'browser/chrome_browser_application_mac_unittest.mm', 'browser/chromeos/cros/network_library.cc', 'browser/chromeos/cros/network_library.h', |