Chromium Code Reviews| 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,135 @@ |
| +// 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 { |
|
Paweł Hajdan Jr.
2011/07/21 16:29:41
Does this need to be a browser test? Have you cons
ycxiao
2011/07/21 19:04:49
Combine the browser test to the unit test.
|
| + public: |
| + void CreateCookiesForTest() { |
| + 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()); |
| + } |
| + |
| + void FetchCallback(const net::CookieList& cookies) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + ASSERT_EQ(2UL, cookies.size()); |
| + cookie_list_ = cookies; |
| + net::CookieList::const_iterator it = cookies.begin(); |
| + |
| + // Correct because fetching cookies will get a sorted cookie list. |
| + 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()); |
| + cookie_list_ = cookies; |
| + 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()); |
| + } |
| + |
| + protected: |
| + TestingProfile testing_profile_; |
| + |
| + net::CookieList cookie_list_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, FetchData) { |
| + CreateCookiesForTest(); |
| + scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| + new BrowsingDataCookieHelper(&testing_profile_)); |
| + |
| + cookie_helper->StartFetching( |
| + base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
| + base::Unretained(this))); |
| + |
| + // Blocks until BrowsingDataCookieHelperTest::Callback is notified. |
| + ui_test_utils::RunMessageLoop(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) { |
| + CreateCookiesForTest(); |
| + scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| + new BrowsingDataCookieHelper(&testing_profile_)); |
| + |
| + cookie_helper->StartFetching( |
| + base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
| + base::Unretained(this))); |
| + |
| + // Blocks until BrowsingDataCookieHelperTest::Callback is notified. |
| + ui_test_utils::RunMessageLoop(); |
| + |
| + net::CookieMonster::CanonicalCookie cookie = cookie_list_[0]; |
| + cookie_helper->DeleteCookie(cookie); |
| + |
| + cookie_helper->StartFetching( |
| + base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, |
| + base::Unretained(this))); |
| + 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_)); |
| + |
| + ASSERT_TRUE(helper->empty()); |
| + helper->AddChangeCookie(origin, "A=1", net::CookieOptions()); |
| + helper->AddChangeCookie(origin, "A=1", net::CookieOptions()); |
| + helper->StartFetching( |
| + base::Bind(&BrowsingDataCookieHelperTest::CannedUniqueCallback, |
| + base::Unretained(this))); |
| + cookie = cookie_list_; |
| + helper->Reset(); |
| + ASSERT_TRUE(helper->empty()); |
| + |
| + helper->AddReadCookie(origin, cookie); |
| + helper->AddReadCookie(origin, cookie); |
| + helper->StartFetching( |
| + base::Bind(&BrowsingDataCookieHelperTest::CannedUniqueCallback, |
| + base::Unretained(this))); |
| +} |
| + |
| +} // namespace |
| Property changes on: chrome/browser/browsing_data_cookie_helper_browsertest.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |