| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, net::CookieSameSite::DEFAULT_MODE, | 88 base::Time(), false, false, net::CookieSameSite::DEFAULT_MODE, |
| 89 net::COOKIE_PRIORITY_DEFAULT); | 89 net::COOKIE_PRIORITY_DEFAULT); |
| 90 scoped_ptr<Cookie> cookie1( | 90 Cookie cookie1 = |
| 91 cookies_helpers::CreateCookie( | 91 cookies_helpers::CreateCookie(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_EQ(api::cookies::SAME_SITE_STATUS_NO_RESTRICTION, cookie1.same_site); |
| 100 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_NO_RESTRICTION, cookie1->same_site); | 100 EXPECT_TRUE(cookie1.session); |
| 101 EXPECT_TRUE(cookie1->session); | 101 EXPECT_FALSE(cookie1.expiration_date.get()); |
| 102 EXPECT_FALSE(cookie1->expiration_date.get()); | 102 EXPECT_EQ("some cookie store", cookie1.store_id); |
| 103 EXPECT_EQ("some cookie store", cookie1->store_id); | |
| 104 | 103 |
| 105 net::CanonicalCookie canonical_cookie2( | 104 net::CanonicalCookie canonical_cookie2( |
| 106 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), | 105 GURL(), "ABC", "DEF", ".foobar.com", "/", base::Time(), |
| 107 base::Time::FromDoubleT(10000), base::Time(), false, false, | 106 base::Time::FromDoubleT(10000), base::Time(), false, false, |
| 108 net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_DEFAULT); | 107 net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
| 109 scoped_ptr<Cookie> cookie2( | 108 Cookie cookie2 = |
| 110 cookies_helpers::CreateCookie( | 109 cookies_helpers::CreateCookie(canonical_cookie2, "some cookie store"); |
| 111 canonical_cookie2, "some cookie store")); | 110 EXPECT_FALSE(cookie2.host_only); |
| 112 EXPECT_FALSE(cookie2->host_only); | 111 EXPECT_FALSE(cookie2.session); |
| 113 EXPECT_FALSE(cookie2->session); | 112 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2.same_site); |
| 114 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2->same_site); | 113 ASSERT_TRUE(cookie2.expiration_date.get()); |
| 115 ASSERT_TRUE(cookie2->expiration_date.get()); | 114 EXPECT_EQ(10000, *cookie2.expiration_date); |
| 116 EXPECT_EQ(10000, *cookie2->expiration_date); | |
| 117 | 115 |
| 118 TestingProfile profile; | 116 TestingProfile profile; |
| 119 base::ListValue* tab_ids_list = new base::ListValue(); | 117 base::ListValue* tab_ids_list = new base::ListValue(); |
| 120 std::vector<int> tab_ids; | 118 std::vector<int> tab_ids; |
| 121 scoped_ptr<CookieStore> cookie_store( | 119 CookieStore cookie_store = |
| 122 cookies_helpers::CreateCookieStore(&profile, tab_ids_list)); | 120 cookies_helpers::CreateCookieStore(&profile, tab_ids_list); |
| 123 EXPECT_EQ("0", cookie_store->id); | 121 EXPECT_EQ("0", cookie_store.id); |
| 124 EXPECT_EQ(tab_ids, cookie_store->tab_ids); | 122 EXPECT_EQ(tab_ids, cookie_store.tab_ids); |
| 125 } | 123 } |
| 126 | 124 |
| 127 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { | 125 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { |
| 128 net::CanonicalCookie cookie1(GURL(), "ABC", "DEF", "www.foobar.com", "/", | 126 net::CanonicalCookie cookie1(GURL(), "ABC", "DEF", "www.foobar.com", "/", |
| 129 base::Time(), base::Time(), base::Time(), false, | 127 base::Time(), base::Time(), base::Time(), false, |
| 130 false, net::CookieSameSite::DEFAULT_MODE, | 128 false, net::CookieSameSite::DEFAULT_MODE, |
| 131 net::COOKIE_PRIORITY_DEFAULT); | 129 net::COOKIE_PRIORITY_DEFAULT); |
| 132 EXPECT_EQ("http://www.foobar.com/", | 130 EXPECT_EQ("http://www.foobar.com/", |
| 133 cookies_helpers::GetURLFromCanonicalCookie( | 131 cookies_helpers::GetURLFromCanonicalCookie( |
| 134 cookie1).spec()); | 132 cookie1).spec()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); | 176 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
| 179 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); | 177 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 | 180 |
| 183 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { | 181 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { |
| 184 net::CanonicalCookie canonical_cookie( | 182 net::CanonicalCookie canonical_cookie( |
| 185 GURL(), std::string(), "011Q255bNX_1!yd\203e+", "test.com", "/path\203", | 183 GURL(), std::string(), "011Q255bNX_1!yd\203e+", "test.com", "/path\203", |
| 186 base::Time(), base::Time(), base::Time(), false, false, | 184 base::Time(), base::Time(), base::Time(), false, false, |
| 187 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); | 185 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); |
| 188 scoped_ptr<Cookie> cookie( | 186 Cookie cookie = |
| 189 cookies_helpers::CreateCookie( | 187 cookies_helpers::CreateCookie(canonical_cookie, "some cookie store"); |
| 190 canonical_cookie, "some cookie store")); | 188 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" |
| 191 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value); | 189 "e+"), |
| 192 EXPECT_EQ(std::string(), cookie->path); | 190 cookie.value); |
| 191 EXPECT_EQ(std::string(), cookie.path); |
| 193 } | 192 } |
| 194 | 193 |
| 195 } // namespace extensions | 194 } // namespace extensions |
| OLD | NEW |