summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browsing_data_remover_unittest.cc
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 /chrome/browser/browsing_data_remover_unittest.cc
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
Diffstat (limited to 'chrome/browser/browsing_data_remover_unittest.cc')
-rw-r--r--chrome/browser/browsing_data_remover_unittest.cc78
1 files changed, 78 insertions, 0 deletions
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