summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browsing_data_remover_unittest.cc
diff options
context:
space:
mode:
authorycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 19:32:52 +0000
committerycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 19:32:52 +0000
commitdd1635341d7d6f14c81ae106870753fbfc16de74 (patch)
tree4cfc9e03ad6e1f2e2abca3f257ae6c97369daa2b /chrome/browser/browsing_data_remover_unittest.cc
parent10ff3b3bb6129b1706b5608d7bd97f44839e3d6a (diff)
downloadchromium_src-dd1635341d7d6f14c81ae106870753fbfc16de74.zip
chromium_src-dd1635341d7d6f14c81ae106870753fbfc16de74.tar.gz
chromium_src-dd1635341d7d6f14c81ae106870753fbfc16de74.tar.bz2
Update BrowsingDataRemover with the asynchronous CookieMonster API.
BUG=XXXX TEST=XXXX Review URL: http://codereview.chromium.org/7210034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browsing_data_remover_unittest.cc')
-rw-r--r--chrome/browser/browsing_data_remover_unittest.cc95
1 files changed, 92 insertions, 3 deletions
diff --git a/chrome/browser/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data_remover_unittest.cc
index e18e02e..0d27cfe 100644
--- a/chrome/browser/browsing_data_remover_unittest.cc
+++ b/chrome/browser/browsing_data_remover_unittest.cc
@@ -6,12 +6,16 @@
#include <set>
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
#include "chrome/browser/history/history.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
+#include "net/base/cookie_monster.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.cc"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
@@ -34,11 +38,20 @@ const GURL kOrigin3(kTestkOrigin3);
class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
public:
- BrowsingDataRemoverTester() {}
+ BrowsingDataRemoverTester()
+ : start_(false),
+ already_quit_(false) {}
virtual ~BrowsingDataRemoverTester() {}
void BlockUntilNotified() {
- MessageLoop::current()->Run();
+ if (!already_quit_) {
+ DCHECK(!start_);
+ start_ = true;
+ MessageLoop::current()->Run();
+ } else {
+ DCHECK(!start_);
+ already_quit_ = false;
+ }
}
protected:
@@ -48,15 +61,78 @@ class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
}
void Notify() {
- MessageLoop::current()->Quit();
+ if (start_) {
+ DCHECK(!already_quit_);
+ MessageLoop::current()->Quit();
+ start_ = false;
+ } else {
+ DCHECK(!already_quit_);
+ already_quit_ = true;
+ }
}
private:
+ // Helps prevent from running message_loop, if the callback invoked
+ // immediately.
+ bool start_;
+ bool already_quit_;
+
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester);
};
// Testers -------------------------------------------------------------------
+class RemoveCookieTester : public BrowsingDataRemoverTester {
+ public:
+ explicit RemoveCookieTester(TestingProfile* profile)
+ : get_cookie_success_(false) {
+ profile->CreateRequestContext();
+ monster_ = profile->GetRequestContext()->GetURLRequestContext()->
+ cookie_store()->GetCookieMonster();
+ }
+
+ // Returns true, if the given cookie exists in the cookie store.
+ bool ContainsCookie() {
+ get_cookie_success_ = false;
+ monster_->GetCookiesWithOptionsAsync(
+ kOrigin1, net::CookieOptions(),
+ base::Bind(&RemoveCookieTester::GetCookieCallback,
+ base::Unretained(this)));
+ BlockUntilNotified();
+ return get_cookie_success_;
+ }
+
+ void AddCookie() {
+ monster_->SetCookieWithOptionsAsync(
+ kOrigin1, "A=1", net::CookieOptions(),
+ base::Bind(&RemoveCookieTester::SetCookieCallback,
+ base::Unretained(this)));
+ BlockUntilNotified();
+ }
+
+ private:
+ void GetCookieCallback(const std::string& cookies) {
+ if (cookies == "A=1") {
+ get_cookie_success_ = true;
+ } else {
+ EXPECT_EQ(cookies, "");
+ get_cookie_success_ = false;
+ }
+ Notify();
+ }
+
+ void SetCookieCallback(bool result) {
+ ASSERT_TRUE(result);
+ Notify();
+ }
+
+ bool get_cookie_success_;
+
+ net::CookieStore* monster_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
+};
+
class RemoveHistoryTester : public BrowsingDataRemoverTester {
public:
explicit RemoveHistoryTester(TestingProfile* profile)
@@ -220,6 +296,19 @@ class BrowsingDataRemoverTest : public TestingBrowserProcessTest {
// Tests ---------------------------------------------------------------------
+TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
+ scoped_ptr<RemoveCookieTester> tester(
+ new RemoveCookieTester(GetProfile()));
+
+ tester->AddCookie();
+ ASSERT_TRUE(tester->ContainsCookie());
+
+ BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
+ base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get());
+
+ EXPECT_FALSE(tester->ContainsCookie());
+}
+
TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
scoped_ptr<RemoveHistoryTester> tester(
new RemoveHistoryTester(GetProfile()));