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

Side by Side Diff: ios/net/cookies/cookie_cache_unittest.cc

Issue 994823004: [iOS] Upstream //ios/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2014 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_cache.h"
6
7 #include "net/cookies/canonical_cookie.h"
8 #include "net/cookies/cookie_constants.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace net {
12
13 using net::CanonicalCookie;
14
15 namespace {
16
17 CanonicalCookie MakeCookie(const GURL& url,
18 const std::string& name,
19 const std::string& value) {
20 return CanonicalCookie(url, name, value, url.host(), url.path(), base::Time(),
21 base::Time(), base::Time(), false, false, false,
22 net::COOKIE_PRIORITY_DEFAULT);
23 }
24
25 } // namespace
26
27 TEST(CookieCacheTest, UpdateAddsCookieAllowsnullptr) {
28 CookieCache cache;
29 const GURL test_url("http://www.google.com");
30 std::vector<CanonicalCookie> cookies;
31 cookies.push_back(MakeCookie(test_url, "abc", "def"));
32 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, nullptr, nullptr));
33 EXPECT_FALSE(cache.Update(test_url, "abc", cookies, nullptr, nullptr));
34 }
35
36 TEST(CookieCacheTest, UpdateAddsCookie) {
37 CookieCache cache;
38 const GURL test_url("http://www.google.com");
39 std::vector<CanonicalCookie> cookies;
40 cookies.push_back(MakeCookie(test_url, "abc", "def"));
41 std::vector<net::CanonicalCookie> removed;
42 std::vector<net::CanonicalCookie> changed;
43
44 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, &removed, &changed));
45 EXPECT_TRUE(removed.empty());
46 EXPECT_EQ(1U, changed.size());
47 EXPECT_EQ("abc", changed[0].Name());
48 EXPECT_EQ("def", changed[0].Value());
49 removed.clear();
50 changed.clear();
51
52 EXPECT_FALSE(cache.Update(test_url, "abc", cookies, &removed, &changed));
53 EXPECT_TRUE(removed.empty());
54 EXPECT_TRUE(changed.empty());
55 }
56
57 TEST(CookieCacheTest, UpdateAddsDistinctCookie) {
58 CookieCache cache;
59 const GURL test_url("http://www.google.com");
60 const GURL test_url_path("http://www.google.com/foo");
61 const GURL test_url_path_long("http://www.google.com/foo/bar");
62 std::vector<CanonicalCookie> cookies;
63 std::vector<net::CanonicalCookie> removed;
64 std::vector<net::CanonicalCookie> changed;
65
66 cookies.push_back(MakeCookie(test_url, "abc", "def"));
67 EXPECT_TRUE(
68 cache.Update(test_url_path_long, "abc", cookies, &removed, &changed));
69 EXPECT_TRUE(removed.empty());
70 EXPECT_EQ(1U, changed.size());
71 removed.clear();
72 changed.clear();
73
74 cookies.push_back(MakeCookie(test_url_path, "abc", "def"));
75 EXPECT_TRUE(
76 cache.Update(test_url_path_long, "abc", cookies, &removed, &changed));
77 EXPECT_TRUE(removed.empty());
78 EXPECT_EQ(1U, changed.size());
79 removed.clear();
80 changed.clear();
81
82 cookies.push_back(MakeCookie(test_url_path_long, "abc", "def"));
83 EXPECT_TRUE(
84 cache.Update(test_url_path_long, "abc", cookies, &removed, &changed));
85 EXPECT_TRUE(removed.empty());
86 EXPECT_EQ(1U, changed.size());
87 }
88
89 TEST(CookieCacheTest, UpdateValueChanged) {
90 CookieCache cache;
91 const GURL test_url("http://www.google.com");
92 std::vector<CanonicalCookie> cookies;
93
94 cookies.push_back(MakeCookie(test_url, "abc", "def"));
95 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, nullptr, nullptr));
96
97 std::vector<net::CanonicalCookie> removed;
98 std::vector<net::CanonicalCookie> changed;
99 cookies[0] = MakeCookie(test_url, "abc", "ghi");
100 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, &removed, &changed));
101 EXPECT_EQ(1U, removed.size());
102 EXPECT_EQ("abc", removed[0].Name());
103 EXPECT_EQ("def", removed[0].Value());
104
105 EXPECT_EQ(1U, changed.size());
106 EXPECT_EQ("abc", changed[0].Name());
107 EXPECT_EQ("ghi", changed[0].Value());
108 }
109
110 TEST(CookieCacheTest, UpdateDeletedCookie) {
111 CookieCache cache;
112 const GURL test_url("http://www.google.com");
113 std::vector<CanonicalCookie> cookies;
114 cookies.push_back(MakeCookie(test_url, "abc", "def"));
115 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, nullptr, nullptr));
116 cookies.clear();
117
118 std::vector<net::CanonicalCookie> removed;
119 std::vector<net::CanonicalCookie> changed;
120 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, &removed, &changed));
121 EXPECT_EQ(1U, removed.size());
122 EXPECT_TRUE(changed.empty());
123 }
124
125 TEST(CookieCacheTest, UpdatePathChanged) {
126 CookieCache cache;
127 const GURL test_url("http://www.google.com");
128 const GURL test_url_path("http://www.google.com/foo");
129 std::vector<CanonicalCookie> cookies;
130 cookies.push_back(MakeCookie(test_url, "abc", "def"));
131 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, nullptr, nullptr));
132
133 std::vector<net::CanonicalCookie> removed;
134 std::vector<net::CanonicalCookie> changed;
135 cookies[0] = MakeCookie(test_url_path, "abc", "def");
136 EXPECT_TRUE(cache.Update(test_url, "abc", cookies, &removed, &changed));
137 EXPECT_EQ(1U, removed.size());
138 EXPECT_EQ(1U, changed.size());
139 }
140
141 TEST(CookieCacheTest, MultipleDomains) {
142 CookieCache cache;
143 const GURL test_url_a("http://www.google.com");
144 const GURL test_url_b("http://test.google.com");
145 const GURL cookieurl("http://google.com");
146 std::vector<CanonicalCookie> cookies;
147 cookies.push_back(MakeCookie(cookieurl, "abc", "def"));
148 EXPECT_TRUE(cache.Update(test_url_a, "abc", cookies, nullptr, nullptr));
149 EXPECT_FALSE(cache.Update(test_url_a, "abc", cookies, nullptr, nullptr));
150 EXPECT_TRUE(cache.Update(test_url_b, "abc", cookies, nullptr, nullptr));
151 EXPECT_FALSE(cache.Update(test_url_b, "abc", cookies, nullptr, nullptr));
152 }
153
154 TEST(CookieCacheTest, MultipleNames) {
155 CookieCache cache;
156 const GURL cookieurl("http://google.com");
157 std::vector<CanonicalCookie> cookies;
158 cookies.push_back(MakeCookie(cookieurl, "abc", "def"));
159 EXPECT_TRUE(cache.Update(cookieurl, "abc", cookies, nullptr, nullptr));
160 EXPECT_FALSE(cache.Update(cookieurl, "abc", cookies, nullptr, nullptr));
161 cookies[0] = MakeCookie(cookieurl, "def", "def");
162 EXPECT_TRUE(cache.Update(cookieurl, "def", cookies, nullptr, nullptr));
163 EXPECT_FALSE(cache.Update(cookieurl, "def", cookies, nullptr, nullptr));
164 cookies[0] = MakeCookie(cookieurl, "abc", "def");
165 EXPECT_FALSE(cache.Update(cookieurl, "abc", cookies, nullptr, nullptr));
166 }
167
168 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698