Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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" |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 8 | #include "base/message_loop/message_loop.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 9 | |
| 10 | namespace net { |
| 11 | |
| 12 | const int kDelayedTime = 0; |
| 13 | |
| 14 | DelayedCookieMonster::DelayedCookieMonster() |
| 15 | : cookie_monster_(new CookieMonster(NULL, NULL)), |
| 16 | did_run_(false), |
| 17 | result_(false) { |
| 18 | } |
| 19 | |
| 20 | DelayedCookieMonster::~DelayedCookieMonster() { |
| 21 | } |
| 22 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | void DelayedCookieMonster::SetCookiesInternalCallback(bool result) { |
| 24 | result_ = result; |
| 25 | did_run_ = true; |
| 26 | } |
| 27 | |
| 28 | void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback( |
| 29 | const std::string& cookie) { |
| 30 | cookie_ = cookie; |
| 31 | did_run_ = true; |
| 32 | } |
| 33 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 34 | void DelayedCookieMonster::SetCookieWithOptionsAsync( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 35 | const GURL& url, |
| 36 | const std::string& cookie_line, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 45 | base::MessageLoop::current()->PostDelayedTask( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | FROM_HERE, |
| 47 | base::Bind(&DelayedCookieMonster::InvokeSetCookiesCallback, |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 48 | base::Unretained(this), |
| 49 | callback), |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | base::TimeDelta::FromMilliseconds(kDelayedTime)); |
| 51 | } |
| 52 | |
| 53 | void DelayedCookieMonster::GetCookiesWithOptionsAsync( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 54 | const GURL& url, |
| 55 | const CookieOptions& options, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 63 | base::MessageLoop::current()->PostDelayedTask( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 64 | FROM_HERE, |
| 65 | base::Bind(&DelayedCookieMonster::InvokeGetCookieStringCallback, |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 66 | base::Unretained(this), |
| 67 | callback), |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 68 | base::TimeDelta::FromMilliseconds(kDelayedTime)); |
| 69 | } |
| 70 | |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 71 | void DelayedCookieMonster::GetAllCookiesForURLAsync( |
| 72 | const GURL& url, |
| 73 | const GetCookieListCallback& callback) { |
| 74 | cookie_monster_->GetAllCookiesForURLAsync(url, callback); |
| 75 | } |
| 76 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 77 | void DelayedCookieMonster::InvokeSetCookiesCallback( |
| 78 | const CookieMonster::SetCookiesCallback& callback) { |
| 79 | if (!callback.is_null()) |
| 80 | callback.Run(result_); |
| 81 | } |
| 82 | |
| 83 | void DelayedCookieMonster::InvokeGetCookieStringCallback( |
| 84 | const CookieMonster::GetCookiesCallback& callback) { |
| 85 | if (!callback.is_null()) |
| 86 | callback.Run(cookie_); |
| 87 | } |
| 88 | |
| 89 | bool DelayedCookieMonster::SetCookieWithOptions( |
| 90 | const GURL& url, |
| 91 | const std::string& cookie_line, |
| 92 | const CookieOptions& options) { |
| 93 | ADD_FAILURE(); |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | std::string DelayedCookieMonster::GetCookiesWithOptions( |
| 98 | const GURL& url, |
| 99 | const CookieOptions& options) { |
| 100 | ADD_FAILURE(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 101 | return std::string(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 104 | void DelayedCookieMonster::DeleteCookie(const GURL& url, |
| 105 | const std::string& cookie_name) { |
| 106 | ADD_FAILURE(); |
| 107 | } |
| 108 | |
| 109 | void DelayedCookieMonster::DeleteCookieAsync(const GURL& url, |
| 110 | const std::string& cookie_name, |
| 111 | const base::Closure& callback) { |
| 112 | ADD_FAILURE(); |
| 113 | } |
| 114 | |
| 115 | void DelayedCookieMonster::DeleteAllCreatedBetweenAsync( |
| 116 | const base::Time& delete_begin, |
| 117 | const base::Time& delete_end, |
| 118 | const DeleteCallback& callback) { |
| 119 | ADD_FAILURE(); |
| 120 | } |
| 121 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 122 | void DelayedCookieMonster::DeleteAllCreatedBetweenForHostAsync( |
| 123 | const base::Time delete_begin, |
| 124 | const base::Time delete_end, |
| 125 | const GURL& url, |
| 126 | const DeleteCallback& callback) { |
| 127 | ADD_FAILURE(); |
| 128 | } |
| 129 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 130 | void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback&) { |
| 131 | ADD_FAILURE(); |
| 132 | } |
| 133 | |
| 134 | CookieMonster* DelayedCookieMonster::GetCookieMonster() { |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 135 | return cookie_monster_.get(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | } // namespace net |