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" | |
9 | |
10 #include <stddef.h> | 8 #include <stddef.h> |
11 | 9 |
| 10 #include <utility> |
| 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 15 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
15 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 16 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
16 #include "chrome/common/extensions/api/cookies.h" | 17 #include "chrome/common/extensions/api/cookies.h" |
17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "net/cookies/canonical_cookie.h" | 20 #include "net/cookies/canonical_cookie.h" |
20 #include "net/cookies/cookie_constants.h" | 21 #include "net/cookies/cookie_constants.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
22 | 24 |
23 using extensions::api::cookies::Cookie; | 25 using extensions::api::cookies::Cookie; |
24 using extensions::api::cookies::CookieStore; | 26 using extensions::api::cookies::CookieStore; |
25 | 27 |
26 namespace GetAll = extensions::api::cookies::GetAll; | 28 namespace GetAll = extensions::api::cookies::GetAll; |
27 | 29 |
28 namespace extensions { | 30 namespace extensions { |
29 | 31 |
30 namespace keys = cookies_api_constants; | 32 namespace keys = cookies_api_constants; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ASSERT_NE(nullptr, canonical_cookie2.get()); | 114 ASSERT_NE(nullptr, canonical_cookie2.get()); |
113 Cookie cookie2 = | 115 Cookie cookie2 = |
114 cookies_helpers::CreateCookie(*canonical_cookie2, "some cookie store"); | 116 cookies_helpers::CreateCookie(*canonical_cookie2, "some cookie store"); |
115 EXPECT_FALSE(cookie2.host_only); | 117 EXPECT_FALSE(cookie2.host_only); |
116 EXPECT_FALSE(cookie2.session); | 118 EXPECT_FALSE(cookie2.session); |
117 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2.same_site); | 119 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2.same_site); |
118 ASSERT_TRUE(cookie2.expiration_date.get()); | 120 ASSERT_TRUE(cookie2.expiration_date.get()); |
119 EXPECT_EQ(10000, *cookie2.expiration_date); | 121 EXPECT_EQ(10000, *cookie2.expiration_date); |
120 | 122 |
121 TestingProfile profile; | 123 TestingProfile profile; |
122 base::ListValue* tab_ids_list = new base::ListValue(); | 124 auto tab_ids_list = base::MakeUnique<base::ListValue>(); |
123 std::vector<int> tab_ids; | 125 std::vector<int> tab_ids; |
124 CookieStore cookie_store = | 126 CookieStore cookie_store = |
125 cookies_helpers::CreateCookieStore(&profile, tab_ids_list); | 127 cookies_helpers::CreateCookieStore(&profile, std::move(tab_ids_list)); |
126 EXPECT_EQ("0", cookie_store.id); | 128 EXPECT_EQ("0", cookie_store.id); |
127 EXPECT_EQ(tab_ids, cookie_store.tab_ids); | 129 EXPECT_EQ(tab_ids, cookie_store.tab_ids); |
128 } | 130 } |
129 | 131 |
130 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 132 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
131 std::unique_ptr<net::CanonicalCookie> cookie1(net::CanonicalCookie::Create( | 133 std::unique_ptr<net::CanonicalCookie> cookie1(net::CanonicalCookie::Create( |
132 GURL("http://example.com"), "ABC", "DEF", "example.com", "/", | 134 GURL("http://example.com"), "ABC", "DEF", "example.com", "/", |
133 base::Time(), base::Time(), false, false, | 135 base::Time(), base::Time(), false, false, |
134 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT)); | 136 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT)); |
135 ASSERT_NE(nullptr, cookie1.get()); | 137 ASSERT_NE(nullptr, cookie1.get()); |
(...skipping 25 matching lines...) Expand all Loading... |
161 {".bar.com", "http://bar.com", "bar.com", true}, | 163 {".bar.com", "http://bar.com", "bar.com", true}, |
162 {"bar.com", "http://foo.bar.com", "", true}, | 164 {"bar.com", "http://foo.bar.com", "", true}, |
163 {"bar.com", "http://bar.foo.com", "", false}, | 165 {"bar.com", "http://bar.foo.com", "", false}, |
164 {".bar.com", "http://foo.bar.com", ".foo.bar.com", true}, | 166 {".bar.com", "http://foo.bar.com", ".foo.bar.com", true}, |
165 {".bar.com", "http://baz.foo.bar.com", "", true}, | 167 {".bar.com", "http://baz.foo.bar.com", "", true}, |
166 {"foo.bar.com", "http://bar.com", ".bar.com", false}}; | 168 {"foo.bar.com", "http://bar.com", ".bar.com", false}}; |
167 | 169 |
168 for (size_t i = 0; i < arraysize(tests); ++i) { | 170 for (size_t i = 0; i < arraysize(tests); ++i) { |
169 // Build up the Params struct. | 171 // Build up the Params struct. |
170 base::ListValue args; | 172 base::ListValue args; |
171 base::DictionaryValue* dict = new base::DictionaryValue(); | 173 auto dict = base::MakeUnique<base::DictionaryValue>(); |
172 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); | 174 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); |
173 args.Set(0, dict); | 175 args.Set(0, std::move(dict)); |
174 std::unique_ptr<GetAll::Params> params(GetAll::Params::Create(args)); | 176 std::unique_ptr<GetAll::Params> params(GetAll::Params::Create(args)); |
175 | 177 |
176 cookies_helpers::MatchFilter filter(¶ms->details); | 178 cookies_helpers::MatchFilter filter(¶ms->details); |
177 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( | 179 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( |
178 GURL(tests[i].url), std::string(), std::string(), tests[i].domain, | 180 GURL(tests[i].url), std::string(), std::string(), tests[i].domain, |
179 std::string(), base::Time(), base::Time(), false, false, | 181 std::string(), base::Time(), base::Time(), false, false, |
180 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT)); | 182 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT)); |
181 ASSERT_NE(nullptr, cookie.get()); | 183 ASSERT_NE(nullptr, cookie.get()); |
182 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(*cookie)); | 184 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(*cookie)); |
183 } | 185 } |
184 } | 186 } |
185 | 187 |
186 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { | 188 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { |
187 std::unique_ptr<net::CanonicalCookie> canonical_cookie( | 189 std::unique_ptr<net::CanonicalCookie> canonical_cookie( |
188 net::CanonicalCookie::Create(GURL("http://test.com"), | 190 net::CanonicalCookie::Create(GURL("http://test.com"), |
189 "=011Q255bNX_1!yd\203e+;path=/path\203", | 191 "=011Q255bNX_1!yd\203e+;path=/path\203", |
190 base::Time(), net::CookieOptions())); | 192 base::Time(), net::CookieOptions())); |
191 ASSERT_NE(nullptr, canonical_cookie.get()); | 193 ASSERT_NE(nullptr, canonical_cookie.get()); |
192 Cookie cookie = | 194 Cookie cookie = |
193 cookies_helpers::CreateCookie(*canonical_cookie, "some cookie store"); | 195 cookies_helpers::CreateCookie(*canonical_cookie, "some cookie store"); |
194 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" | 196 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" |
195 "e+"), | 197 "e+"), |
196 cookie.value); | 198 cookie.value); |
197 EXPECT_EQ(std::string(), cookie.path); | 199 EXPECT_EQ(std::string(), cookie.path); |
198 } | 200 } |
199 | 201 |
200 } // namespace extensions | 202 } // namespace extensions |
OLD | NEW |