OLD | NEW |
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 Loading... |
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::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); |
| 132 EXPECT_EQ(net::CookiePriorityToString(net::PRIORITY_DEFAULT), |
| 133 cookie1->priority); |
131 | 134 |
132 net::CanonicalCookie canonical_cookie2( | 135 net::CanonicalCookie canonical_cookie2( |
133 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), | 136 GURL(), "ABC", "DEF", ".foobar.com", "/", |
134 base::Time::FromDoubleT(10000), base::Time(), false, false); | 137 base::Time(), base::Time::FromDoubleT(10000), base::Time(), |
| 138 false, false, net::PRIORITY_HIGH); |
135 scoped_ptr<Cookie> cookie2( | 139 scoped_ptr<Cookie> cookie2( |
136 cookies_helpers::CreateCookie( | 140 cookies_helpers::CreateCookie( |
137 canonical_cookie2, "some cookie store")); | 141 canonical_cookie2, "some cookie store")); |
138 EXPECT_FALSE(cookie2->host_only); | 142 EXPECT_FALSE(cookie2->host_only); |
139 EXPECT_FALSE(cookie2->session); | 143 EXPECT_FALSE(cookie2->session); |
140 ASSERT_TRUE(cookie2->expiration_date.get()); | 144 ASSERT_TRUE(cookie2->expiration_date.get()); |
141 EXPECT_EQ(10000, *cookie2->expiration_date); | 145 EXPECT_EQ(10000, *cookie2->expiration_date); |
| 146 EXPECT_EQ("high", cookie2->priority); |
142 | 147 |
143 TestingProfile profile; | 148 TestingProfile profile; |
144 ListValue* tab_ids_list = new ListValue(); | 149 ListValue* tab_ids_list = new ListValue(); |
145 std::vector<int> tab_ids; | 150 std::vector<int> tab_ids; |
146 scoped_ptr<CookieStore> cookie_store( | 151 scoped_ptr<CookieStore> cookie_store( |
147 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 152 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
148 EXPECT_EQ("0", cookie_store->id); | 153 EXPECT_EQ("0", cookie_store->id); |
149 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 154 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
150 } | 155 } |
151 | 156 |
152 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 157 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
153 net::CanonicalCookie cookie1( | 158 net::CanonicalCookie cookie1( |
154 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), | 159 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), |
155 base::Time(), false, false); | 160 base::Time(), false, false, net::PRIORITY_HIGH); |
156 EXPECT_EQ("http://www.foobar.com/", | 161 EXPECT_EQ("http://www.foobar.com/", |
157 cookies_helpers::GetURLFromCanonicalCookie( | 162 cookies_helpers::GetURLFromCanonicalCookie( |
158 cookie1).spec()); | 163 cookie1).spec()); |
159 | 164 |
160 net::CanonicalCookie cookie2( | 165 net::CanonicalCookie cookie2( |
161 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), | 166 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), |
162 base::Time(), true, false); | 167 base::Time(), true, false, net::PRIORITY_LOW); |
163 EXPECT_EQ("https://helloworld.com/", | 168 EXPECT_EQ("https://helloworld.com/", |
164 cookies_helpers::GetURLFromCanonicalCookie( | 169 cookies_helpers::GetURLFromCanonicalCookie( |
165 cookie2).spec()); | 170 cookie2).spec()); |
166 } | 171 } |
167 | 172 |
168 TEST_F(ExtensionCookiesTest, EmptyDictionary) { | 173 TEST_F(ExtensionCookiesTest, EmptyDictionary) { |
169 DictionaryValue dict; | 174 DictionaryValue dict; |
170 GetAll::Params::Details details; | 175 GetAll::Params::Details details; |
171 bool rv = GetAll::Params::Details::Populate(dict, &details); | 176 bool rv = GetAll::Params::Details::Populate(dict, &details); |
172 ASSERT_TRUE(rv); | 177 ASSERT_TRUE(rv); |
(...skipping 24 matching lines...) Expand all Loading... |
197 cookies_helpers::MatchFilter filter(¶ms->details); | 202 cookies_helpers::MatchFilter filter(¶ms->details); |
198 net::CanonicalCookie cookie(GURL(), | 203 net::CanonicalCookie cookie(GURL(), |
199 std::string(), | 204 std::string(), |
200 std::string(), | 205 std::string(), |
201 tests[i].domain, | 206 tests[i].domain, |
202 std::string(), | 207 std::string(), |
203 base::Time(), | 208 base::Time(), |
204 base::Time(), | 209 base::Time(), |
205 base::Time(), | 210 base::Time(), |
206 false, | 211 false, |
207 false); | 212 false, |
| 213 net::PRIORITY_DEFAULT); |
208 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); | 214 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); |
209 } | 215 } |
210 } | 216 } |
211 | 217 |
212 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { | 218 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { |
213 net::CanonicalCookie canonical_cookie(GURL(), | 219 net::CanonicalCookie canonical_cookie(GURL(), |
214 std::string(), | 220 std::string(), |
215 "011Q255bNX_1!yd\203e+", | 221 "011Q255bNX_1!yd\203e+", |
216 "test.com", | 222 "test.com", |
217 "/path\203", | 223 "/path\203", |
218 base::Time(), | 224 base::Time(), |
219 base::Time(), | 225 base::Time(), |
220 base::Time(), | 226 base::Time(), |
221 false, | 227 false, |
222 false); | 228 false, |
| 229 net::PRIORITY_DEFAULT); |
223 scoped_ptr<Cookie> cookie( | 230 scoped_ptr<Cookie> cookie( |
224 cookies_helpers::CreateCookie( | 231 cookies_helpers::CreateCookie( |
225 canonical_cookie, "some cookie store")); | 232 canonical_cookie, "some cookie store")); |
226 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 233 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
227 EXPECT_EQ(std::string(), cookie->path); | 234 EXPECT_EQ(std::string(), cookie->path); |
228 } | 235 } |
229 | 236 |
230 } // namespace extensions | 237 } // namespace extensions |
OLD | NEW |