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. 4 5#include "net/cookies/cookie_store_test_helpers.h" 6 7#include "base/bind.h" 8#include "base/message_loop/message_loop.h" 9 10namespace net { 11 12const int kDelayedTime = 0; 13 14DelayedCookieMonster::DelayedCookieMonster() 15 : cookie_monster_(new CookieMonster(NULL, NULL)), 16 did_run_(false), 17 result_(false) { 18} 19 20DelayedCookieMonster::~DelayedCookieMonster() { 21} 22 23void DelayedCookieMonster::SetCookiesInternalCallback(bool result) { 24 result_ = result; 25 did_run_ = true; 26} 27 28void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback( 29 const std::string& cookie) { 30 cookie_ = cookie; 31 did_run_ = true; 32} 33 34void DelayedCookieMonster::SetCookieWithOptionsAsync( 35 const GURL& url, 36 const std::string& cookie_line, 37 const CookieOptions& options, 38 const CookieMonster::SetCookiesCallback& callback) { 39 did_run_ = false; 40 cookie_monster_->SetCookieWithOptionsAsync( 41 url, cookie_line, options, 42 base::Bind(&DelayedCookieMonster::SetCookiesInternalCallback, 43 base::Unretained(this))); 44 DCHECK_EQ(did_run_, true); 45 base::MessageLoop::current()->PostDelayedTask( 46 FROM_HERE, 47 base::Bind(&DelayedCookieMonster::InvokeSetCookiesCallback, 48 base::Unretained(this), 49 callback), 50 base::TimeDelta::FromMilliseconds(kDelayedTime)); 51} 52 53void DelayedCookieMonster::GetCookiesWithOptionsAsync( 54 const GURL& url, 55 const CookieOptions& options, 56 const CookieMonster::GetCookiesCallback& callback) { 57 did_run_ = false; 58 cookie_monster_->GetCookiesWithOptionsAsync( 59 url, options, 60 base::Bind(&DelayedCookieMonster::GetCookiesWithOptionsInternalCallback, 61 base::Unretained(this))); 62 DCHECK_EQ(did_run_, true); 63 base::MessageLoop::current()->PostDelayedTask( 64 FROM_HERE, 65 base::Bind(&DelayedCookieMonster::InvokeGetCookieStringCallback, 66 base::Unretained(this), 67 callback), 68 base::TimeDelta::FromMilliseconds(kDelayedTime)); 69} 70 71void DelayedCookieMonster::InvokeSetCookiesCallback( 72 const CookieMonster::SetCookiesCallback& callback) { 73 if (!callback.is_null()) 74 callback.Run(result_); 75} 76 77void DelayedCookieMonster::InvokeGetCookieStringCallback( 78 const CookieMonster::GetCookiesCallback& callback) { 79 if (!callback.is_null()) 80 callback.Run(cookie_); 81} 82 83bool DelayedCookieMonster::SetCookieWithOptions( 84 const GURL& url, 85 const std::string& cookie_line, 86 const CookieOptions& options) { 87 ADD_FAILURE(); 88 return false; 89} 90 91std::string DelayedCookieMonster::GetCookiesWithOptions( 92 const GURL& url, 93 const CookieOptions& options) { 94 ADD_FAILURE(); 95 return std::string(); 96} 97 98void DelayedCookieMonster::DeleteCookie(const GURL& url, 99 const std::string& cookie_name) { 100 ADD_FAILURE(); 101} 102 103void DelayedCookieMonster::DeleteCookieAsync(const GURL& url, 104 const std::string& cookie_name, 105 const base::Closure& callback) { 106 ADD_FAILURE(); 107} 108 109void DelayedCookieMonster::DeleteAllCreatedBetweenAsync( 110 const base::Time& delete_begin, 111 const base::Time& delete_end, 112 const DeleteCallback& callback) { 113 ADD_FAILURE(); 114} 115 116void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback&) { 117 ADD_FAILURE(); 118} 119 120CookieMonster* DelayedCookieMonster::GetCookieMonster() { 121 return cookie_monster_.get(); 122} 123 124} // namespace net 125