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