Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / browsing_data / mock_browsing_data_cookie_helper.cc
blobabf8b54f043241eddc42830555eb1fed6ac457e3
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 "base/stl_util.h"
9 #include "net/cookies/canonical_cookie.h"
10 #include "net/cookies/parsed_cookie.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(
14 net::URLRequestContextGetter* request_context_getter)
15 : BrowsingDataCookieHelper(request_context_getter) {
18 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
21 void MockBrowsingDataCookieHelper::StartFetching(
22 const net::CookieMonster::GetCookieListCallback &callback) {
23 ASSERT_FALSE(callback.is_null());
24 ASSERT_TRUE(callback_.is_null());
25 callback_ = callback;
28 void MockBrowsingDataCookieHelper::DeleteCookie(
29 const net::CanonicalCookie& cookie) {
30 ASSERT_FALSE(callback_.is_null());
31 std::string key = cookie.Name() + "=" + cookie.Value();
32 ASSERT_TRUE(ContainsKey(cookies_, key));
33 cookies_[key] = false;
36 void MockBrowsingDataCookieHelper::AddCookieSamples(
37 const GURL& url, const std::string& cookie_line) {
38 net::ParsedCookie pc(cookie_line);
39 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie(url, pc));
41 if (cc.get()) {
42 for (const auto& cookie : cookie_list_) {
43 if (cookie.Name() == cc->Name() && cookie.Domain() == cc->Domain() &&
44 cookie.Path() == cc->Path()) {
45 return;
48 cookie_list_.push_back(*cc);
49 cookies_[cookie_line] = true;
53 void MockBrowsingDataCookieHelper::Notify() {
54 if (!callback_.is_null())
55 callback_.Run(cookie_list_);
58 void MockBrowsingDataCookieHelper::Reset() {
59 for (auto& pair : cookies_)
60 pair.second = true;
63 bool MockBrowsingDataCookieHelper::AllDeleted() {
64 for (const auto& pair : cookies_) {
65 if (pair.second)
66 return false;
68 return true;