Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: ios/net/cookies/cookie_store_ios_test_util.mm

Issue 2667753007: Divide Cookie Store IOS tests into different files (Closed)
Patch Set: rename unittest helper to test util and other renamings Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "ios/net/cookies/cookie_store_ios_test_util.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/run_loop.h"
10 #import "ios/net/cookies/cookie_store_ios.h"
11 #include "net/cookies/canonical_cookie.h"
12 #include "net/cookies/cookie_options.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace net {
16
17 namespace {
18
19 void IgnoreBoolean(bool not_used) {}
20
21 } // namespace
22
23 #pragma mark -
24 #pragma mark TestPersistentCookieStore
25
26 TestPersistentCookieStore::TestPersistentCookieStore()
27 : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {}
28
29 TestPersistentCookieStore::~TestPersistentCookieStore() = default;
30
31 #pragma mark -
32 #pragma mark TestPersistentCookieStore methods
33
34 void TestPersistentCookieStore::RunLoadedCallback() {
35 std::vector<std::unique_ptr<net::CanonicalCookie>> cookies;
36 net::CookieOptions options;
37 options.set_include_httponly();
38
39 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create(
40 kTestCookieURL, "a=b", base::Time::Now(), options));
41 cookies.push_back(std::move(cookie));
42
43 std::unique_ptr<net::CanonicalCookie> bad_canonical_cookie(
44 net::CanonicalCookie::Create(
45 GURL("http://domain/"), "name", "\x81r\xe4\xbd\xa0\xe5\xa5\xbd",
46 std::string(), "/path/",
47 base::Time(), // creation
48 base::Time(), // expires
49 false, // secure
50 false, // httponly
51 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
52 cookies.push_back(std::move(bad_canonical_cookie));
53 loaded_callback_.Run(std::move(cookies));
54 }
55
56 bool TestPersistentCookieStore::flushed() {
57 return flushed_;
58 }
59
60 #pragma mark -
61 #pragma mark Private methods
62
63 void TestPersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
64 loaded_callback_ = loaded_callback;
65 }
66
67 void TestPersistentCookieStore::LoadCookiesForKey(
68 const std::string& key,
69 const LoadedCallback& loaded_callback) {
70 loaded_callback_ = loaded_callback;
71 }
72
73 void TestPersistentCookieStore::AddCookie(const net::CanonicalCookie& cc) {}
74
75 void TestPersistentCookieStore::UpdateCookieAccessTime(
76 const net::CanonicalCookie& cc) {}
77
78 void TestPersistentCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {}
79
80 void TestPersistentCookieStore::SetForceKeepSessionState() {}
81
82 void TestPersistentCookieStore::Flush(const base::Closure& callback) {
83 flushed_ = true;
84 }
85
86 #pragma mark -
87 #pragma mark GetCookieCallback
88
89 GetCookieCallback::GetCookieCallback() : did_run_(false) {}
90
91 #pragma mark -
92 #pragma mark GetCookieCallback methods
93
94 bool GetCookieCallback::did_run() {
95 return did_run_;
96 }
97
98 const std::string& GetCookieCallback::cookie_line() {
99 return cookie_line_;
100 }
101
102 void GetCookieCallback::Run(const std::string& cookie_line) {
103 ASSERT_FALSE(did_run_);
104 did_run_ = true;
105 cookie_line_ = cookie_line;
106 }
107
108 //------------------------------------------------------------------------------
109
110 void RecordCookieChanges(std::vector<net::CanonicalCookie>* out_cookies,
111 std::vector<bool>* out_removes,
112 const net::CanonicalCookie& cookie,
113 net::CookieStore::ChangeCause cause) {
114 DCHECK(out_cookies);
115 out_cookies->push_back(cookie);
116 if (out_removes)
117 out_removes->push_back(net::CookieStore::ChangeCauseIsDeletion(cause));
118 }
119
120 void SetCookie(const std::string& cookie_line,
121 const GURL& url,
122 net::CookieStore* store) {
123 net::CookieOptions options;
124 options.set_include_httponly();
125 store->SetCookieWithOptionsAsync(url, cookie_line, options,
126 base::Bind(&IgnoreBoolean));
127 net::CookieStoreIOS::NotifySystemCookiesChanged();
128 // Wait until the flush is posted.
129 base::RunLoop().RunUntilIdle();
130 }
131
132 void ClearCookies() {
133 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage];
134 [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
135 NSArray* cookies = [store cookies];
136 for (NSHTTPCookie* cookie in cookies)
137 [store deleteCookie:cookie];
138 EXPECT_EQ(0u, [[store cookies] count]);
139 }
140
141 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/cookie_store_ios_test_util.h ('k') | ios/net/cookies/cookie_store_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698