| Index: chrome/browser/browsing_data_cookie_helper_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/browsing_data_cookie_helper_browsertest.cc (revision 0)
|
| +++ chrome/browser/browsing_data_cookie_helper_browsertest.cc (revision 0)
|
| @@ -0,0 +1,147 @@
|
| +// 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 "base/bind.h"
|
| +#include "chrome/browser/browsing_data_cookie_helper.h"
|
| +#include "chrome/test/in_process_browser_test.h"
|
| +#include "chrome/test/testing_profile.h"
|
| +#include "chrome/test/ui_test_utils.h"
|
| +#include "content/browser/browser_thread.h"
|
| +
|
| +namespace {
|
| +
|
| +class BrowsingDataCookieHelperTest : public InProcessBrowserTest {
|
| + public:
|
| + void CreatCookiesForTest() {
|
| + testing_profile_.CreateRequestContext();
|
| + scoped_refptr<net::CookieMonster> cookie_monster =
|
| + testing_profile_.GetCookieMonster();
|
| + cookie_monster->SetCookieWithOptions(
|
| + GURL("http://www.google.com"), "A=1", net::CookieOptions());
|
| + cookie_monster->SetCookieWithOptions(
|
| + GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions());
|
| + }
|
| +
|
| + protected:
|
| + TestingProfile testing_profile_;
|
| +};
|
| +
|
| +// Called back by BrowsingDataCookieHelper on the UI thread once the cookie
|
| +// information has been retrieved.
|
| +class StopTestOnCallback {
|
| + public:
|
| + explicit StopTestOnCallback(BrowsingDataCookieHelper* cookie_helper)
|
| + : cookie_helper_(cookie_helper) {
|
| + DCHECK(cookie_helper_);
|
| + }
|
| +
|
| + void FetchCallback(const net::CookieList& cookies) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + ASSERT_EQ(2UL, cookies.size());
|
| + net::CookieList::const_iterator it = cookies.begin();
|
| +
|
| + ASSERT_TRUE(it != cookies.end());
|
| + EXPECT_EQ("www.google.com", it->Domain());
|
| + EXPECT_EQ("A", it->Name());
|
| +
|
| + ASSERT_TRUE(++it != cookies.end());
|
| + EXPECT_EQ("www.gmail.google.com", it->Domain());
|
| + EXPECT_EQ("B", it->Name());
|
| +
|
| + ASSERT_TRUE(++it == cookies.end());
|
| + MessageLoop::current()->Quit();
|
| + }
|
| +
|
| + void DeleteCallback(const net::CookieList& cookies) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + ASSERT_EQ(1UL, cookies.size());
|
| + net::CookieList::const_iterator it = cookies.begin();
|
| +
|
| + ASSERT_TRUE(it != cookies.end());
|
| + EXPECT_EQ("www.gmail.google.com", it->Domain());
|
| + EXPECT_EQ("B", it->Name());
|
| +
|
| + ASSERT_TRUE(++it == cookies.end());
|
| + MessageLoop::current()->Quit();
|
| + }
|
| +
|
| + void CannedUniqueCallback(const net::CookieList& cookies) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + ASSERT_EQ(1UL, cookies.size());
|
| + net::CookieList::const_iterator it = cookies.begin();
|
| +
|
| + ASSERT_TRUE(it != cookies.end());
|
| + EXPECT_EQ("http://www.google.com/", it->Source());
|
| + EXPECT_EQ("A", it->Name());
|
| +
|
| + ASSERT_TRUE(++it == cookies.end());
|
| + }
|
| +
|
| + private:
|
| + BrowsingDataCookieHelper* cookie_helper_;
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, FetchData) {
|
| + CreatCookiesForTest();
|
| + scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
|
| + new BrowsingDataCookieHelper(&testing_profile_));
|
| + StopTestOnCallback stop_test_on_callback(cookie_helper);
|
| +
|
| + cookie_helper->StartFetching(
|
| + base::Bind(&StopTestOnCallback::FetchCallback,
|
| + base::Unretained(&stop_test_on_callback)));
|
| +
|
| + // Blocks until StopTestOnCallback::Callback is notified.
|
| + ui_test_utils::RunMessageLoop();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
|
| + CreatCookiesForTest();
|
| + scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
|
| + new BrowsingDataCookieHelper(&testing_profile_));
|
| + StopTestOnCallback stop_test_on_callback(cookie_helper);
|
| +
|
| + cookie_helper->StartFetching(
|
| + base::Bind(&StopTestOnCallback::FetchCallback,
|
| + base::Unretained(&stop_test_on_callback)));
|
| +
|
| + // Blocks until StopTestOnCallback::Callback is notified.
|
| + ui_test_utils::RunMessageLoop();
|
| +
|
| + net::CookieMonster::CanonicalCookie cookie =
|
| + cookie_helper->cookie_list()[0];
|
| + cookie_helper->DeleteCookie(cookie);
|
| +
|
| + cookie_helper->StartFetching(
|
| + base::Bind(&StopTestOnCallback::DeleteCallback,
|
| + base::Unretained(&stop_test_on_callback)));
|
| + ui_test_utils::RunMessageLoop();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
|
| + const GURL origin("http://www.google.com");
|
| + net::CookieList cookie;
|
| +
|
| + scoped_refptr<CannedBrowsingDataCookieHelper> helper(
|
| + new CannedBrowsingDataCookieHelper(&testing_profile_));
|
| + StopTestOnCallback callback(helper);
|
| +
|
| + ASSERT_TRUE(helper->empty());
|
| + helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
|
| + helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
|
| + helper->StartFetching(
|
| + base::Bind(&StopTestOnCallback::CannedUniqueCallback,
|
| + base::Unretained(&callback)));
|
| + cookie = helper->cookie_list();
|
| + helper->Reset();
|
| + ASSERT_TRUE(helper->empty());
|
| +
|
| + helper->AddReadCookie(origin, cookie);
|
| + helper->AddReadCookie(origin, cookie);
|
| + helper->StartFetching(
|
| + base::Bind(&StopTestOnCallback::CannedUniqueCallback,
|
| + base::Unretained(&callback)));
|
| +}
|
| +
|
| +} // namespace
|
|
|
| Property changes on: chrome/browser/browsing_data_cookie_helper_browsertest.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|