Chromium Code Reviews| Index: chrome/browser/browsing_data_remover_unittest.cc |
| =================================================================== |
| --- chrome/browser/browsing_data_remover_unittest.cc (revision 93449) |
| +++ chrome/browser/browsing_data_remover_unittest.cc (working copy) |
| @@ -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/test_url_request_context_getter.h" |
|
erikwright (departed)
2011/07/25 16:27:16
Do you need this, or just url_request_context_gett
|
| #include "chrome/test/testing_profile.h" |
| #include "content/browser/appcache/chrome_appcache_service.h" |
| +#include "net/base/cookie_monster.h" |
| +#include "net/url_request/url_request_context.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "webkit/appcache/appcache.h" |
| #include "webkit/appcache/appcache_group.h" |
| @@ -37,11 +41,18 @@ |
| class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { |
| public: |
| - BrowsingDataRemoverTester() {} |
| + BrowsingDataRemoverTester() |
| + : start_(false), |
| + already_quit_(false) {} |
| virtual ~BrowsingDataRemoverTester() {} |
| void BlockUntilNotified() { |
| - MessageLoop::current()->Run(); |
| + if (!already_quit_) { |
| + start_ = true; |
| + MessageLoop::current()->Run(); |
| + } else { |
| + already_quit_ = false; |
| + } |
| } |
| protected: |
| @@ -51,13 +62,71 @@ |
| } |
| void Notify() { |
| - MessageLoop::current()->Quit(); |
| + if (start_) { |
| + MessageLoop::current()->Quit(); |
| + start_ = false; |
| + } else { |
| + 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); |
| }; |
| +class RemoveCookieTester : public BrowsingDataRemoverTester { |
| + public: |
| + explicit RemoveCookieTester(TestingProfile* profile) { |
| + profile->CreateRequestContext(); |
| + monster_ = profile->GetRequestContext()->GetURLRequestContext()-> |
| + cookie_store()->GetCookieMonster(); |
| + } |
| + |
| + // Returns true, if the given cookie exists in the cookie store. |
| + bool ContainsCookie() { |
| + monster_->GetCookiesAsync(kOrigin1, |
| + 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) |
| @@ -307,6 +376,19 @@ |
| DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
| }; |
| +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())); |