summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-30 16:39:41 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-30 16:39:41 +0000
commit9d4ca083fc3f3c5c3ee275eed683c5e3ab019990 (patch)
tree1a1dfd467b4b7e2bcfe3c1db80b9b2056a4bea6e
parentbd961022d7b63f9e3cc792bcaf90e70224683c64 (diff)
downloadchromium_src-9d4ca083fc3f3c5c3ee275eed683c5e3ab019990.zip
chromium_src-9d4ca083fc3f3c5c3ee275eed683c5e3ab019990.tar.gz
chromium_src-9d4ca083fc3f3c5c3ee275eed683c5e3ab019990.tar.bz2
Add unit test for removing history via BrowsingDataRemover
BUG=none TEST=BrowsingDataRemoverTest.* Review URL: http://codereview.chromium.org/7080028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87238 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browsing_data_remover.cc19
-rw-r--r--chrome/browser/browsing_data_remover_unittest.cc78
-rw-r--r--chrome/chrome_tests.gypi1
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',