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 <stddef.h> | 10 #include <stddef.h> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 cookies_helpers::ChooseProfileFromStoreId( | 78 cookies_helpers::ChooseProfileFromStoreId( |
79 "1", profile->GetOffTheRecordProfile(), true)); | 79 "1", profile->GetOffTheRecordProfile(), true)); |
80 EXPECT_EQ(profile->GetOffTheRecordProfile(), | 80 EXPECT_EQ(profile->GetOffTheRecordProfile(), |
81 cookies_helpers::ChooseProfileFromStoreId( | 81 cookies_helpers::ChooseProfileFromStoreId( |
82 "1", profile->GetOffTheRecordProfile(), false)); | 82 "1", profile->GetOffTheRecordProfile(), false)); |
83 } | 83 } |
84 | 84 |
85 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { | 85 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { |
86 net::CanonicalCookie canonical_cookie1( | 86 net::CanonicalCookie canonical_cookie1( |
87 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), | 87 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), |
88 base::Time(), false, false, false, net::COOKIE_PRIORITY_DEFAULT); | 88 base::Time(), false, false, net::CookieSameSite::DEFAULT_MODE, |
| 89 net::COOKIE_PRIORITY_DEFAULT); |
89 scoped_ptr<Cookie> cookie1( | 90 scoped_ptr<Cookie> cookie1( |
90 cookies_helpers::CreateCookie( | 91 cookies_helpers::CreateCookie( |
91 canonical_cookie1, "some cookie store")); | 92 canonical_cookie1, "some cookie store")); |
92 EXPECT_EQ("ABC", cookie1->name); | 93 EXPECT_EQ("ABC", cookie1->name); |
93 EXPECT_EQ("DEF", cookie1->value); | 94 EXPECT_EQ("DEF", cookie1->value); |
94 EXPECT_EQ("www.foobar.com", cookie1->domain); | 95 EXPECT_EQ("www.foobar.com", cookie1->domain); |
95 EXPECT_TRUE(cookie1->host_only); | 96 EXPECT_TRUE(cookie1->host_only); |
96 EXPECT_EQ("/", cookie1->path); | 97 EXPECT_EQ("/", cookie1->path); |
97 EXPECT_FALSE(cookie1->secure); | 98 EXPECT_FALSE(cookie1->secure); |
98 EXPECT_FALSE(cookie1->http_only); | 99 EXPECT_FALSE(cookie1->http_only); |
99 EXPECT_TRUE(cookie1->session); | 100 EXPECT_TRUE(cookie1->session); |
100 EXPECT_FALSE(cookie1->expiration_date.get()); | 101 EXPECT_FALSE(cookie1->expiration_date.get()); |
101 EXPECT_EQ("some cookie store", cookie1->store_id); | 102 EXPECT_EQ("some cookie store", cookie1->store_id); |
102 | 103 |
103 net::CanonicalCookie canonical_cookie2( | 104 net::CanonicalCookie canonical_cookie2( |
104 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), | 105 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), |
105 base::Time::FromDoubleT(10000), base::Time(), false, false, false, | 106 base::Time::FromDoubleT(10000), base::Time(), false, false, |
106 net::COOKIE_PRIORITY_DEFAULT); | 107 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
107 scoped_ptr<Cookie> cookie2( | 108 scoped_ptr<Cookie> cookie2( |
108 cookies_helpers::CreateCookie( | 109 cookies_helpers::CreateCookie( |
109 canonical_cookie2, "some cookie store")); | 110 canonical_cookie2, "some cookie store")); |
110 EXPECT_FALSE(cookie2->host_only); | 111 EXPECT_FALSE(cookie2->host_only); |
111 EXPECT_FALSE(cookie2->session); | 112 EXPECT_FALSE(cookie2->session); |
112 ASSERT_TRUE(cookie2->expiration_date.get()); | 113 ASSERT_TRUE(cookie2->expiration_date.get()); |
113 EXPECT_EQ(10000, *cookie2->expiration_date); | 114 EXPECT_EQ(10000, *cookie2->expiration_date); |
114 | 115 |
115 TestingProfile profile; | 116 TestingProfile profile; |
116 base::ListValue* tab_ids_list = new base::ListValue(); | 117 base::ListValue* tab_ids_list = new base::ListValue(); |
117 std::vector<int> tab_ids; | 118 std::vector<int> tab_ids; |
118 scoped_ptr<CookieStore> cookie_store( | 119 scoped_ptr<CookieStore> cookie_store( |
119 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 120 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
120 EXPECT_EQ("0", cookie_store->id); | 121 EXPECT_EQ("0", cookie_store->id); |
121 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 122 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
122 } | 123 } |
123 | 124 |
124 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 125 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
125 net::CanonicalCookie cookie1(GURL(), "ABC", "DEF", "www.foobar.com", "/", | 126 net::CanonicalCookie cookie1(GURL(), "ABC", "DEF", "www.foobar.com", "/", |
126 base::Time(), base::Time(), base::Time(), false, | 127 base::Time(), base::Time(), base::Time(), false, |
127 false, false, net::COOKIE_PRIORITY_DEFAULT); | 128 false, net::CookieSameSite::DEFAULT_MODE, |
| 129 net::COOKIE_PRIORITY_DEFAULT); |
128 EXPECT_EQ("http://www.foobar.com/", | 130 EXPECT_EQ("http://www.foobar.com/", |
129 cookies_helpers::GetURLFromCanonicalCookie( | 131 cookies_helpers::GetURLFromCanonicalCookie( |
130 cookie1).spec()); | 132 cookie1).spec()); |
131 | 133 |
132 net::CanonicalCookie cookie2(GURL(), "ABC", "DEF", ".helloworld.com", "/", | 134 net::CanonicalCookie cookie2(GURL(), "ABC", "DEF", ".helloworld.com", "/", |
133 base::Time(), base::Time(), base::Time(), true, | 135 base::Time(), base::Time(), base::Time(), true, |
134 false, false, net::COOKIE_PRIORITY_DEFAULT); | 136 false, net::CookieSameSite::DEFAULT_MODE, |
| 137 net::COOKIE_PRIORITY_DEFAULT); |
135 EXPECT_EQ("https://helloworld.com/", | 138 EXPECT_EQ("https://helloworld.com/", |
136 cookies_helpers::GetURLFromCanonicalCookie( | 139 cookies_helpers::GetURLFromCanonicalCookie( |
137 cookie2).spec()); | 140 cookie2).spec()); |
138 } | 141 } |
139 | 142 |
140 TEST_F(ExtensionCookiesTest, EmptyDictionary) { | 143 TEST_F(ExtensionCookiesTest, EmptyDictionary) { |
141 base::DictionaryValue dict; | 144 base::DictionaryValue dict; |
142 GetAll::Params::Details details; | 145 GetAll::Params::Details details; |
143 bool rv = GetAll::Params::Details::Populate(dict, &details); | 146 bool rv = GetAll::Params::Details::Populate(dict, &details); |
144 ASSERT_TRUE(rv); | 147 ASSERT_TRUE(rv); |
(...skipping 15 matching lines...) Expand all Loading... |
160 | 163 |
161 for (size_t i = 0; i < arraysize(tests); ++i) { | 164 for (size_t i = 0; i < arraysize(tests); ++i) { |
162 // Build up the Params struct. | 165 // Build up the Params struct. |
163 base::ListValue args; | 166 base::ListValue args; |
164 base::DictionaryValue* dict = new base::DictionaryValue(); | 167 base::DictionaryValue* dict = new base::DictionaryValue(); |
165 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); | 168 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); |
166 args.Set(0, dict); | 169 args.Set(0, dict); |
167 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); | 170 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); |
168 | 171 |
169 cookies_helpers::MatchFilter filter(¶ms->details); | 172 cookies_helpers::MatchFilter filter(¶ms->details); |
170 net::CanonicalCookie cookie(GURL(), std::string(), std::string(), | 173 net::CanonicalCookie cookie( |
171 tests[i].domain, std::string(), base::Time(), | 174 GURL(), std::string(), std::string(), tests[i].domain, std::string(), |
172 base::Time(), base::Time(), false, false, false, | 175 base::Time(), base::Time(), base::Time(), false, false, |
173 net::COOKIE_PRIORITY_DEFAULT); | 176 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
174 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); | 177 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); |
175 } | 178 } |
176 } | 179 } |
177 | 180 |
178 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { | 181 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { |
179 net::CanonicalCookie canonical_cookie( | 182 net::CanonicalCookie canonical_cookie( |
180 GURL(), std::string(), "011Q255bNX_1!yd\203e+", "test.com", "/path\203", | 183 GURL(), std::string(), "011Q255bNX_1!yd\203e+", "test.com", "/path\203", |
181 base::Time(), base::Time(), base::Time(), false, false, false, | 184 base::Time(), base::Time(), base::Time(), false, false, |
182 net::COOKIE_PRIORITY_DEFAULT); | 185 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
183 scoped_ptr<Cookie> cookie( | 186 scoped_ptr<Cookie> cookie( |
184 cookies_helpers::CreateCookie( | 187 cookies_helpers::CreateCookie( |
185 canonical_cookie, "some cookie store")); | 188 canonical_cookie, "some cookie store")); |
186 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 189 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); |
187 EXPECT_EQ(std::string(), cookie->path); | 190 EXPECT_EQ(std::string(), cookie->path); |
188 } | 191 } |
189 | 192 |
190 } // namespace extensions | 193 } // namespace extensions |
OLD | NEW |