Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / browsing_data / mock_browsing_data_cookie_helper.cc
blob5e95faa71c217b91979217d5ae8ef59ae6bf32f1
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"
10 #include "testing/gtest/include/gtest/gtest.h"
12 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(
13 net::URLRequestContextGetter* request_context_getter)
14 : BrowsingDataCookieHelper(request_context_getter) {
17 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
20 void MockBrowsingDataCookieHelper::StartFetching(
21 const net::CookieMonster::GetCookieListCallback &callback) {
22 ASSERT_FALSE(callback.is_null());
23 ASSERT_TRUE(callback_.is_null());
24 callback_ = callback;
27 void MockBrowsingDataCookieHelper::DeleteCookie(
28 const net::CanonicalCookie& cookie) {
29 ASSERT_FALSE(callback_.is_null());
30 std::string key = cookie.Name() + "=" + cookie.Value();
31 ASSERT_TRUE(cookies_.find(key) != cookies_.end());
32 cookies_[key] = false;
35 void MockBrowsingDataCookieHelper::AddCookieSamples(
36 const GURL& url, const std::string& cookie_line) {
37 typedef net::CookieList::const_iterator cookie_iterator;
38 net::ParsedCookie pc(cookie_line);
39 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie(url, pc));
41 if (cc.get()) {
42 for (cookie_iterator cookie = cookie_list_.begin();
43 cookie != cookie_list_.end(); ++cookie) {
44 if (cookie->Name() == cc->Name() &&
45 cookie->Domain() == cc->Domain() &&
46 cookie->Path() == cc->Path()) {
47 return;
50 cookie_list_.push_back(*cc);
51 cookies_[cookie_line] = true;
55 void MockBrowsingDataCookieHelper::Notify() {
56 if (!callback_.is_null())
57 callback_.Run(cookie_list_);
60 void MockBrowsingDataCookieHelper::Reset() {
61 for (std::map<const std::string, bool>::iterator i = cookies_.begin();
62 i != cookies_.end(); ++i)
63 i->second = true;
66 bool MockBrowsingDataCookieHelper::AllDeleted() {
67 for (std::map<const std::string, bool>::const_iterator i = cookies_.begin();
68 i != cookies_.end(); ++i)
69 if (i->second)
70 return false;
71 return true;