| 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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 false, false, net::COOKIE_PRIORITY_DEFAULT); | 136 false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 137 scoped_ptr<Cookie> cookie2( | 137 scoped_ptr<Cookie> cookie2( |
| 138 cookies_helpers::CreateCookie( | 138 cookies_helpers::CreateCookie( |
| 139 canonical_cookie2, "some cookie store")); | 139 canonical_cookie2, "some cookie store")); |
| 140 EXPECT_FALSE(cookie2->host_only); | 140 EXPECT_FALSE(cookie2->host_only); |
| 141 EXPECT_FALSE(cookie2->session); | 141 EXPECT_FALSE(cookie2->session); |
| 142 ASSERT_TRUE(cookie2->expiration_date.get()); | 142 ASSERT_TRUE(cookie2->expiration_date.get()); |
| 143 EXPECT_EQ(10000, *cookie2->expiration_date); | 143 EXPECT_EQ(10000, *cookie2->expiration_date); |
| 144 | 144 |
| 145 TestingProfile profile; | 145 TestingProfile profile; |
| 146 ListValue* tab_ids_list = new ListValue(); | 146 base::ListValue* tab_ids_list = new base::ListValue(); |
| 147 std::vector<int> tab_ids; | 147 std::vector<int> tab_ids; |
| 148 scoped_ptr<CookieStore> cookie_store( | 148 scoped_ptr<CookieStore> cookie_store( |
| 149 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 149 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); |
| 150 EXPECT_EQ("0", cookie_store->id); | 150 EXPECT_EQ("0", cookie_store->id); |
| 151 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 151 EXPECT_EQ(tab_ids, cookie_store->tab_ids); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 154 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
| 155 net::CanonicalCookie cookie1( | 155 net::CanonicalCookie cookie1( |
| 156 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), | 156 GURL(), "ABC", "DEF", "www.foobar.com", "/", base::Time(), base::Time(), |
| 157 base::Time(), false, false, net::COOKIE_PRIORITY_DEFAULT); | 157 base::Time(), false, false, net::COOKIE_PRIORITY_DEFAULT); |
| 158 EXPECT_EQ("http://www.foobar.com/", | 158 EXPECT_EQ("http://www.foobar.com/", |
| 159 cookies_helpers::GetURLFromCanonicalCookie( | 159 cookies_helpers::GetURLFromCanonicalCookie( |
| 160 cookie1).spec()); | 160 cookie1).spec()); |
| 161 | 161 |
| 162 net::CanonicalCookie cookie2( | 162 net::CanonicalCookie cookie2( |
| 163 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), | 163 GURL(), "ABC", "DEF", ".helloworld.com", "/", base::Time(), base::Time(), |
| 164 base::Time(), true, false, net::COOKIE_PRIORITY_DEFAULT); | 164 base::Time(), true, false, net::COOKIE_PRIORITY_DEFAULT); |
| 165 EXPECT_EQ("https://helloworld.com/", | 165 EXPECT_EQ("https://helloworld.com/", |
| 166 cookies_helpers::GetURLFromCanonicalCookie( | 166 cookies_helpers::GetURLFromCanonicalCookie( |
| 167 cookie2).spec()); | 167 cookie2).spec()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 TEST_F(ExtensionCookiesTest, EmptyDictionary) { | 170 TEST_F(ExtensionCookiesTest, EmptyDictionary) { |
| 171 DictionaryValue dict; | 171 base::DictionaryValue dict; |
| 172 GetAll::Params::Details details; | 172 GetAll::Params::Details details; |
| 173 bool rv = GetAll::Params::Details::Populate(dict, &details); | 173 bool rv = GetAll::Params::Details::Populate(dict, &details); |
| 174 ASSERT_TRUE(rv); | 174 ASSERT_TRUE(rv); |
| 175 cookies_helpers::MatchFilter filter(&details); | 175 cookies_helpers::MatchFilter filter(&details); |
| 176 net::CanonicalCookie cookie; | 176 net::CanonicalCookie cookie; |
| 177 EXPECT_TRUE(filter.MatchesCookie(cookie)); | 177 EXPECT_TRUE(filter.MatchesCookie(cookie)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(ExtensionCookiesTest, DomainMatching) { | 180 TEST_F(ExtensionCookiesTest, DomainMatching) { |
| 181 const DomainMatchCase tests[] = { | 181 const DomainMatchCase tests[] = { |
| 182 { "bar.com", "bar.com", true }, | 182 { "bar.com", "bar.com", true }, |
| 183 { ".bar.com", "bar.com", true }, | 183 { ".bar.com", "bar.com", true }, |
| 184 { "bar.com", "foo.bar.com", true }, | 184 { "bar.com", "foo.bar.com", true }, |
| 185 { "bar.com", "bar.foo.com", false }, | 185 { "bar.com", "bar.foo.com", false }, |
| 186 { ".bar.com", ".foo.bar.com", true }, | 186 { ".bar.com", ".foo.bar.com", true }, |
| 187 { ".bar.com", "baz.foo.bar.com", true }, | 187 { ".bar.com", "baz.foo.bar.com", true }, |
| 188 { "foo.bar.com", ".bar.com", false } | 188 { "foo.bar.com", ".bar.com", false } |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 for (size_t i = 0; i < arraysize(tests); ++i) { | 191 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 192 // Build up the Params struct. | 192 // Build up the Params struct. |
| 193 ListValue args; | 193 base::ListValue args; |
| 194 DictionaryValue* dict = new DictionaryValue(); | 194 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 195 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); | 195 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); |
| 196 args.Set(0, dict); | 196 args.Set(0, dict); |
| 197 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); | 197 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args)); |
| 198 | 198 |
| 199 cookies_helpers::MatchFilter filter(¶ms->details); | 199 cookies_helpers::MatchFilter filter(¶ms->details); |
| 200 net::CanonicalCookie cookie(GURL(), | 200 net::CanonicalCookie cookie(GURL(), |
| 201 std::string(), | 201 std::string(), |
| 202 std::string(), | 202 std::string(), |
| 203 tests[i].domain, | 203 tests[i].domain, |
| 204 std::string(), | 204 std::string(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 225 false, | 225 false, |
| 226 net::COOKIE_PRIORITY_DEFAULT); | 226 net::COOKIE_PRIORITY_DEFAULT); |
| 227 scoped_ptr<Cookie> cookie( | 227 scoped_ptr<Cookie> cookie( |
| 228 cookies_helpers::CreateCookie( | 228 cookies_helpers::CreateCookie( |
| 229 canonical_cookie, "some cookie store")); | 229 canonical_cookie, "some cookie store")); |
| 230 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); |
| 231 EXPECT_EQ(std::string(), cookie->path); | 231 EXPECT_EQ(std::string(), cookie->path); |
| 232 } | 232 } |
| 233 | 233 |
| 234 } // namespace extensions | 234 } // namespace extensions |
| OLD | NEW |