blob: bb6d656b140c3fd91b42c631d2382ffef467ba78 [file] [log] [blame]
[email protected]63ee33bd2012-03-15 09:29:581// 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#ifndef NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_
6#define NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_
[email protected]63ee33bd2012-03-15 09:29:587
8#include "net/cookies/cookie_monster.h"
9
10#include <string>
11#include <vector>
12
13#include "base/callback_forward.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16namespace net {
17
18class DelayedCookieMonster : public CookieStore {
19 public:
20 DelayedCookieMonster();
21
mmenke606c59c2016-03-07 18:20:5522 ~DelayedCookieMonster() override;
23
[email protected]63ee33bd2012-03-15 09:29:5824 // Call the asynchronous CookieMonster function, expect it to immediately
25 // invoke the internal callback.
26 // Post a delayed task to invoke the original callback with the results.
27
dchengb03027d2014-10-21 12:00:2028 void SetCookieWithOptionsAsync(
[email protected]63ee33bd2012-03-15 09:29:5829 const GURL& url,
30 const std::string& cookie_line,
31 const CookieOptions& options,
mostynbba063d6032014-10-09 11:01:1332 const CookieMonster::SetCookiesCallback& callback) override;
[email protected]63ee33bd2012-03-15 09:29:5833
mmenkeea4cd402016-02-02 04:03:1034 void SetCookieWithDetailsAsync(const GURL& url,
35 const std::string& name,
36 const std::string& value,
37 const std::string& domain,
38 const std::string& path,
mmenkefdd4fc72016-02-05 20:53:2439 base::Time creation_time,
40 base::Time expiration_time,
41 base::Time last_access_time,
mmenkeea4cd402016-02-02 04:03:1042 bool secure,
43 bool http_only,
mkwste1a29582016-03-15 10:07:5244 CookieSameSite same_site,
mmenkeea4cd402016-02-02 04:03:1045 CookiePriority priority,
46 const SetCookiesCallback& callback) override;
47
dchengb03027d2014-10-21 12:00:2048 void GetCookiesWithOptionsAsync(
[email protected]63ee33bd2012-03-15 09:29:5849 const GURL& url,
50 const CookieOptions& options,
mostynbba063d6032014-10-09 11:01:1351 const CookieMonster::GetCookiesCallback& callback) override;
[email protected]63ee33bd2012-03-15 09:29:5852
mkwstc611e6d2016-02-23 15:45:5553 void GetCookieListWithOptionsAsync(
54 const GURL& url,
55 const CookieOptions& options,
56 const GetCookieListCallback& callback) override;
[email protected]dc8313a2014-03-24 21:38:1457
mmenke9fa44f2d2016-01-22 23:36:3958 void GetAllCookiesAsync(const GetCookieListCallback& callback) override;
59
[email protected]63ee33bd2012-03-15 09:29:5860 virtual bool SetCookieWithOptions(const GURL& url,
61 const std::string& cookie_line,
62 const CookieOptions& options);
63
64 virtual std::string GetCookiesWithOptions(const GURL& url,
65 const CookieOptions& options);
66
[email protected]63ee33bd2012-03-15 09:29:5867 virtual void DeleteCookie(const GURL& url,
68 const std::string& cookie_name);
69
dchengb03027d2014-10-21 12:00:2070 void DeleteCookieAsync(const GURL& url,
71 const std::string& cookie_name,
72 const base::Closure& callback) override;
[email protected]63ee33bd2012-03-15 09:29:5873
mmenke24379d52016-02-05 23:50:1774 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
75 const DeleteCallback& callback) override;
76
dchengb03027d2014-10-21 12:00:2077 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
78 const base::Time& delete_end,
79 const DeleteCallback& callback) override;
[email protected]63ee33bd2012-03-15 09:29:5880
dmurphfaea244c2016-04-09 00:42:3081 void DeleteAllCreatedBetweenWithPredicateAsync(
82 const base::Time& delete_begin,
83 const base::Time& delete_end,
84 const base::Callback<bool(const CanonicalCookie&)>& predicate,
mostynbba063d6032014-10-09 11:01:1385 const DeleteCallback& callback) override;
[email protected]a67a1112013-12-19 19:04:0286
dchengb03027d2014-10-21 12:00:2087 void DeleteSessionCookiesAsync(const DeleteCallback&) override;
[email protected]264807b2012-04-25 14:49:3788
mmenke96f3bab2016-01-22 17:34:0289 void FlushStore(const base::Closure& callback) override;
90
danakja9850e12016-04-18 22:28:0891 std::unique_ptr<CookieStore::CookieChangedSubscription> AddCallbackForCookie(
92 const GURL& url,
93 const std::string& name,
94 const CookieChangedCallback& callback) override;
ellyjones399e35a22014-10-27 11:09:5695
nharper5babb5e62016-03-09 18:58:0796 bool IsEphemeral() override;
97
[email protected]63ee33bd2012-03-15 09:29:5898 private:
[email protected]63ee33bd2012-03-15 09:29:5899 // Be called immediately from CookieMonster.
100
[email protected]63ee33bd2012-03-15 09:29:58101 void SetCookiesInternalCallback(bool result);
102
103 void GetCookiesWithOptionsInternalCallback(const std::string& cookie);
mkwstc611e6d2016-02-23 15:45:55104 void GetCookieListWithOptionsInternalCallback(const CookieList& cookie);
[email protected]63ee33bd2012-03-15 09:29:58105
106 // Invoke the original callbacks.
107
[email protected]63ee33bd2012-03-15 09:29:58108 void InvokeSetCookiesCallback(
109 const CookieMonster::SetCookiesCallback& callback);
110
111 void InvokeGetCookieStringCallback(
112 const CookieMonster::GetCookiesCallback& callback);
113
mkwstc611e6d2016-02-23 15:45:55114 void InvokeGetCookieListCallback(
115 const CookieMonster::GetCookieListCallback& callback);
116
[email protected]63ee33bd2012-03-15 09:29:58117 friend class base::RefCountedThreadSafe<DelayedCookieMonster>;
[email protected]63ee33bd2012-03-15 09:29:58118
danakja9850e12016-04-18 22:28:08119 std::unique_ptr<CookieMonster> cookie_monster_;
[email protected]63ee33bd2012-03-15 09:29:58120
121 bool did_run_;
122 bool result_;
123 std::string cookie_;
124 std::string cookie_line_;
mkwstc611e6d2016-02-23 15:45:55125 CookieList cookie_list_;
[email protected]63ee33bd2012-03-15 09:29:58126};
127
cmumford8688a8f2015-10-15 18:08:06128class CookieURLHelper {
129 public:
130 explicit CookieURLHelper(const std::string& url_string);
131
132 const std::string& domain() const { return domain_and_registry_; }
133 std::string host() const { return url_.host(); }
134 const GURL& url() const { return url_; }
135 const GURL AppendPath(const std::string& path) const;
136
137 // Return a new string with the following substitutions:
138 // 1. "%R" -> Domain registry (i.e. "com")
139 // 2. "%D" -> Domain + registry (i.e. "google.com")
140 std::string Format(const std::string& format_string) const;
141
142 private:
143 const GURL url_;
144 const std::string registry_;
145 const std::string domain_and_registry_;
146};
147
[email protected]63ee33bd2012-03-15 09:29:58148} // namespace net
149
150#endif // NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_