summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-12 17:09:17 +0000
committerycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-12 17:09:17 +0000
commit7dd2b87199f491e790d87451408de40021818e15 (patch)
tree4a84064785aeadca4c3439a533897d67980262a8 /chrome
parent7799ffda6e3d514df19949502bdec717c1b629c4 (diff)
downloadchromium_src-7dd2b87199f491e790d87451408de40021818e15.zip
chromium_src-7dd2b87199f491e790d87451408de40021818e15.tar.gz
chromium_src-7dd2b87199f491e790d87451408de40021818e15.tar.bz2
Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cookies at UI thread.
Moving from http://codereview.chromium.org/7355025/ BUG=XXXX TEST=BrowsingDataCookieHelperTest TBR=rdsmith Review URL: http://codereview.chromium.org/7601018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96569 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browsing_data_cookie_helper.cc178
-rw-r--r--chrome/browser/browsing_data_cookie_helper.h134
-rw-r--r--chrome/browser/browsing_data_cookie_helper_unittest.cc204
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.cc49
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.h15
-rw-r--r--chrome/browser/cookies_tree_model.cc90
-rw-r--r--chrome/browser/cookies_tree_model.h19
-rw-r--r--chrome/browser/cookies_tree_model_unittest.cc202
-rw-r--r--chrome/browser/mock_browsing_data_cookie_helper.cc69
-rw-r--r--chrome/browser/mock_browsing_data_cookie_helper.h50
-rw-r--r--chrome/browser/safe_browsing/client_side_detection_host_unittest.cc3
-rw-r--r--chrome/browser/ui/webui/options/cookies_view_handler.cc5
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi3
14 files changed, 821 insertions, 202 deletions
diff --git a/chrome/browser/browsing_data_cookie_helper.cc b/chrome/browser/browsing_data_cookie_helper.cc
new file mode 100644
index 0000000..589d2057
--- /dev/null
+++ b/chrome/browser/browsing_data_cookie_helper.cc
@@ -0,0 +1,178 @@
+// 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_cookie_helper.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+
+BrowsingDataCookieHelper::BrowsingDataCookieHelper(Profile* profile)
+ : is_fetching_(false),
+ profile_(profile),
+ request_context_getter_(profile->GetRequestContext()) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+BrowsingDataCookieHelper::~BrowsingDataCookieHelper() {
+}
+
+void BrowsingDataCookieHelper::StartFetching(
+ const base::Callback<void(const net::CookieList& cookies)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!is_fetching_);
+ DCHECK(!callback.is_null());
+ DCHECK(completion_callback_.is_null());
+ is_fetching_ = true;
+ completion_callback_ = callback;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BrowsingDataCookieHelper::FetchCookiesOnIOThread, this));
+}
+
+void BrowsingDataCookieHelper::CancelNotification() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ completion_callback_.Reset();
+}
+
+void BrowsingDataCookieHelper::DeleteCookie(
+ const net::CookieMonster::CanonicalCookie& cookie) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BrowsingDataCookieHelper::DeleteCookieOnIOThread,
+ this, cookie));
+}
+
+void BrowsingDataCookieHelper::FetchCookiesOnIOThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ scoped_refptr<net::CookieMonster> cookie_monster =
+ request_context_getter_->GetURLRequestContext()->
+ cookie_store()->GetCookieMonster();
+ if (cookie_monster) {
+ cookie_monster->GetAllCookiesAsync(
+ base::Bind(&BrowsingDataCookieHelper::OnFetchComplete, this));
+ } else {
+ OnFetchComplete(net::CookieList());
+ }
+}
+
+void BrowsingDataCookieHelper::OnFetchComplete(const net::CookieList& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&BrowsingDataCookieHelper::NotifyInUIThread, this, cookies));
+}
+
+void BrowsingDataCookieHelper::NotifyInUIThread(
+ const net::CookieList& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(is_fetching_);
+ is_fetching_ = false;
+ if (!completion_callback_.is_null()) {
+ completion_callback_.Run(cookies);
+ completion_callback_.Reset();
+ }
+}
+
+void BrowsingDataCookieHelper::DeleteCookieOnIOThread(
+ const net::CookieMonster::CanonicalCookie& cookie) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ scoped_refptr<net::CookieMonster> cookie_monster =
+ request_context_getter_->GetURLRequestContext()->
+ cookie_store()->GetCookieMonster();
+ if (cookie_monster) {
+ cookie_monster->DeleteCanonicalCookieAsync(
+ cookie, net::CookieMonster::DeleteCookieCallback());
+ }
+}
+
+CannedBrowsingDataCookieHelper::CannedBrowsingDataCookieHelper(
+ Profile* profile)
+ : BrowsingDataCookieHelper(profile),
+ profile_(profile) {
+}
+
+CannedBrowsingDataCookieHelper::~CannedBrowsingDataCookieHelper() {}
+
+CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CannedBrowsingDataCookieHelper* clone =
+ new CannedBrowsingDataCookieHelper(profile_);
+
+ clone->cookie_list_ = cookie_list_;
+ return clone;
+}
+
+void CannedBrowsingDataCookieHelper::AddReadCookies(
+ const GURL& url,
+ const net::CookieList& cookie_list) {
+ typedef net::CookieList::const_iterator cookie_iterator;
+ for (cookie_iterator add_cookie = cookie_list.begin();
+ add_cookie != cookie_list.end(); ++add_cookie) {
+ DeleteMetchingCookie(*add_cookie);
+ cookie_list_.push_back(*add_cookie);
+ }
+}
+
+void CannedBrowsingDataCookieHelper::AddChangedCookie(
+ const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options) {
+ typedef net::CookieList::iterator cookie_iterator;
+
+ net::CookieMonster::ParsedCookie pc(cookie_line);
+ if (options.exclude_httponly() && pc.IsHttpOnly()) {
+ // Return if a Javascript cookie illegally specified the HTTP only flag.
+ return;
+ }
+
+ scoped_ptr<net::CookieMonster::CanonicalCookie> cc;
+ // This fails to create a canonical cookie, if the normalized cookie domain
+ // form cookie line and the url don't have the same domain+registry, or url
+ // host isn't cookie domain or one of its subdomains.
+ cc.reset(net::CookieMonster::CanonicalCookie::Create(url, pc));
+
+ if (cc.get()) {
+ DeleteMetchingCookie(*cc);
+ cookie_list_.push_back(*cc);
+ }
+}
+
+void CannedBrowsingDataCookieHelper::Reset() {
+ cookie_list_.clear();
+}
+
+bool CannedBrowsingDataCookieHelper::empty() const {
+ return cookie_list_.empty();
+}
+
+void CannedBrowsingDataCookieHelper::StartFetching(
+ const net::CookieMonster::GetCookieListCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!callback.is_null())
+ callback.Run(cookie_list_);
+}
+
+void CannedBrowsingDataCookieHelper::CancelNotification() {}
+
+bool CannedBrowsingDataCookieHelper::DeleteMetchingCookie(
+ const net::CookieMonster::CanonicalCookie& add_cookie) {
+ typedef net::CookieList::iterator cookie_iterator;
+ for (cookie_iterator cookie = cookie_list_.begin();
+ cookie != cookie_list_.end(); ++cookie) {
+ if (cookie->Name() == add_cookie.Name() &&
+ cookie->Domain() == add_cookie.Domain()&&
+ cookie->Path() == add_cookie.Path()) {
+ cookie_list_.erase(cookie);
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/chrome/browser/browsing_data_cookie_helper.h b/chrome/browser/browsing_data_cookie_helper.h
new file mode 100644
index 0000000..6f93054
--- /dev/null
+++ b/chrome/browser/browsing_data_cookie_helper.h
@@ -0,0 +1,134 @@
+// 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.
+
+#ifndef CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
+#define CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "net/base/cookie_monster.h"
+
+class GURL;
+class Profile;
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+// This class fetches cookie information on behalf of a caller
+// on the UI thread.
+// A client of this class need to call StartFetching from the UI thread to
+// initiate the flow, and it'll be notified by the callback in its UI
+// thread at some later point.
+// The client must call CancelNotification() if it's destroyed before the
+// callback is notified.
+class BrowsingDataCookieHelper
+ : public base::RefCountedThreadSafe<BrowsingDataCookieHelper> {
+ public:
+ explicit BrowsingDataCookieHelper(Profile* profile);
+
+ // Starts the fetching process, which will notify its completion via
+ // callback.
+ // This must be called only in the UI thread.
+ virtual void StartFetching(
+ const base::Callback<void(const net::CookieList& cookies)>& callback);
+
+ // Cancels the notification callback (i.e., the window that created it no
+ // longer exists).
+ // This must be called only in the UI thread.
+ virtual void CancelNotification();
+
+ // Requests a single cookie to be deleted in the IO thread. This must be
+ // called in the UI thread.
+ virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie& cookie);
+
+ protected:
+ friend class base::RefCountedThreadSafe<BrowsingDataCookieHelper>;
+ virtual ~BrowsingDataCookieHelper();
+
+ private:
+ // Fetch the cookies. This must be called in the IO thread.
+ void FetchCookiesOnIOThread();
+
+ // Callback function for get cookie. This must be called in the IO thread.
+ void OnFetchComplete(const net::CookieList& cookies);
+
+ // Notifies the completion callback. This must be called in the UI thread.
+ void NotifyInUIThread(const net::CookieList& cookies);
+
+ // Delete a single cookie. This must be called in IO thread.
+ void DeleteCookieOnIOThread(
+ const net::CookieMonster::CanonicalCookie& cookie);
+
+ // Indicates whether or not we're currently fetching information:
+ // it's true when StartFetching() is called in the UI thread, and it's reset
+ // after we notify the callback in the UI thread.
+ // This only mutates on the UI thread.
+ bool is_fetching_;
+
+ Profile* profile_;
+
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
+
+ // This only mutates on the UI thread.
+ base::Callback<void(const net::CookieList& cookies)> completion_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataCookieHelper);
+};
+
+// This class is a thin wrapper around BrowsingDataCookieHelper that does not
+// fetch its information from the persistent cookie store, but gets them passed
+// as a parameter during construction.
+class CannedBrowsingDataCookieHelper : public BrowsingDataCookieHelper {
+ public:
+ explicit CannedBrowsingDataCookieHelper(Profile* profile);
+
+ // Return a copy of the cookie helper. Only one consumer can use the
+ // StartFetching method at a time, so we need to create a copy of the helper
+ // everytime we instantiate a cookies tree model for it.
+ CannedBrowsingDataCookieHelper* Clone();
+
+ // Adds cookies and delete the current cookies with the same Name, Domain,
+ // and Path as the newly created ones.
+ void AddReadCookies(const GURL& url,
+ const net::CookieList& cookie_list);
+
+ // Adds cookies that will be stored by the CookieMonster. Designed to mirror
+ // the logic of SetCookieWithOptions.
+ void AddChangedCookie(const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options);
+
+ // Clears the list of canned cookies.
+ void Reset();
+
+ // True if no cookie are currently stored.
+ bool empty() const;
+
+ // BrowsingDataCookieHelper methods.
+ virtual void StartFetching(
+ const net::CookieMonster::GetCookieListCallback& callback);
+ virtual void CancelNotification();
+
+ private:
+ // Check if the cookie list contains a cookie with the same name,
+ // domain, and path as the newly created cookie. Delete the old cookie
+ // if does.
+ bool DeleteMetchingCookie(
+ const net::CookieMonster::CanonicalCookie& add_cookie);
+
+ virtual ~CannedBrowsingDataCookieHelper();
+
+ net::CookieList cookie_list_;
+
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCookieHelper);
+};
+
+#endif // CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
diff --git a/chrome/browser/browsing_data_cookie_helper_unittest.cc b/chrome/browser/browsing_data_cookie_helper_unittest.cc
new file mode 100644
index 0000000..44bc5ac
--- /dev/null
+++ b/chrome/browser/browsing_data_cookie_helper_unittest.cc
@@ -0,0 +1,204 @@
+// 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_cookie_helper.h"
+
+
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/test/base/testing_browser_process_test.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/browser/browser_thread.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class BrowsingDataCookieHelperTest : public TestingBrowserProcessTest {
+ public:
+ void SetUpOnIOThread(base::WaitableEvent* io_setup_complete) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ // This is a workaround for a bug in the TestingProfile.
+ // The URLRequestContext will be created by GetCookieMonster on the UI
+ // thread, if it does not already exist. But it must be created on the IO
+ // thread or else it will DCHECK upon destruction.
+ // Force it to be created here.
+ testing_profile_->CreateRequestContext();
+ testing_profile_->GetRequestContext()->GetURLRequestContext();
+ io_setup_complete->Signal();
+ }
+
+ virtual void SetUp() {
+ ui_thread_.reset(new BrowserThread(BrowserThread::UI, &message_loop_));
+ // Note: we're starting a real IO thread because parts of the
+ // BrowsingDataCookieHelper expect to run on that thread.
+ io_thread_.reset(new BrowserThread(BrowserThread::IO));
+ ASSERT_TRUE(io_thread_->Start());
+ testing_profile_.reset(new TestingProfile());
+ base::WaitableEvent io_setup_complete(true, false);
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BrowsingDataCookieHelperTest::SetUpOnIOThread,
+ base::Unretained(this), &io_setup_complete));
+ io_setup_complete.Wait();
+ }
+
+ virtual void TearDown() {
+ // This must be reset before the IO thread stops, because the
+ // URLRequestContextGetter forces its own deletion to occur on that thread.
+ testing_profile_->ResetRequestContext();
+ io_thread_.reset();
+ ui_thread_.reset();
+ }
+
+ void CreateCookiesForTest() {
+ scoped_refptr<net::CookieMonster> cookie_monster =
+ testing_profile_->GetCookieMonster();
+ cookie_monster->SetCookieWithOptionsAsync(
+ GURL("http://www.google.com"), "A=1", net::CookieOptions(),
+ net::CookieMonster::SetCookiesCallback());
+ cookie_monster->SetCookieWithOptionsAsync(
+ GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions(),
+ net::CookieMonster::SetCookiesCallback());
+ }
+
+ 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:
+ MessageLoop message_loop_;
+ scoped_ptr<BrowserThread> ui_thread_;
+ scoped_ptr<BrowserThread> io_thread_;
+ scoped_ptr<TestingProfile> testing_profile_;
+
+ net::CookieList cookie_list_;
+};
+
+TEST_F(BrowsingDataCookieHelperTest, FetchData) {
+ CreateCookiesForTest();
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
+ new BrowsingDataCookieHelper(testing_profile_.get()));
+
+ cookie_helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
+ base::Unretained(this)));
+
+ // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
+ MessageLoop::current()->Run();
+}
+
+TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
+ CreateCookiesForTest();
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
+ new BrowsingDataCookieHelper(testing_profile_.get()));
+
+ cookie_helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
+ base::Unretained(this)));
+
+ // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
+ MessageLoop::current()->Run();
+
+ net::CookieMonster::CanonicalCookie cookie = cookie_list_[0];
+ cookie_helper->DeleteCookie(cookie);
+
+ cookie_helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback,
+ base::Unretained(this)));
+ MessageLoop::current()->Run();
+}
+
+TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
+ const GURL origin("http://www.google.com");
+ net::CookieList cookie;
+
+ scoped_refptr<CannedBrowsingDataCookieHelper> helper(
+ new CannedBrowsingDataCookieHelper(testing_profile_.get()));
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddChangedCookie(origin, "A=1", net::CookieOptions());
+ helper->AddChangedCookie(origin, "A=1", net::CookieOptions());
+ helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::CannedUniqueCallback,
+ base::Unretained(this)));
+ cookie = cookie_list_;
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+
+ helper->AddReadCookies(origin, cookie);
+ helper->AddReadCookies(origin, cookie);
+ helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::CannedUniqueCallback,
+ base::Unretained(this)));
+}
+
+TEST_F(BrowsingDataCookieHelperTest, CannedEmpty) {
+ const GURL url_google("http://www.google.com");
+
+ scoped_refptr<CannedBrowsingDataCookieHelper> helper(
+ new CannedBrowsingDataCookieHelper(testing_profile_.get()));
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddChangedCookie(url_google, "a=1",
+ net::CookieOptions());
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+
+ net::CookieList cookies;
+ net::CookieMonster::ParsedCookie pc("a=1");
+ scoped_ptr<net::CookieMonster::CanonicalCookie> cookie(
+ new net::CookieMonster::CanonicalCookie(url_google, pc));
+ cookies.push_back(*cookie);
+
+ helper->AddReadCookies(url_google, cookies);
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+}
+
+} // namespace
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index 186fa485..51c9359 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -9,6 +9,7 @@
#include "base/lazy_instance.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browsing_data_appcache_helper.h"
+#include "chrome/browser/browsing_data_cookie_helper.h"
#include "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_file_system_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
@@ -26,7 +27,6 @@
#include "content/browser/tab_contents/tab_contents_delegate.h"
#include "content/common/notification_service.h"
#include "content/common/view_messages.h"
-#include "net/base/cookie_monster.h"
#include "webkit/fileapi/file_system_types.h"
namespace {
@@ -36,8 +36,8 @@ static base::LazyInstance<TabSpecificList> g_tab_specific(
}
bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const {
- return cookies_->GetAllCookies().empty() &&
- appcaches_->empty() &&
+ return appcaches_->empty() &&
+ cookies_->empty() &&
databases_->empty() &&
file_systems_->empty() &&
indexed_dbs_->empty() &&
@@ -239,24 +239,15 @@ void TabSpecificContentSettings::OnCookiesRead(
bool blocked_by_policy) {
if (cookie_list.empty())
return;
- LocalSharedObjectsContainer& container = blocked_by_policy ?
- blocked_local_shared_objects_ : allowed_local_shared_objects_;
- typedef net::CookieList::const_iterator cookie_iterator;
- for (cookie_iterator cookie = cookie_list.begin();
- cookie != cookie_list.end(); ++cookie) {
- container.cookies()->SetCookieWithDetails(url,
- cookie->Name(),
- cookie->Value(),
- cookie->Domain(),
- cookie->Path(),
- cookie->ExpiryDate(),
- cookie->IsSecure(),
- cookie->IsHttpOnly());
- }
- if (blocked_by_policy)
+ if (blocked_by_policy) {
+ blocked_local_shared_objects_.cookies()->AddReadCookies(
+ url, cookie_list);
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
- else
+ } else {
+ allowed_local_shared_objects_.cookies()->AddReadCookies(
+ url, cookie_list);
OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
+ }
}
void TabSpecificContentSettings::OnCookieChanged(
@@ -265,11 +256,11 @@ void TabSpecificContentSettings::OnCookieChanged(
const net::CookieOptions& options,
bool blocked_by_policy) {
if (blocked_by_policy) {
- blocked_local_shared_objects_.cookies()->SetCookieWithOptions(
+ blocked_local_shared_objects_.cookies()->AddChangedCookie(
url, cookie_line, options);
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
} else {
- allowed_local_shared_objects_.cookies()->SetCookieWithOptions(
+ allowed_local_shared_objects_.cookies()->AddChangedCookie(
url, cookie_line, options);
OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
}
@@ -486,17 +477,13 @@ void TabSpecificContentSettings::Observe(int type,
TabSpecificContentSettings::LocalSharedObjectsContainer::
LocalSharedObjectsContainer(Profile* profile)
- : cookies_(new net::CookieMonster(NULL, NULL)),
- appcaches_(new CannedBrowsingDataAppCacheHelper(profile)),
+ : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)),
+ cookies_(new CannedBrowsingDataCookieHelper(profile)),
databases_(new CannedBrowsingDataDatabaseHelper(profile)),
file_systems_(new CannedBrowsingDataFileSystemHelper(profile)),
indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)),
local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)),
session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) {
- cookies_->SetCookieableSchemes(
- net::CookieMonster::kDefaultCookieableSchemes,
- net::CookieMonster::kDefaultCookieableSchemesCount);
- cookies_->SetKeepExpiredCookies();
}
TabSpecificContentSettings::LocalSharedObjectsContainer::
@@ -504,12 +491,8 @@ TabSpecificContentSettings::LocalSharedObjectsContainer::
}
void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() {
- cookies_ = new net::CookieMonster(NULL, NULL);
- cookies_->SetCookieableSchemes(
- net::CookieMonster::kDefaultCookieableSchemes,
- net::CookieMonster::kDefaultCookieableSchemesCount);
- cookies_->SetKeepExpiredCookies();
appcaches_->Reset();
+ cookies_->Reset();
databases_->Reset();
file_systems_->Reset();
indexed_dbs_->Reset();
@@ -519,7 +502,7 @@ void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() {
CookiesTreeModel*
TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() {
- return new CookiesTreeModel(cookies_,
+ return new CookiesTreeModel(cookies_->Clone(),
databases_->Clone(),
local_storages_->Clone(),
session_storages_->Clone(),
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.h b/chrome/browser/content_settings/tab_specific_content_settings.h
index 448844d..e104d30 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.h
+++ b/chrome/browser/content_settings/tab_specific_content_settings.h
@@ -6,6 +6,9 @@
#define CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
#pragma once
+#include <set>
+#include <string>
+
#include "base/basictypes.h"
#include "chrome/browser/geolocation/geolocation_settings_state.h"
#include "chrome/common/content_settings.h"
@@ -16,6 +19,7 @@
#include "content/common/notification_registrar.h"
class CannedBrowsingDataAppCacheHelper;
+class CannedBrowsingDataCookieHelper;
class CannedBrowsingDataDatabaseHelper;
class CannedBrowsingDataFileSystemHelper;
class CannedBrowsingDataIndexedDBHelper;
@@ -27,7 +31,6 @@ struct ContentSettings;
namespace net {
class CookieList;
-class CookieMonster;
class CookieOptions;
}
@@ -205,10 +208,12 @@ class TabSpecificContentSettings : public TabContentsObserver,
// Empties the container.
void Reset();
- net::CookieMonster* cookies() const { return cookies_; }
CannedBrowsingDataAppCacheHelper* appcaches() const {
return appcaches_;
}
+ CannedBrowsingDataCookieHelper* cookies() const {
+ return cookies_;
+ }
CannedBrowsingDataDatabaseHelper* databases() const {
return databases_;
}
@@ -230,15 +235,15 @@ class TabSpecificContentSettings : public TabContentsObserver,
bool empty() const;
private:
- DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer);
-
- scoped_refptr<net::CookieMonster> cookies_;
scoped_refptr<CannedBrowsingDataAppCacheHelper> appcaches_;
+ scoped_refptr<CannedBrowsingDataCookieHelper> cookies_;
scoped_refptr<CannedBrowsingDataDatabaseHelper> databases_;
scoped_refptr<CannedBrowsingDataFileSystemHelper> file_systems_;
scoped_refptr<CannedBrowsingDataIndexedDBHelper> indexed_dbs_;
scoped_refptr<CannedBrowsingDataLocalStorageHelper> local_storages_;
scoped_refptr<CannedBrowsingDataLocalStorageHelper> session_storages_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer);
};
void AddBlockedResource(ContentSettingsType content_type,
diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc
index e626f66..d198fa2 100644
--- a/chrome/browser/cookies_tree_model.cc
+++ b/chrome/browser/cookies_tree_model.cc
@@ -8,10 +8,12 @@
#include <functional>
#include <vector>
+#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/linked_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browsing_data_cookie_helper.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/extensions/extension_service.h"
#include "content/browser/in_process_webkit/webkit_context.h"
@@ -62,7 +64,7 @@ void CookieTreeCookieNode::DeleteStoredObjects() {
// vector storing the cookies in-tact and not delete from there (that would
// invalidate our pointers), and the fact that it contains semi out-of-date
// data is not problematic as we don't re-build the model based on that.
- GetModel()->cookie_monster_->DeleteCanonicalCookie(*cookie_);
+ GetModel()->cookie_helper_->DeleteCookie(*cookie_);
}
CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const {
@@ -585,7 +587,7 @@ void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) {
// CookiesTreeModel, public:
CookiesTreeModel::CookiesTreeModel(
- net::CookieMonster* cookie_monster,
+ BrowsingDataCookieHelper* cookie_helper,
BrowsingDataDatabaseHelper* database_helper,
BrowsingDataLocalStorageHelper* local_storage_helper,
BrowsingDataLocalStorageHelper* session_storage_helper,
@@ -596,8 +598,8 @@ CookiesTreeModel::CookiesTreeModel(
bool use_cookie_source)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>(
new CookieTreeRootNode(this))),
- cookie_monster_(cookie_monster),
appcache_helper_(appcache_helper),
+ cookie_helper_(cookie_helper),
database_helper_(database_helper),
local_storage_helper_(local_storage_helper),
session_storage_helper_(session_storage_helper),
@@ -606,7 +608,10 @@ CookiesTreeModel::CookiesTreeModel(
quota_helper_(quota_helper),
batch_update_(0),
use_cookie_source_(use_cookie_source) {
- LoadCookies();
+ DCHECK(cookie_helper_);
+ cookie_helper_->StartFetching(
+ base::Bind(&CookiesTreeModel::OnCookiesModelInfoLoaded,
+ base::Unretained(this)));
DCHECK(database_helper_);
database_helper_->StartFetching(NewCallback(
this, &CookiesTreeModel::OnDatabaseModelInfoLoaded));
@@ -642,6 +647,7 @@ CookiesTreeModel::CookiesTreeModel(
}
CookiesTreeModel::~CookiesTreeModel() {
+ cookie_helper_->CancelNotification();
database_helper_->CancelNotification();
local_storage_helper_->CancelNotification();
if (session_storage_helper_)
@@ -701,42 +707,6 @@ int CookiesTreeModel::GetIconIndex(ui::TreeModelNode* node) {
return -1;
}
-void CookiesTreeModel::LoadCookies() {
- LoadCookiesWithFilter(std::wstring());
-}
-
-void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) {
- // mmargh mmargh mmargh! delicious!
-
- all_cookies_ = cookie_monster_->GetAllCookies();
- CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
- for (CookieList::iterator it = all_cookies_.begin();
- it != all_cookies_.end(); ++it) {
- std::string source_string = it->Source();
- if (source_string.empty() || !use_cookie_source_) {
- std::string domain = it->Domain();
- if (domain.length() > 1 && domain[0] == '.')
- domain = domain.substr(1);
-
- // We treat secure cookies just the same as normal ones.
- source_string = std::string(chrome::kHttpScheme) +
- chrome::kStandardSchemeSeparator + domain + "/";
- }
-
- GURL source(source_string);
- if (!filter.size() ||
- (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
- std::string::npos)) {
- CookieTreeOriginNode* origin_node =
- root->GetOrCreateOriginNode(source);
- CookieTreeCookiesNode* cookies_node =
- origin_node->GetOrCreateCookiesNode();
- CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
- cookies_node->AddCookieNode(new_cookie);
- }
- }
-}
-
void CookiesTreeModel::DeleteAllStoredObjects() {
NotifyObserverBeginBatch();
CookieTreeNode* root = GetRoot();
@@ -764,7 +734,7 @@ void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) {
NotifyObserverBeginBatch();
for (int i = num_children - 1; i >= 0; --i)
delete Remove(root, root->GetChild(i));
- LoadCookiesWithFilter(filter);
+ PopulateCookieInfoWithFilter(filter);
PopulateDatabaseInfoWithFilter(filter);
PopulateLocalStorageInfoWithFilter(filter);
PopulateSessionStorageInfoWithFilter(filter);
@@ -826,6 +796,44 @@ void CookiesTreeModel::PopulateAppCacheInfoWithFilter(
NotifyObserverEndBatch();
}
+void CookiesTreeModel::OnCookiesModelInfoLoaded(
+ const CookieList& cookie_list) {
+ cookie_list_ = cookie_list;
+ PopulateCookieInfoWithFilter(std::wstring());
+}
+
+void CookiesTreeModel::PopulateCookieInfoWithFilter(
+ const std::wstring& filter) {
+ // mmargh mmargh mmargh! delicious!
+
+ CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
+ for (CookieList::iterator it = cookie_list_.begin();
+ it != cookie_list_.end(); ++it) {
+ std::string source_string = it->Source();
+ if (source_string.empty() || !use_cookie_source_) {
+ std::string domain = it->Domain();
+ if (domain.length() > 1 && domain[0] == '.')
+ domain = domain.substr(1);
+
+ // We treat secure cookies just the same as normal ones.
+ source_string = std::string(chrome::kHttpScheme) +
+ chrome::kStandardSchemeSeparator + domain + "/";
+ }
+
+ GURL source(source_string);
+ if (!filter.size() ||
+ (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
+ std::string::npos)) {
+ CookieTreeOriginNode* origin_node =
+ root->GetOrCreateOriginNode(source);
+ CookieTreeCookiesNode* cookies_node =
+ origin_node->GetOrCreateCookiesNode();
+ CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
+ cookies_node->AddCookieNode(new_cookie);
+ }
+ }
+}
+
void CookiesTreeModel::OnDatabaseModelInfoLoaded(
const DatabaseInfoList& database_info) {
database_info_list_ = database_info;
diff --git a/chrome/browser/cookies_tree_model.h b/chrome/browser/cookies_tree_model.h
index bf9dcae..d908cc6 100644
--- a/chrome/browser/cookies_tree_model.h
+++ b/chrome/browser/cookies_tree_model.h
@@ -26,6 +26,7 @@
#include "net/base/cookie_monster.h"
#include "ui/base/models/tree_node_model.h"
+class BrowsingDataCookieHelper;
class CookiesTreeModel;
class CookieTreeAppCacheNode;
class CookieTreeAppCachesNode;
@@ -545,7 +546,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
};
CookiesTreeModel(
- net::CookieMonster* cookie_monster_,
+ BrowsingDataCookieHelper* cookie_helper,
BrowsingDataDatabaseHelper* database_helper,
BrowsingDataLocalStorageHelper* local_storage_helper,
BrowsingDataLocalStorageHelper* session_storage_helper,
@@ -599,10 +600,8 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
FileSystemInfoList;
typedef std::vector<BrowsingDataQuotaHelper::QuotaInfo> QuotaInfoArray;
- void LoadCookies();
- void LoadCookiesWithFilter(const std::wstring& filter);
-
void OnAppCacheModelInfoLoaded();
+ void OnCookiesModelInfoLoaded(const CookieList& cookie_list);
void OnDatabaseModelInfoLoaded(const DatabaseInfoList& database_info);
void OnLocalStorageModelInfoLoaded(
const LocalStorageInfoList& local_storage_info);
@@ -615,6 +614,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
void OnQuotaModelInfoLoaded(const QuotaInfoArray& quota_info);
void PopulateAppCacheInfoWithFilter(const std::wstring& filter);
+ void PopulateCookieInfoWithFilter(const std::wstring& filter);
void PopulateDatabaseInfoWithFilter(const std::wstring& filter);
void PopulateLocalStorageInfoWithFilter(const std::wstring& filter);
void PopulateSessionStorageInfoWithFilter(const std::wstring& filter);
@@ -625,19 +625,18 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
void NotifyObserverBeginBatch();
void NotifyObserverEndBatch();
- scoped_refptr<net::CookieMonster> cookie_monster_;
- CookieList all_cookies_;
-
scoped_refptr<BrowsingDataAppCacheHelper> appcache_helper_;
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper_;
scoped_refptr<BrowsingDataDatabaseHelper> database_helper_;
- scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_;
- DatabaseInfoList database_info_list_;
-
scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_;
scoped_refptr<BrowsingDataLocalStorageHelper> session_storage_helper_;
scoped_refptr<BrowsingDataIndexedDBHelper> indexed_db_helper_;
scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper_;
scoped_refptr<BrowsingDataQuotaHelper> quota_helper_;
+
+ scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_;
+ CookieList cookie_list_;
+ DatabaseInfoList database_info_list_;
LocalStorageInfoList local_storage_info_list_;
LocalStorageInfoList session_storage_info_list_;
IndexedDBInfoList indexed_db_info_list_;
diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc
index 636afc6..03e2f9e 100644
--- a/chrome/browser/cookies_tree_model_unittest.cc
+++ b/chrome/browser/cookies_tree_model_unittest.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/mock_settings_observer.h"
#include "chrome/browser/mock_browsing_data_appcache_helper.h"
+#include "chrome/browser/mock_browsing_data_cookie_helper.h"
#include "chrome/browser/mock_browsing_data_database_helper.h"
#include "chrome/browser/mock_browsing_data_file_system_helper.h"
#include "chrome/browser/mock_browsing_data_indexed_db_helper.h"
@@ -40,6 +41,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
profile_->CreateRequestContext();
+ mock_browsing_data_cookie_helper_ =
+ new MockBrowsingDataCookieHelper(profile_.get());
mock_browsing_data_database_helper_ =
new MockBrowsingDataDatabaseHelper(profile_.get());
mock_browsing_data_local_storage_helper_ =
@@ -68,12 +71,9 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
}
CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() {
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo1"), "A=1");
- monster->SetCookie(GURL("http://foo2"), "B=1");
- monster->SetCookie(GURL("http://foo3"), "C=1");
CookiesTreeModel* cookies_model = new CookiesTreeModel(
- monster, mock_browsing_data_database_helper_,
+ mock_browsing_data_cookie_helper_,
+ mock_browsing_data_database_helper_,
mock_browsing_data_local_storage_helper_,
mock_browsing_data_session_storage_helper_,
mock_browsing_data_appcache_helper_,
@@ -81,6 +81,13 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
mock_browsing_data_file_system_helper_,
mock_browsing_data_quota_helper_,
false);
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo1"), "A=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo2"), "B=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "C=1");
+ mock_browsing_data_cookie_helper_->Notify();
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
@@ -112,6 +119,7 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
// quotahost1 -> quotahost1,
// quotahost2 -> quotahost2.
EXPECT_EQ(45, cookies_model->GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("A,B,C", GetDisplayedCookies(cookies_model));
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
GetDisplayedLocalStorages(cookies_model));
@@ -127,20 +135,6 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
return cookies_model;
}
- // Get the cookie names in the cookie list, as a comma seperated string.
- // (Note that the CookieMonster cookie list is sorted by domain.)
- // Ex:
- // monster->SetCookie(GURL("http://b"), "X=1")
- // monster->SetCookie(GURL("http://a"), "Y=1")
- // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str());
- std::string GetMonsterCookies(net::CookieMonster* monster) {
- std::vector<std::string> parts;
- net::CookieList cookie_list = monster->GetAllCookies();
- for (size_t i = 0; i < cookie_list.size(); ++i)
- parts.push_back(cookie_list[i].Name());
- return JoinString(parts, ',');
- }
-
std::string GetNodesOfChildren(
const CookieTreeNode* node,
CookieTreeNode::DetailedInfo::NodeType node_type) {
@@ -281,6 +275,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
BrowserThread io_thread_;
scoped_ptr<TestingProfile> profile_;
+ scoped_refptr<MockBrowsingDataCookieHelper>
+ mock_browsing_data_cookie_helper_;
scoped_refptr<MockBrowsingDataDatabaseHelper>
mock_browsing_data_database_helper_;
scoped_refptr<MockBrowsingDataLocalStorageHelper>
@@ -300,12 +296,11 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
TEST_F(CookiesTreeModelTest, RemoveAll) {
scoped_ptr<CookiesTreeModel> cookies_model(
CreateCookiesTreeModelWithInitialSample());
- net::CookieMonster* monster = profile_->GetCookieMonster();
// Reset the selection of the first row.
{
SCOPED_TRACE("Before removing");
- EXPECT_EQ(GetMonsterCookies(monster),
+ EXPECT_EQ("A,B,C",
GetDisplayedCookies(cookies_model.get()));
EXPECT_EQ("db1,db2",
GetDisplayedDatabases(cookies_model.get()));
@@ -321,6 +316,7 @@ TEST_F(CookiesTreeModelTest, RemoveAll) {
GetDisplayedQuotas(cookies_model.get()));
}
+ mock_browsing_data_cookie_helper_->Reset();
mock_browsing_data_database_helper_->Reset();
mock_browsing_data_local_storage_helper_->Reset();
mock_browsing_data_session_storage_helper_->Reset();
@@ -333,9 +329,8 @@ TEST_F(CookiesTreeModelTest, RemoveAll) {
SCOPED_TRACE("After removing");
EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount());
EXPECT_EQ(0, cookies_model->GetRoot()->child_count());
- EXPECT_EQ(std::string(""), GetMonsterCookies(monster));
- EXPECT_EQ(GetMonsterCookies(monster),
- GetDisplayedCookies(cookies_model.get()));
+ EXPECT_EQ(std::string(""), GetDisplayedCookies(cookies_model.get()));
+ EXPECT_TRUE(mock_browsing_data_cookie_helper_->AllDeleted());
EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted());
EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted());
EXPECT_FALSE(mock_browsing_data_session_storage_helper_->AllDeleted());
@@ -347,7 +342,6 @@ TEST_F(CookiesTreeModelTest, RemoveAll) {
TEST_F(CookiesTreeModelTest, Remove) {
scoped_ptr<CookiesTreeModel> cookies_model(
CreateCookiesTreeModelWithInitialSample());
- net::CookieMonster* monster = profile_->GetCookieMonster();
// Children start out arranged as follows:
//
@@ -372,7 +366,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(13));
{
SCOPED_TRACE("`quotahost2` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -390,7 +383,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(12));
{
SCOPED_TRACE("`quotahost1` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -406,7 +398,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11));
{
SCOPED_TRACE("`idbhost2` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -422,7 +413,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10));
{
SCOPED_TRACE("`idbhost1` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -437,7 +427,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(9));
{
SCOPED_TRACE("`host2` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/",
@@ -452,7 +441,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8));
{
SCOPED_TRACE("`host1` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -465,7 +453,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(7));
{
SCOPED_TRACE("`gdbhost2` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -478,7 +465,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6));
{
SCOPED_TRACE("`gdbhost1` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -491,7 +477,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(5));
{
SCOPED_TRACE("`fshost3` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -504,7 +489,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(4));
{
SCOPED_TRACE("`fshost2` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -517,7 +501,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3));
{
SCOPED_TRACE("`fshost1` removed.");
- EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -529,7 +512,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2));
{
SCOPED_TRACE("`foo3` removed.");
- EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -541,7 +523,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1));
{
SCOPED_TRACE("`foo2` removed.");
- EXPECT_STREQ("A", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -553,7 +534,6 @@ TEST_F(CookiesTreeModelTest, Remove) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0));
{
SCOPED_TRACE("`foo1` removed.");
- EXPECT_STREQ("", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
@@ -567,12 +547,10 @@ TEST_F(CookiesTreeModelTest, Remove) {
TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
scoped_ptr<CookiesTreeModel> cookies_model(
CreateCookiesTreeModelWithInitialSample());
- net::CookieMonster* monster = profile_->GetCookieMonster();
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)->GetChild(0));
{
SCOPED_TRACE("First origin removed");
- EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
// 43 because in this case, the origin remains, although the COOKIES
// node beneath it has been deleted. So, we have
@@ -603,7 +581,6 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
{
SCOPED_TRACE("First database removed");
- EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -621,7 +598,6 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
{
SCOPED_TRACE("First origin removed");
- EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host2:2/",
@@ -640,12 +616,10 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
scoped_ptr<CookiesTreeModel> cookies_model(
CreateCookiesTreeModelWithInitialSample());
- net::CookieMonster* monster = profile_->GetCookieMonster();
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)->GetChild(0));
{
SCOPED_TRACE("Second origin COOKIES node removed");
- EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -678,7 +652,6 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
{
SCOPED_TRACE("First database removed");
- EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -696,7 +669,6 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
{
SCOPED_TRACE("First origin removed");
- EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host2:2/",
@@ -713,12 +685,7 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
}
TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo1"), "A=1");
- monster->SetCookie(GURL("http://foo2"), "B=1");
- monster->SetCookie(GURL("http://foo3"), "C=1");
- monster->SetCookie(GURL("http://foo3"), "D=1");
- CookiesTreeModel cookies_model(monster,
+ CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_,
mock_browsing_data_database_helper_,
mock_browsing_data_local_storage_helper_,
mock_browsing_data_session_storage_helper_,
@@ -727,6 +694,15 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
mock_browsing_data_file_system_helper_,
mock_browsing_data_quota_helper_,
false);
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo1"), "A=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo2"), "B=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "C=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "D=1");
+ mock_browsing_data_cookie_helper_->Notify();
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
@@ -758,7 +734,6 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
// quotahost1 -> quotahost1,
// quotahost2 -> quotahost2.
EXPECT_EQ(46, cookies_model.GetRoot()->GetTotalNodeCount());
- EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -774,7 +749,6 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2));
{
SCOPED_TRACE("Third origin removed");
- EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -791,13 +765,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
}
TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo1"), "A=1");
- monster->SetCookie(GURL("http://foo2"), "B=1");
- monster->SetCookie(GURL("http://foo3"), "C=1");
- monster->SetCookie(GURL("http://foo3"), "D=1");
- monster->SetCookie(GURL("http://foo3"), "E=1");
- CookiesTreeModel cookies_model(monster,
+ CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_,
mock_browsing_data_database_helper_,
mock_browsing_data_local_storage_helper_,
mock_browsing_data_session_storage_helper_,
@@ -806,6 +774,17 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
mock_browsing_data_file_system_helper_,
mock_browsing_data_quota_helper_,
false);
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo1"), "A=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo2"), "B=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "C=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "D=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "E=1");
+ mock_browsing_data_cookie_helper_->Notify();
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
@@ -838,7 +817,6 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
// quotahost1 -> quotahost1,
// quotahost2 -> quotahost2.
EXPECT_EQ(47, cookies_model.GetRoot()->GetTotalNodeCount());
- EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
@@ -855,7 +833,6 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
GetChild(1));
{
SCOPED_TRACE("Middle cookie in third origin removed");
- EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ(46, cookies_model.GetRoot()->GetTotalNodeCount());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
@@ -872,13 +849,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
}
TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo1"), "A=1");
- monster->SetCookie(GURL("http://foo2"), "B=1");
- monster->SetCookie(GURL("http://foo3"), "C=1");
- monster->SetCookie(GURL("http://foo3"), "D=1");
- monster->SetCookie(GURL("http://foo3"), "E=1");
- CookiesTreeModel cookies_model(monster,
+ CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_,
mock_browsing_data_database_helper_,
mock_browsing_data_local_storage_helper_,
mock_browsing_data_session_storage_helper_,
@@ -887,18 +858,28 @@ TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
mock_browsing_data_file_system_helper_,
mock_browsing_data_quota_helper_,
false);
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo1"), "A=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo2"), "B=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "C=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "D=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3"), "E=1");
+ mock_browsing_data_cookie_helper_->Notify();
+
{
SCOPED_TRACE("Initial State 5 cookies");
// 11 because there's the root, then foo1 -> cookies -> a,
// foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
- EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
}
DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1));
{
SCOPED_TRACE("Second origin removed");
- EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
// Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e
EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount());
@@ -906,56 +887,59 @@ TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
}
TEST_F(CookiesTreeModelTest, OriginOrdering) {
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://a.foo2.com"), "A=1");
- monster->SetCookie(GURL("http://foo2.com"), "B=1");
- monster->SetCookie(GURL("http://b.foo1.com"), "C=1");
- monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;"
- " path=/;"); // Leading dot on the foo4
- monster->SetCookie(GURL("http://a.foo1.com"), "E=1");
- monster->SetCookie(GURL("http://foo1.com"), "F=1");
- monster->SetCookie(GURL("http://foo3.com"), "G=1");
- monster->SetCookie(GURL("http://foo4.com"), "H=1");
-
- CookiesTreeModel cookies_model(monster,
- new MockBrowsingDataDatabaseHelper(profile_.get()),
- new MockBrowsingDataLocalStorageHelper(profile_.get()),
- new MockBrowsingDataLocalStorageHelper(profile_.get()),
- new MockBrowsingDataAppCacheHelper(profile_.get()),
- new MockBrowsingDataIndexedDBHelper(profile_.get()),
- new MockBrowsingDataFileSystemHelper(profile_.get()),
- new MockBrowsingDataQuotaHelper(profile_.get()),
- false);
+ CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_,
+ mock_browsing_data_database_helper_,
+ mock_browsing_data_local_storage_helper_,
+ mock_browsing_data_session_storage_helper_,
+ mock_browsing_data_appcache_helper_,
+ mock_browsing_data_indexed_db_helper_,
+ mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
+ false);
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://a.foo2.com"), "A=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo2.com"), "B=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://b.foo1.com"), "C=1");
+ // Leading dot on the foo4
+ mock_browsing_data_cookie_helper_->AddCookieSamples(
+ GURL("http://foo4.com"), "D=1; domain=.foo4.com; path=/;");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://a.foo1.com"), "E=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo1.com"), "F=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo3.com"), "G=1");
+ mock_browsing_data_cookie_helper_->
+ AddCookieSamples(GURL("http://foo4.com"), "H=1");
+ mock_browsing_data_cookie_helper_->Notify();
{
SCOPED_TRACE("Initial State 8 cookies");
- // CookieMonster orders cookies by pathlength, then by creation time.
- // All paths are length 1.
- EXPECT_STREQ("A,B,C,D,E,F,G,H", GetMonsterCookies(monster).c_str());
+ EXPECT_EQ(23, cookies_model.GetRoot()->GetTotalNodeCount());
EXPECT_STREQ("F,E,C,B,A,G,D,H",
GetDisplayedCookies(&cookies_model).c_str());
}
DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E"
{
- EXPECT_STREQ("A,B,C,D,F,G,H", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str());
}
}
TEST_F(CookiesTreeModelTest, ContentSettings) {
GURL host("http://example.com/");
- net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(host, "A=1");
-
- CookiesTreeModel cookies_model(monster,
- new MockBrowsingDataDatabaseHelper(profile_.get()),
- new MockBrowsingDataLocalStorageHelper(profile_.get()),
- new MockBrowsingDataLocalStorageHelper(profile_.get()),
- new MockBrowsingDataAppCacheHelper(profile_.get()),
- new MockBrowsingDataIndexedDBHelper(profile_.get()),
- new MockBrowsingDataFileSystemHelper(profile_.get()),
- new MockBrowsingDataQuotaHelper(profile_.get()),
- false);
+ CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_,
+ mock_browsing_data_database_helper_,
+ mock_browsing_data_local_storage_helper_,
+ mock_browsing_data_session_storage_helper_,
+ mock_browsing_data_appcache_helper_,
+ mock_browsing_data_indexed_db_helper_,
+ mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
+ false);
+ mock_browsing_data_cookie_helper_->AddCookieSamples(host, "A=1");
+ mock_browsing_data_cookie_helper_->Notify();
TestingProfile profile;
HostContentSettingsMap* content_settings =
diff --git a/chrome/browser/mock_browsing_data_cookie_helper.cc b/chrome/browser/mock_browsing_data_cookie_helper.cc
new file mode 100644
index 0000000..2d85cab
--- /dev/null
+++ b/chrome/browser/mock_browsing_data_cookie_helper.cc
@@ -0,0 +1,69 @@
+// 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/mock_browsing_data_cookie_helper.h"
+
+MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(Profile* profile)
+ : BrowsingDataCookieHelper(profile),
+ profile_(profile) {
+}
+
+MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
+}
+
+void MockBrowsingDataCookieHelper::StartFetching(
+ const net::CookieMonster::GetCookieListCallback &callback) {
+ callback_ = callback;
+}
+
+void MockBrowsingDataCookieHelper::CancelNotification() {
+ callback_.Reset();
+}
+
+void MockBrowsingDataCookieHelper::DeleteCookie(
+ const net::CookieMonster::CanonicalCookie& cookie) {
+ std::string key = cookie.Name() + "=" + cookie.Value();
+ CHECK(cookies_.find(key) != cookies_.end());
+ cookies_[key] = false;
+}
+
+void MockBrowsingDataCookieHelper::AddCookieSamples(
+ const GURL& url, const std::string& cookie_line) {
+ typedef net::CookieList::const_iterator cookie_iterator;
+ net::CookieMonster::ParsedCookie pc(cookie_line);
+ scoped_ptr<net::CookieMonster::CanonicalCookie> cc;
+ cc.reset(new net::CookieMonster::CanonicalCookie(url, pc));
+
+ if (cc.get()) {
+ for (cookie_iterator cookie = cookie_list_.begin();
+ cookie != cookie_list_.end(); ++cookie) {
+ if (cookie->Name() == cc->Name() &&
+ cookie->Domain() == cc->Domain()&&
+ cookie->Path() == cc->Path()) {
+ return;
+ }
+ }
+ cookie_list_.push_back(*cc);
+ cookies_[cookie_line] = true;
+ }
+}
+
+void MockBrowsingDataCookieHelper::Notify() {
+ if (!callback_.is_null())
+ callback_.Run(cookie_list_);
+}
+
+void MockBrowsingDataCookieHelper::Reset() {
+ for (std::map<const std::string, bool>::iterator i = cookies_.begin();
+ i != cookies_.end(); ++i)
+ i->second = true;
+}
+
+bool MockBrowsingDataCookieHelper::AllDeleted() {
+ for (std::map<const std::string, bool>::const_iterator i = cookies_.begin();
+ i != cookies_.end(); ++i)
+ if (i->second)
+ return false;
+ return true;
+}
diff --git a/chrome/browser/mock_browsing_data_cookie_helper.h b/chrome/browser/mock_browsing_data_cookie_helper.h
new file mode 100644
index 0000000..723e9b5
--- /dev/null
+++ b/chrome/browser/mock_browsing_data_cookie_helper.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef CHROME_BROWSER_MOCK_BROWSING_DATA_COOKIE_HELPER_H_
+#define CHROME_BROWSER_MOCK_BROWSING_DATA_COOKIE_HELPER_H_
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "chrome/browser/browsing_data_cookie_helper.h"
+
+// Mock for BrowsingDataCookieHelper.
+class MockBrowsingDataCookieHelper : public BrowsingDataCookieHelper {
+ public:
+ explicit MockBrowsingDataCookieHelper(Profile* profile);
+
+ // BrowsingDataCookieHelper methods.
+ virtual void StartFetching(
+ const net::CookieMonster::GetCookieListCallback &callback);
+ virtual void CancelNotification();
+ virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie& cookie);
+
+ // Adds some cookie samples.
+ void AddCookieSamples(const GURL& url, const std::string& cookie_line);
+
+ // Notifies the callback.
+ void Notify();
+
+ // Marks all cookies as existing.
+ void Reset();
+
+ // Returns true if all cookies since the last Reset() invocation were
+ // deleted.
+ bool AllDeleted();
+
+ private:
+ virtual ~MockBrowsingDataCookieHelper();
+
+ Profile* profile_;
+ net::CookieMonster::GetCookieListCallback callback_;
+
+ net::CookieList cookie_list_;
+
+ // Stores which cookies exist.
+ std::map<const std::string, bool> cookies_;
+};
+
+#endif // CHROME_BROWSER_MOCK_BROWSING_DATA_COOKIE_HELPER_H_
diff --git a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
index 70e7427..af6f5ee 100644
--- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
+++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
@@ -149,13 +149,14 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
mock_profile_ = new NiceMock<MockTestingProfile>();
profile_.reset(mock_profile_);
- TabContentsWrapperTestHarness::SetUp();
ui_thread_.reset(new BrowserThread(BrowserThread::UI, &message_loop_));
// Note: we're starting a real IO thread to make sure our DCHECKs that
// verify which thread is running are actually tested.
io_thread_.reset(new BrowserThread(BrowserThread::IO));
ASSERT_TRUE(io_thread_->Start());
+ TabContentsWrapperTestHarness::SetUp();
+
// Inject service classes.
csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
sb_service_ = new StrictMock<MockSafeBrowsingService>();
diff --git a/chrome/browser/ui/webui/options/cookies_view_handler.cc b/chrome/browser/ui/webui/options/cookies_view_handler.cc
index 019791f..536391f 100644
--- a/chrome/browser/ui/webui/options/cookies_view_handler.cc
+++ b/chrome/browser/ui/webui/options/cookies_view_handler.cc
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browsing_data_appcache_helper.h"
+#include "chrome/browser/browsing_data_cookie_helper.h"
#include "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_file_system_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
@@ -15,7 +16,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/cookies_tree_model_util.h"
#include "grit/generated_resources.h"
-#include "net/url_request/url_request_context_getter.h"
#include "ui/base/l10n/l10n_util.h"
CookiesViewHandler::CookiesViewHandler() : batch_update_(false) {
@@ -144,8 +144,7 @@ void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
if (!cookies_tree_model_.get()) {
Profile* profile = Profile::FromWebUI(web_ui_);
cookies_tree_model_.reset(new CookiesTreeModel(
- profile->GetRequestContext()->DONTUSEME_GetCookieStore()->
- GetCookieMonster(),
+ new BrowsingDataCookieHelper(profile),
new BrowsingDataDatabaseHelper(profile),
new BrowsingDataLocalStorageHelper(profile),
NULL,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 399713e..f546423 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -307,6 +307,8 @@
'browser/browser_util_win.h',
'browser/browsing_data_appcache_helper.cc',
'browser/browsing_data_appcache_helper.h',
+ 'browser/browsing_data_cookie_helper.cc',
+ 'browser/browsing_data_cookie_helper.h',
'browser/browsing_data_database_helper.cc',
'browser/browsing_data_database_helper.h',
'browser/browsing_data_file_system_helper.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index da90c34..5bda4d7 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -80,6 +80,8 @@
'browser/extensions/test_extension_service.h',
'browser/mock_browsing_data_appcache_helper.cc',
'browser/mock_browsing_data_appcache_helper.h',
+ 'browser/mock_browsing_data_cookie_helper.cc',
+ 'browser/mock_browsing_data_cookie_helper.h',
'browser/mock_browsing_data_database_helper.cc',
'browser/mock_browsing_data_database_helper.h',
'browser/mock_browsing_data_file_system_helper.cc',
@@ -1323,6 +1325,7 @@
'browser/browser_commands_unittest.cc',
'browser/browser_main_unittest.cc',
'browser/browsing_data_appcache_helper_unittest.cc',
+ 'browser/browsing_data_cookie_helper_unittest.cc',
'browser/browsing_data_database_helper_unittest.cc',
'browser/browsing_data_file_system_helper_unittest.cc',
'browser/browsing_data_indexed_db_helper_unittest.cc',