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

Side by Side Diff: third_party/WebKit/Source/core/dom/DocumentTest.cpp

Issue 2278823004: Stop supporting legacy keywords in Referrer-Policy header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: jochen comment Created 4 years, 3 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 /* 1 /*
2 * Copyright (c) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_EQ(link, document().linkManifest()); 177 EXPECT_EQ(link, document().linkManifest());
178 } 178 }
179 179
180 TEST_F(DocumentTest, referrerPolicyParsing) 180 TEST_F(DocumentTest, referrerPolicyParsing)
181 { 181 {
182 EXPECT_EQ(ReferrerPolicyDefault, document().getReferrerPolicy()); 182 EXPECT_EQ(ReferrerPolicyDefault, document().getReferrerPolicy());
183 183
184 struct TestCase { 184 struct TestCase {
185 const char* policy; 185 const char* policy;
186 ReferrerPolicy expected; 186 ReferrerPolicy expected;
187 bool isLegacy;
187 } tests[] = { 188 } tests[] = {
188 { "", ReferrerPolicyDefault }, 189 { "", ReferrerPolicyDefault, false },
189 // Test that invalid policy values are ignored. 190 // Test that invalid policy values are ignored.
190 { "not-a-real-policy", ReferrerPolicyDefault }, 191 { "not-a-real-policy", ReferrerPolicyDefault, false },
191 { "not-a-real-policy,also-not-a-real-policy", ReferrerPolicyDefault }, 192 { "not-a-real-policy,also-not-a-real-policy", ReferrerPolicyDefault, fal se },
192 { "not-a-real-policy,unsafe-url", ReferrerPolicyAlways }, 193 { "not-a-real-policy,unsafe-url", ReferrerPolicyAlways, false },
193 { "unsafe-url,not-a-real-policy", ReferrerPolicyAlways }, 194 { "unsafe-url,not-a-real-policy", ReferrerPolicyAlways, false },
194 // Test parsing each of the policy values. 195 // Test parsing each of the policy values.
195 { "always", ReferrerPolicyAlways }, 196 { "always", ReferrerPolicyAlways, true },
196 { "default", ReferrerPolicyNoReferrerWhenDowngrade }, 197 { "default", ReferrerPolicyNoReferrerWhenDowngrade, true },
197 { "never", ReferrerPolicyNever }, 198 { "never", ReferrerPolicyNever, true },
198 { "no-referrer", ReferrerPolicyNever }, 199 { "no-referrer", ReferrerPolicyNever, false },
199 { "no-referrer-when-downgrade", ReferrerPolicyNoReferrerWhenDowngrade }, 200 { "default", ReferrerPolicyNoReferrerWhenDowngrade, true },
200 { "origin", ReferrerPolicyOrigin }, 201 { "no-referrer-when-downgrade", ReferrerPolicyNoReferrerWhenDowngrade, f alse },
201 { "origin-when-crossorigin", ReferrerPolicyOriginWhenCrossOrigin }, 202 { "origin", ReferrerPolicyOrigin, false },
202 { "origin-when-cross-origin", ReferrerPolicyOriginWhenCrossOrigin }, 203 { "origin-when-crossorigin", ReferrerPolicyOriginWhenCrossOrigin, true } ,
204 { "origin-when-cross-origin", ReferrerPolicyOriginWhenCrossOrigin, false },
203 { "unsafe-url", ReferrerPolicyAlways }, 205 { "unsafe-url", ReferrerPolicyAlways },
204 }; 206 };
205 207
206 for (auto test : tests) { 208 for (auto test : tests) {
207 document().setReferrerPolicy(ReferrerPolicyDefault); 209 document().setReferrerPolicy(ReferrerPolicyDefault);
208 document().parseAndSetReferrerPolicy(test.policy); 210 if (test.isLegacy) {
211 // Legacy keyword support must be explicitly enabled for the policy to parse successfully.
212 document().parseAndSetReferrerPolicy(test.policy);
213 EXPECT_EQ(ReferrerPolicyDefault, document().getReferrerPolicy());
214 document().parseAndSetReferrerPolicy(test.policy, true);
215 } else {
216 document().parseAndSetReferrerPolicy(test.policy);
217 }
209 EXPECT_EQ(test.expected, document().getReferrerPolicy()) << test.policy; 218 EXPECT_EQ(test.expected, document().getReferrerPolicy()) << test.policy;
210 } 219 }
211 } 220 }
212 221
213 TEST_F(DocumentTest, OutgoingReferrer) 222 TEST_F(DocumentTest, OutgoingReferrer)
214 { 223 {
215 document().setURL(KURL(KURL(), "https://www.example.com/hoge#fuga?piyo")); 224 document().setURL(KURL(KURL(), "https://www.example.com/hoge#fuga?piyo"));
216 document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://ww w.example.com/"))); 225 document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://ww w.example.com/")));
217 EXPECT_EQ("https://www.example.com/hoge", document().outgoingReferrer()); 226 EXPECT_EQ("https://www.example.com/hoge", document().outgoingReferrer());
218 } 227 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy()); 292 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy());
284 293
285 origin = SecurityOrigin::createFromString("https://example.test"); 294 origin = SecurityOrigin::createFromString("https://example.test");
286 document().setSecurityOrigin(origin); 295 document().setSecurityOrigin(origin);
287 document().enforceSandboxFlags(mask); 296 document().enforceSandboxFlags(mask);
288 EXPECT_TRUE(document().getSecurityOrigin()->isUnique()); 297 EXPECT_TRUE(document().getSecurityOrigin()->isUnique());
289 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy()); 298 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy());
290 } 299 }
291 300
292 } // namespace blink 301 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698