Index: third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp |
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp |
index a87f84e3f445462ac6625674ab18ffed7d8fd5cc..a31ec683dcca085ec93a6ef21b5f0014cfe7d443 100644 |
--- a/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp |
+++ b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp |
@@ -123,13 +123,14 @@ protected: |
return data; |
} |
- void runSetUp(ViewportState viewportState, PreloadState preloadState = PreloadEnabled) |
+ void runSetUp(ViewportState viewportState, PreloadState preloadState = PreloadEnabled, ReferrerPolicy documentReferrerPolicy = ReferrerPolicyDefault) |
{ |
HTMLParserOptions options(&m_dummyPageHolder->document()); |
KURL documentURL(ParsedURLString, "http://whatever.test/"); |
m_dummyPageHolder->document().settings()->setViewportEnabled(viewportState == ViewportEnabled); |
m_dummyPageHolder->document().settings()->setViewportMetaEnabled(viewportState == ViewportEnabled); |
m_dummyPageHolder->document().settings()->setDoHtmlPreloadScanning(preloadState == PreloadEnabled); |
+ m_dummyPageHolder->document().setReferrerPolicy(documentReferrerPolicy); |
m_scanner = HTMLPreloadScanner::create(options, documentURL, CachedDocumentParameters::create(&m_dummyPageHolder->document()), createMediaValuesData()); |
} |
@@ -362,6 +363,28 @@ TEST_F(HTMLPreloadScannerTest, testReferrerPolicy) |
test(testCase); |
} |
+// Tests that a document-level referrer policy (e.g. one set by HTTP |
+// header) is applied for preload requests. |
+TEST_F(HTMLPreloadScannerTest, testReferrerPolicyOnDocument) |
+{ |
+ runSetUp(ViewportEnabled, PreloadEnabled, ReferrerPolicyOrigin); |
+ ReferrerPolicyTestCase testCases[] = { |
+ { "http://example.test", "<img src='blah.gif'/>", "blah.gif", "http://example.test/", Resource::Image, 0, ReferrerPolicyOrigin }, |
+ { "http://example.test", "<style>@import url('blah.css');</style>", "blah.css", "http://example.test/", Resource::CSSStyleSheet, 0, ReferrerPolicyOrigin }, |
+ // Tests that a meta-delivered referrer policy with an |
+ // unrecognized policy value does not override the document's |
+ // referrer policy. |
+ { "http://example.test", "<meta name='referrer' content='not-a-valid-policy'><img src='bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPolicyOrigin }, |
+ // Tests that a meta-delivered referrer policy with a |
+ // valid policy value does override the document's |
+ // referrer policy. |
+ { "http://example.test", "<meta name='referrer' content='unsafe-url'><img src='bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPolicyAlways }, |
+ }; |
+ |
+ for (const auto& testCase : testCases) |
+ test(testCase); |
+} |
+ |
TEST_F(HTMLPreloadScannerTest, testLinkRelPreload) |
{ |
TestCase testCases[] = { |