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

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_unittest.cc

Issue 14113014: Adding Priority field to cookies. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed enums PRIORITY_* to COOKIE_PRIORITY_*. Created 7 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests common functionality used by the Chrome Extensions Cookies API 5 // Tests common functionality used by the Chrome Extensions Cookies API
6 // implementation. 6 // implementation.
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" 11 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h"
12 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" 12 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
13 #include "chrome/common/extensions/api/cookies.h" 13 #include "chrome/common/extensions/api/cookies.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/cookies/canonical_cookie.h" 16 #include "net/cookies/canonical_cookie.h"
17 #include "net/cookies/cookie_constants.h"
17 18
18 using extensions::api::cookies::Cookie; 19 using extensions::api::cookies::Cookie;
19 using extensions::api::cookies::CookieStore; 20 using extensions::api::cookies::CookieStore;
20 21
21 namespace GetAll = extensions::api::cookies::GetAll; 22 namespace GetAll = extensions::api::cookies::GetAll;
22 23
23 namespace extensions { 24 namespace extensions {
24 25
25 namespace keys = cookies_api_constants; 26 namespace keys = cookies_api_constants;
26 27
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 "1", &otrProfile, true)); 108 "1", &otrProfile, true));
108 EXPECT_EQ(&otrProfile, 109 EXPECT_EQ(&otrProfile,
109 cookies_helpers::ChooseProfileFromStoreId( 110 cookies_helpers::ChooseProfileFromStoreId(
110 "1", &otrProfile, false)); 111 "1", &otrProfile, false));
111 } 112 }
112 113
113 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { 114 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
114 net::CanonicalCookie canonical_cookie1( 115 net::CanonicalCookie canonical_cookie1(
115 GURL(), "ABC", "DEF", "www.foobar.com", "/", 116 GURL(), "ABC", "DEF", "www.foobar.com", "/",
116 base::Time(), base::Time(), base::Time(), 117 base::Time(), base::Time(), base::Time(),
117 false, false); 118 false, false, net::COOKIE_PRIORITY_DEFAULT);
118 scoped_ptr<Cookie> cookie1( 119 scoped_ptr<Cookie> cookie1(
119 cookies_helpers::CreateCookie( 120 cookies_helpers::CreateCookie(
120 canonical_cookie1, "some cookie store")); 121 canonical_cookie1, "some cookie store"));
121 EXPECT_EQ("ABC", cookie1->name); 122 EXPECT_EQ("ABC", cookie1->name);
122 EXPECT_EQ("DEF", cookie1->value); 123 EXPECT_EQ("DEF", cookie1->value);
123 EXPECT_EQ("www.foobar.com", cookie1->domain); 124 EXPECT_EQ("www.foobar.com", cookie1->domain);
124 EXPECT_TRUE(cookie1->host_only); 125 EXPECT_TRUE(cookie1->host_only);
125 EXPECT_EQ("/", cookie1->path); 126 EXPECT_EQ("/", cookie1->path);
126 EXPECT_FALSE(cookie1->secure); 127 EXPECT_FALSE(cookie1->secure);
127 EXPECT_FALSE(cookie1->http_only); 128 EXPECT_FALSE(cookie1->http_only);
128 EXPECT_TRUE(cookie1->session); 129 EXPECT_TRUE(cookie1->session);
129 EXPECT_FALSE(cookie1->expiration_date.get()); 130 EXPECT_FALSE(cookie1->expiration_date.get());
130 EXPECT_EQ("some cookie store", cookie1->store_id); 131 EXPECT_EQ("some cookie store", cookie1->store_id);
131 132
132 net::CanonicalCookie canonical_cookie2( 133 net::CanonicalCookie canonical_cookie2(
133 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), 134 GURL(), "ABC", "DEF", ".foobar.com", "/",
134 base::Time::FromDoubleT(10000), base::Time(), false, false); 135 base::Time(), base::Time::FromDoubleT(10000), base::Time(),
136 false, false, net::COOKIE_PRIORITY_DEFAULT);
135 scoped_ptr<Cookie> cookie2( 137 scoped_ptr<Cookie> cookie2(
136 cookies_helpers::CreateCookie( 138 cookies_helpers::CreateCookie(
137 canonical_cookie2, "some cookie store")); 139 canonical_cookie2, "some cookie store"));
138 EXPECT_FALSE(cookie2->host_only); 140 EXPECT_FALSE(cookie2->host_only);
139 EXPECT_FALSE(cookie2->session); 141 EXPECT_FALSE(cookie2->session);
140 ASSERT_TRUE(cookie2->expiration_date.get()); 142 ASSERT_TRUE(cookie2->expiration_date.get());
141 EXPECT_EQ(10000, *cookie2->expiration_date); 143 EXPECT_EQ(10000, *cookie2->expiration_date);
142 144
143 TestingProfile profile; 145 TestingProfile profile;
144 ListValue* tab_ids_list = new ListValue(); 146 ListValue* tab_ids_list = new ListValue();
145 std::vector<int> tab_ids; 147 std::vector<int> tab_ids;
146 scoped_ptr<CookieStore> cookie_store( 148 scoped_ptr<CookieStore> cookie_store(
147 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); 149 cookies_helpers::CreateCookieStore(&profile, tab_ids_list));
148 EXPECT_EQ("0", cookie_store->id); 150 EXPECT_EQ("0", cookie_store->id);
149 EXPECT_EQ(tab_ids, cookie_store->tab_ids); 151 EXPECT_EQ(tab_ids, cookie_store->tab_ids);
150 } 152 }
151 153
152 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { 154 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
153 net::CanonicalCookie cookie1( 155 net::CanonicalCookie cookie1(
154 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), 156 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(),
155 base::Time(), false, false); 157 base::Time(), false, false, net::COOKIE_PRIORITY_DEFAULT);
156 EXPECT_EQ("http://www.foobar.com/", 158 EXPECT_EQ("http://www.foobar.com/",
157 cookies_helpers::GetURLFromCanonicalCookie( 159 cookies_helpers::GetURLFromCanonicalCookie(
158 cookie1).spec()); 160 cookie1).spec());
159 161
160 net::CanonicalCookie cookie2( 162 net::CanonicalCookie cookie2(
161 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), 163 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(),
162 base::Time(), true, false); 164 base::Time(), true, false, net::COOKIE_PRIORITY_DEFAULT);
163 EXPECT_EQ("https://helloworld.com/", 165 EXPECT_EQ("https://helloworld.com/",
164 cookies_helpers::GetURLFromCanonicalCookie( 166 cookies_helpers::GetURLFromCanonicalCookie(
165 cookie2).spec()); 167 cookie2).spec());
166 } 168 }
167 169
168 TEST_F(ExtensionCookiesTest, EmptyDictionary) { 170 TEST_F(ExtensionCookiesTest, EmptyDictionary) {
169 DictionaryValue dict; 171 DictionaryValue dict;
170 GetAll::Params::Details details; 172 GetAll::Params::Details details;
171 bool rv = GetAll::Params::Details::Populate(dict, &details); 173 bool rv = GetAll::Params::Details::Populate(dict, &details);
172 ASSERT_TRUE(rv); 174 ASSERT_TRUE(rv);
(...skipping 24 matching lines...) Expand all
197 cookies_helpers::MatchFilter filter(&params->details); 199 cookies_helpers::MatchFilter filter(&params->details);
198 net::CanonicalCookie cookie(GURL(), 200 net::CanonicalCookie cookie(GURL(),
199 std::string(), 201 std::string(),
200 std::string(), 202 std::string(),
201 tests[i].domain, 203 tests[i].domain,
202 std::string(), 204 std::string(),
203 base::Time(), 205 base::Time(),
204 base::Time(), 206 base::Time(),
205 base::Time(), 207 base::Time(),
206 false, 208 false,
207 false); 209 false,
210 net::COOKIE_PRIORITY_DEFAULT);
208 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); 211 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie));
209 } 212 }
210 } 213 }
211 214
212 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { 215 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) {
213 net::CanonicalCookie canonical_cookie(GURL(), 216 net::CanonicalCookie canonical_cookie(GURL(),
214 std::string(), 217 std::string(),
215 "011Q255bNX_1!yd\203e+", 218 "011Q255bNX_1!yd\203e+",
216 "test.com", 219 "test.com",
217 "/path\203", 220 "/path\203",
218 base::Time(), 221 base::Time(),
219 base::Time(), 222 base::Time(),
220 base::Time(), 223 base::Time(),
221 false, 224 false,
222 false); 225 false,
226 net::COOKIE_PRIORITY_DEFAULT);
223 scoped_ptr<Cookie> cookie( 227 scoped_ptr<Cookie> cookie(
224 cookies_helpers::CreateCookie( 228 cookies_helpers::CreateCookie(
225 canonical_cookie, "some cookie store")); 229 canonical_cookie, "some cookie store"));
226 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); 230 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value);
227 EXPECT_EQ(std::string(), cookie->path); 231 EXPECT_EQ(std::string(), cookie->path);
228 } 232 }
229 233
230 } // namespace extensions 234 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/cookies/cookies_api.cc ('k') | content/browser/net/sqlite_persistent_cookie_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698