Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_unittest.cc

Issue 2633663003: Implements strict secure cookies as the default behavior in //net (Closed)
Patch Set: Rebase on ToT Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
78 EXPECT_EQ(profile->GetOffTheRecordProfile(), 78 EXPECT_EQ(profile->GetOffTheRecordProfile(),
79 cookies_helpers::ChooseProfileFromStoreId( 79 cookies_helpers::ChooseProfileFromStoreId(
80 "1", profile->GetOffTheRecordProfile(), true)); 80 "1", profile->GetOffTheRecordProfile(), true));
81 EXPECT_EQ(profile->GetOffTheRecordProfile(), 81 EXPECT_EQ(profile->GetOffTheRecordProfile(),
82 cookies_helpers::ChooseProfileFromStoreId( 82 cookies_helpers::ChooseProfileFromStoreId(
83 "1", profile->GetOffTheRecordProfile(), false)); 83 "1", profile->GetOffTheRecordProfile(), false));
84 } 84 }
85 85
86 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { 86 TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
87 std::unique_ptr<net::CanonicalCookie> canonical_cookie1( 87 std::unique_ptr<net::CanonicalCookie> canonical_cookie1(
88 net::CanonicalCookie::Create(GURL("http://www.example.com"), "ABC", "DEF", 88 net::CanonicalCookie::Create(
89 std::string(), "/", base::Time(), 89 GURL("http://www.example.com"), "ABC", "DEF", std::string(), "/",
90 base::Time(), false, false, 90 base::Time(), base::Time(), false, false,
91 net::CookieSameSite::DEFAULT_MODE, false, 91 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
92 net::COOKIE_PRIORITY_DEFAULT));
93 ASSERT_NE(nullptr, canonical_cookie1.get()); 92 ASSERT_NE(nullptr, canonical_cookie1.get());
94 Cookie cookie1 = 93 Cookie cookie1 =
95 cookies_helpers::CreateCookie(*canonical_cookie1, "some cookie store"); 94 cookies_helpers::CreateCookie(*canonical_cookie1, "some cookie store");
96 EXPECT_EQ("ABC", cookie1.name); 95 EXPECT_EQ("ABC", cookie1.name);
97 EXPECT_EQ("DEF", cookie1.value); 96 EXPECT_EQ("DEF", cookie1.value);
98 EXPECT_EQ("www.example.com", cookie1.domain); 97 EXPECT_EQ("www.example.com", cookie1.domain);
99 EXPECT_TRUE(cookie1.host_only); 98 EXPECT_TRUE(cookie1.host_only);
100 EXPECT_EQ("/", cookie1.path); 99 EXPECT_EQ("/", cookie1.path);
101 EXPECT_FALSE(cookie1.secure); 100 EXPECT_FALSE(cookie1.secure);
102 EXPECT_FALSE(cookie1.http_only); 101 EXPECT_FALSE(cookie1.http_only);
103 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_NO_RESTRICTION, cookie1.same_site); 102 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_NO_RESTRICTION, cookie1.same_site);
104 EXPECT_TRUE(cookie1.session); 103 EXPECT_TRUE(cookie1.session);
105 EXPECT_FALSE(cookie1.expiration_date.get()); 104 EXPECT_FALSE(cookie1.expiration_date.get());
106 EXPECT_EQ("some cookie store", cookie1.store_id); 105 EXPECT_EQ("some cookie store", cookie1.store_id);
107 106
108 std::unique_ptr<net::CanonicalCookie> canonical_cookie2( 107 std::unique_ptr<net::CanonicalCookie> canonical_cookie2(
109 net::CanonicalCookie::Create(GURL("http://example.com"), "ABC", "DEF", 108 net::CanonicalCookie::Create(
110 ".example.com", "/", base::Time(), 109 GURL("http://example.com"), "ABC", "DEF", ".example.com", "/",
111 base::Time::FromDoubleT(10000), false, false, 110 base::Time(), base::Time::FromDoubleT(10000), false, false,
112 net::CookieSameSite::STRICT_MODE, false, 111 net::CookieSameSite::STRICT_MODE, net::COOKIE_PRIORITY_DEFAULT));
113 net::COOKIE_PRIORITY_DEFAULT));
114 ASSERT_NE(nullptr, canonical_cookie2.get()); 112 ASSERT_NE(nullptr, canonical_cookie2.get());
115 Cookie cookie2 = 113 Cookie cookie2 =
116 cookies_helpers::CreateCookie(*canonical_cookie2, "some cookie store"); 114 cookies_helpers::CreateCookie(*canonical_cookie2, "some cookie store");
117 EXPECT_FALSE(cookie2.host_only); 115 EXPECT_FALSE(cookie2.host_only);
118 EXPECT_FALSE(cookie2.session); 116 EXPECT_FALSE(cookie2.session);
119 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2.same_site); 117 EXPECT_EQ(api::cookies::SAME_SITE_STATUS_STRICT, cookie2.same_site);
120 ASSERT_TRUE(cookie2.expiration_date.get()); 118 ASSERT_TRUE(cookie2.expiration_date.get());
121 EXPECT_EQ(10000, *cookie2.expiration_date); 119 EXPECT_EQ(10000, *cookie2.expiration_date);
122 120
123 TestingProfile profile; 121 TestingProfile profile;
124 base::ListValue* tab_ids_list = new base::ListValue(); 122 base::ListValue* tab_ids_list = new base::ListValue();
125 std::vector<int> tab_ids; 123 std::vector<int> tab_ids;
126 CookieStore cookie_store = 124 CookieStore cookie_store =
127 cookies_helpers::CreateCookieStore(&profile, tab_ids_list); 125 cookies_helpers::CreateCookieStore(&profile, tab_ids_list);
128 EXPECT_EQ("0", cookie_store.id); 126 EXPECT_EQ("0", cookie_store.id);
129 EXPECT_EQ(tab_ids, cookie_store.tab_ids); 127 EXPECT_EQ(tab_ids, cookie_store.tab_ids);
130 } 128 }
131 129
132 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { 130 TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
133 std::unique_ptr<net::CanonicalCookie> cookie1(net::CanonicalCookie::Create( 131 std::unique_ptr<net::CanonicalCookie> cookie1(net::CanonicalCookie::Create(
134 GURL("http://example.com"), "ABC", "DEF", "example.com", "/", 132 GURL("http://example.com"), "ABC", "DEF", "example.com", "/",
135 base::Time(), base::Time(), false, false, 133 base::Time(), base::Time(), false, false,
136 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT)); 134 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
137 ASSERT_NE(nullptr, cookie1.get()); 135 ASSERT_NE(nullptr, cookie1.get());
138 EXPECT_EQ("http://example.com/", 136 EXPECT_EQ("http://example.com/",
139 cookies_helpers::GetURLFromCanonicalCookie(*cookie1).spec()); 137 cookies_helpers::GetURLFromCanonicalCookie(*cookie1).spec());
140 138
141 std::unique_ptr<net::CanonicalCookie> cookie2(net::CanonicalCookie::Create( 139 std::unique_ptr<net::CanonicalCookie> cookie2(net::CanonicalCookie::Create(
142 GURL("http://helloworld.com"), "ABC", "DEF", ".helloworld.com", "/", 140 GURL("https://helloworld.com"), "ABC", "DEF", ".helloworld.com", "/",
143 base::Time(), base::Time(), true, false, 141 base::Time(), base::Time(), true, false,
144 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT)); 142 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
145 ASSERT_NE(nullptr, cookie2.get()); 143 ASSERT_NE(nullptr, cookie2.get());
146 EXPECT_EQ("https://helloworld.com/", 144 EXPECT_EQ("https://helloworld.com/",
147 cookies_helpers::GetURLFromCanonicalCookie(*cookie2).spec()); 145 cookies_helpers::GetURLFromCanonicalCookie(*cookie2).spec());
148 } 146 }
149 147
150 TEST_F(ExtensionCookiesTest, EmptyDictionary) { 148 TEST_F(ExtensionCookiesTest, EmptyDictionary) {
151 base::DictionaryValue dict; 149 base::DictionaryValue dict;
152 GetAll::Params::Details details; 150 GetAll::Params::Details details;
153 bool rv = GetAll::Params::Details::Populate(dict, &details); 151 bool rv = GetAll::Params::Details::Populate(dict, &details);
154 ASSERT_TRUE(rv); 152 ASSERT_TRUE(rv);
(...skipping 17 matching lines...) Expand all
172 base::ListValue args; 170 base::ListValue args;
173 base::DictionaryValue* dict = new base::DictionaryValue(); 171 base::DictionaryValue* dict = new base::DictionaryValue();
174 dict->SetString(keys::kDomainKey, std::string(tests[i].filter)); 172 dict->SetString(keys::kDomainKey, std::string(tests[i].filter));
175 args.Set(0, dict); 173 args.Set(0, dict);
176 std::unique_ptr<GetAll::Params> params(GetAll::Params::Create(args)); 174 std::unique_ptr<GetAll::Params> params(GetAll::Params::Create(args));
177 175
178 cookies_helpers::MatchFilter filter(&params->details); 176 cookies_helpers::MatchFilter filter(&params->details);
179 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( 177 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create(
180 GURL(tests[i].url), std::string(), std::string(), tests[i].domain, 178 GURL(tests[i].url), std::string(), std::string(), tests[i].domain,
181 std::string(), base::Time(), base::Time(), false, false, 179 std::string(), base::Time(), base::Time(), false, false,
182 net::CookieSameSite::DEFAULT_MODE, false, 180 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
183 net::COOKIE_PRIORITY_DEFAULT));
184 ASSERT_NE(nullptr, cookie.get()); 181 ASSERT_NE(nullptr, cookie.get());
185 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(*cookie)); 182 EXPECT_EQ(tests[i].matches, filter.MatchesCookie(*cookie));
186 } 183 }
187 } 184 }
188 185
189 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) { 186 TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) {
190 std::unique_ptr<net::CanonicalCookie> canonical_cookie( 187 std::unique_ptr<net::CanonicalCookie> canonical_cookie(
191 net::CanonicalCookie::Create(GURL("http://test.com"), 188 net::CanonicalCookie::Create(GURL("http://test.com"),
192 "=011Q255bNX_1!yd\203e+;path=/path\203", 189 "=011Q255bNX_1!yd\203e+;path=/path\203",
193 base::Time(), net::CookieOptions())); 190 base::Time(), net::CookieOptions()));
194 ASSERT_NE(nullptr, canonical_cookie.get()); 191 ASSERT_NE(nullptr, canonical_cookie.get());
195 Cookie cookie = 192 Cookie cookie =
196 cookies_helpers::CreateCookie(*canonical_cookie, "some cookie store"); 193 cookies_helpers::CreateCookie(*canonical_cookie, "some cookie store");
197 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" 194 EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD"
198 "e+"), 195 "e+"),
199 cookie.value); 196 cookie.value);
200 EXPECT_EQ(std::string(), cookie.path); 197 EXPECT_EQ(std::string(), cookie.path);
201 } 198 }
202 199
203 } // namespace extensions 200 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/cookies/cookies_api.cc ('k') | chrome/browser/net/chrome_network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698