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

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

Issue 2075053003: Add basic Referrer-Policy support for Documents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update test expectation for tweaked console message Created 4 years, 5 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } tests[] = { 187 } tests[] = {
188 { "", ReferrerPolicyDefault },
189 // Test that invalid policy values are ignored.
190 { "not-a-real-policy", ReferrerPolicyDefault },
191 { "not-a-real-policy,also-not-a-real-policy", ReferrerPolicyDefault },
192 { "not-a-real-policy,unsafe-url", ReferrerPolicyAlways },
193 { "unsafe-url,not-a-real-policy", ReferrerPolicyAlways },
194 // Test parsing each of the policy values.
188 { "always", ReferrerPolicyAlways }, 195 { "always", ReferrerPolicyAlways },
189 { "default", ReferrerPolicyNoReferrerWhenDowngrade }, 196 { "default", ReferrerPolicyNoReferrerWhenDowngrade },
190 { "never", ReferrerPolicyNever }, 197 { "never", ReferrerPolicyNever },
191 { "no-referrer", ReferrerPolicyNever }, 198 { "no-referrer", ReferrerPolicyNever },
192 { "no-referrer-when-downgrade", ReferrerPolicyNoReferrerWhenDowngrade }, 199 { "no-referrer-when-downgrade", ReferrerPolicyNoReferrerWhenDowngrade },
193 { "not-a-real-policy", ReferrerPolicyDefault },
194 { "origin", ReferrerPolicyOrigin }, 200 { "origin", ReferrerPolicyOrigin },
195 { "origin-when-crossorigin", ReferrerPolicyOriginWhenCrossOrigin }, 201 { "origin-when-crossorigin", ReferrerPolicyOriginWhenCrossOrigin },
196 { "origin-when-cross-origin", ReferrerPolicyOriginWhenCrossOrigin }, 202 { "origin-when-cross-origin", ReferrerPolicyOriginWhenCrossOrigin },
197 { "unsafe-url", ReferrerPolicyAlways }, 203 { "unsafe-url", ReferrerPolicyAlways },
198 }; 204 };
199 205
200 for (auto test : tests) { 206 for (auto test : tests) {
201 document().setReferrerPolicy(ReferrerPolicyDefault); 207 document().setReferrerPolicy(ReferrerPolicyDefault);
202 208 document().parseAndSetReferrerPolicy(test.policy);
203 document().processReferrerPolicy(test.policy);
204 EXPECT_EQ(test.expected, document().getReferrerPolicy()) << test.policy; 209 EXPECT_EQ(test.expected, document().getReferrerPolicy()) << test.policy;
205 } 210 }
206 } 211 }
207 212
208 TEST_F(DocumentTest, OutgoingReferrer) 213 TEST_F(DocumentTest, OutgoingReferrer)
209 { 214 {
210 document().setURL(KURL(KURL(), "https://www.example.com/hoge#fuga?piyo")); 215 document().setURL(KURL(KURL(), "https://www.example.com/hoge#fuga?piyo"));
211 document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://ww w.example.com/"))); 216 document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://ww w.example.com/")));
212 EXPECT_EQ("https://www.example.com/hoge", document().outgoingReferrer()); 217 EXPECT_EQ("https://www.example.com/hoge", document().outgoingReferrer());
213 } 218 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy()); 283 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy());
279 284
280 origin = SecurityOrigin::createFromString("https://example.test"); 285 origin = SecurityOrigin::createFromString("https://example.test");
281 document().setSecurityOrigin(origin); 286 document().setSecurityOrigin(origin);
282 document().enforceSandboxFlags(mask); 287 document().enforceSandboxFlags(mask);
283 EXPECT_TRUE(document().getSecurityOrigin()->isUnique()); 288 EXPECT_TRUE(document().getSecurityOrigin()->isUnique());
284 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy()); 289 EXPECT_TRUE(document().getSecurityOrigin()->isPotentiallyTrustworthy());
285 } 290 }
286 291
287 } // namespace blink 292 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.cpp ('k') | third_party/WebKit/Source/core/dom/ExecutionContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698