1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h"
7 #include "base/logging.h"
8 #include "net/cookies/canonical_cookie.h"
9 #include "net/cookies/parsed_cookie.h"
11 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(
12 net::URLRequestContextGetter
* request_context_getter
)
13 : BrowsingDataCookieHelper(request_context_getter
) {
16 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
19 void MockBrowsingDataCookieHelper::StartFetching(
20 const net::CookieMonster::GetCookieListCallback
&callback
) {
24 void MockBrowsingDataCookieHelper::DeleteCookie(
25 const net::CanonicalCookie
& cookie
) {
26 std::string key
= cookie
.Name() + "=" + cookie
.Value();
27 CHECK(cookies_
.find(key
) != cookies_
.end());
28 cookies_
[key
] = false;
31 void MockBrowsingDataCookieHelper::AddCookieSamples(
32 const GURL
& url
, const std::string
& cookie_line
) {
33 typedef net::CookieList::const_iterator cookie_iterator
;
34 net::ParsedCookie
pc(cookie_line
);
35 scoped_ptr
<net::CanonicalCookie
> cc(new net::CanonicalCookie(url
, pc
));
38 for (cookie_iterator cookie
= cookie_list_
.begin();
39 cookie
!= cookie_list_
.end(); ++cookie
) {
40 if (cookie
->Name() == cc
->Name() &&
41 cookie
->Domain() == cc
->Domain()&&
42 cookie
->Path() == cc
->Path()) {
46 cookie_list_
.push_back(*cc
);
47 cookies_
[cookie_line
] = true;
51 void MockBrowsingDataCookieHelper::Notify() {
52 if (!callback_
.is_null())
53 callback_
.Run(cookie_list_
);
56 void MockBrowsingDataCookieHelper::Reset() {
57 for (std::map
<const std::string
, bool>::iterator i
= cookies_
.begin();
58 i
!= cookies_
.end(); ++i
)
62 bool MockBrowsingDataCookieHelper::AllDeleted() {
63 for (std::map
<const std::string
, bool>::const_iterator i
= cookies_
.begin();
64 i
!= cookies_
.end(); ++i
)