From 9533a4e3f4b290034c36e09368a1e092cb866216 Mon Sep 17 00:00:00 2001 From: Franziskus Kiefer Date: Mon, 11 May 2015 16:18:05 -0700 Subject: [PATCH] Bug 1163743 - Test changes for changing origin-when-crossorigin to origin-when-cross-origin. r=sstamm --- browser/base/content/test/referrer/head.js | 6 +- .../test/csp/test_CSP_referrerdirective.html | 2 +- dom/base/test/mochitest.ini | 4 + dom/base/test/referrerHelper.js | 76 +++++++++++++++++ dom/base/test/test_bug1091883.html | 4 +- dom/base/test/test_bug1163743.html | 44 ++++++++++ dom/base/test/test_bug704320.html | 40 ++++----- dom/base/test/test_bug704320_policyset.html | 82 +------------------ 8 files changed, 153 insertions(+), 105 deletions(-) create mode 100644 dom/base/test/referrerHelper.js create mode 100644 dom/base/test/test_bug1163743.html diff --git a/browser/base/content/test/referrer/head.js b/browser/base/content/test/referrer/head.js index b1c86e6ed156..af4604db0069 100644 --- a/browser/base/content/test/referrer/head.js +++ b/browser/base/content/test/referrer/head.js @@ -49,19 +49,19 @@ let _referrerTests = [ rel: "noreferrer", result: "" // rel=noreferrer trumps meta-referrer }, - // 3. Origin-when-crossorigin policy - this depends on the triggering + // 3. Origin-when-cross-origin policy - this depends on the triggering // principal. We expect full referrer for same-origin requests, // and origin referrer for cross-origin requests. { fromScheme: "https://", toScheme: "https://", - policy: "origin-when-crossorigin", + policy: "origin-when-cross-origin", result: "https://test1.example.com/browser" // same origin }, { fromScheme: "http://", toScheme: "https://", - policy: "origin-when-crossorigin", + policy: "origin-when-cross-origin", result: "http://test1.example.com" // cross origin }, ]; diff --git a/dom/base/test/csp/test_CSP_referrerdirective.html b/dom/base/test/csp/test_CSP_referrerdirective.html index f1ee8721edaa..df3641631044 100644 --- a/dom/base/test/csp/test_CSP_referrerdirective.html +++ b/dom/base/test/csp/test_CSP_referrerdirective.html @@ -44,7 +44,7 @@ var testData = { 'crossorigin': 'origin', 'downgrade': 'origin' }}, - 'origin-when-crossorigin': { 'csp': "script-src * 'unsafe-inline'; referrer origin-when-crossorigin", + 'origin-when-cross-origin': { 'csp': "script-src * 'unsafe-inline'; referrer origin-when-cross-origin", 'expected': { 'sameorigin': 'full', 'crossorigin': 'origin', 'downgrade': 'origin' }}, diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 00361e79c6bc..e9f47b3b572a 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -242,6 +242,7 @@ support-files = w3element_traversal.svg wholeTexty-helper.xml file_nonascii_blob_url.html + referrerHelper.js [test_anonymousContent_api.html] [test_anonymousContent_append_after_reflow.html] @@ -613,6 +614,7 @@ skip-if = buildapp == 'b2g' [test_bug704320.html] skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # b2g (Needs multiple window.open support) android(times out, bug 1100609) e10s(randomly fails, bug 1100362) [test_bug704320_policyset.html] +support-files = referrerHelper.js [test_bug704320_preload.html] [test_bug707142.html] [test_bug708620.html] @@ -665,6 +667,8 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e1 [test_bug1075702.html] [test_bug1101364.html] skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' +[test_bug1163743.html] +support-files = referrerHelper.js [test_caretPositionFromPoint.html] [test_classList.html] # This test fails on the Mac for some reason diff --git a/dom/base/test/referrerHelper.js b/dom/base/test/referrerHelper.js new file mode 100644 index 000000000000..c98d148238c2 --- /dev/null +++ b/dom/base/test/referrerHelper.js @@ -0,0 +1,76 @@ +/** + * Listen for notifications from the child. + * These are sent in case of error, or when the loads we await have completed. + */ +window.addEventListener("message", function(event) { + if (event.data == "childLoadComplete") { + // all loads happen, continue the test. + advance(); + } else if (event.data == "childOverload") { + // too many loads happened in a test frame, abort. + ok(false, "Too many load handlers called in test."); + SimpleTest.finish(); + } else if (event.data.indexOf("fail-") == 0) { + // something else failed in the test frame, abort. + ok(false, "Child failed the test with error " + event.data.substr(5)); + SimpleTest.finish(); + }}); + + +/** + * helper to perform an XHR. + * Used by resetCounter() and checkResults(). + */ +function doXHR(url, onSuccess, onFail) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + if (xhr.status == 200) { + onSuccess(xhr); + } else { + onFail(xhr); + } + }; + xhr.open('GET', url, true); + xhr.send(null); +} + + + +/** + * This triggers state-resetting on the counter server. + */ +function resetCounter() { + doXHR('/tests/dom/base/test/bug704320_counter.sjs?reset', + advance, + function(xhr) { + ok(false, "Need to be able to reset the request counter"); + SimpleTest.finish(); + }); +} + +/** + * Grabs the results via XHR and passes to checker. + */ +function checkResults(testname, expected) { + doXHR('/tests/dom/base/test/bug704320_counter.sjs?results', + function(xhr) { + var results = JSON.parse(xhr.responseText); + info(xhr.responseText); + + ok('img' in results, + testname + " test: some image loads required in results object."); + is(results['img'].count, 2, + testname + " Test: Expected 2 loads for image requests."); + + expected.forEach(function (ref) { + ok(results['img'].referrers.indexOf(ref) >= 0, + testname + " Test: Expected " + ref + " referrer policy in test, results were " + + JSON.stringify(results['img'].referrers) +"."); + }); + advance(); + }, + function(xhr) { + ok(false, "Can't get results from the counter server."); + SimpleTest.finish(); + }); +} diff --git a/dom/base/test/test_bug1091883.html b/dom/base/test/test_bug1091883.html index 2ec4cf1aede2..9789ba970676 100644 --- a/dom/base/test/test_bug1091883.html +++ b/dom/base/test/test_bug1091883.html @@ -5,7 +5,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1091883 --> - + Test for Bug 1091883 @@ -26,7 +26,7 @@ var numOrigins = origins.length; // includes a "frame" that includes a "subframe"; and then this test // navigates this "subframe" to the "target". Both the referrer and // the triggering principal are this test, i.e., "http://mochi.test:8888". -// Since the referrer policy is origin-when-crossorigin, we expect to have +// Since the referrer policy is origin-when-cross-origin, we expect to have // a full referrer if and only if the target is also "http://mochi.test:8888"; // in all other cases, the referrer needs to be the origin alone. var numTests = numOrigins * numOrigins * numOrigins; diff --git a/dom/base/test/test_bug1163743.html b/dom/base/test/test_bug1163743.html new file mode 100644 index 000000000000..411cf6286d08 --- /dev/null +++ b/dom/base/test/test_bug1163743.html @@ -0,0 +1,44 @@ + + + + + + + Test policies for Bug 1163743 + + + + + + + + + + + + + diff --git a/dom/base/test/test_bug704320.html b/dom/base/test/test_bug704320.html index ad8fcc1bff76..de22fe8db3de 100644 --- a/dom/base/test/test_bug704320.html +++ b/dom/base/test/test_bug704320.html @@ -26,25 +26,25 @@ var testIframeUrls = [ 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=no-referrer', 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=unsafe-url', 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=origin', - 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-crossorigin', + 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-cross-origin', // HTTP to HTTPS 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer-when-downgrade', 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer', 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=unsafe-url', 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=origin', - 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=origin-when-crossorigin', + 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=origin-when-cross-origin', // HTTPS to HTTP 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=no-referrer-when-downgrade', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=no-referrer', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=unsafe-url', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=origin', - 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=origin-when-crossorigin', + 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=origin-when-cross-origin', // HTTPS to HTTPS 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=no-referrer-when-downgrade', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=no-referrer', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=unsafe-url', 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=origin', - 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-crossorigin' + 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-cross-origin' ]; var expectedResults = { @@ -58,14 +58,14 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': '', 'origin': '', - 'origin-when-crossorigin': '', + 'origin-when-cross-origin': '', 'no-referrer-when-downgrade': '' }, 'http-to-https': { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=unsafe-url', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com', + 'origin-when-cross-origin': 'http://example.com', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer-when-downgrade' }, // Encrypted and not same-origin @@ -73,7 +73,7 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': '', 'origin': '', - 'origin-when-crossorigin': '', + 'origin-when-cross-origin': '', 'no-referrer-when-downgrade': '' }, // Encrypted @@ -81,7 +81,7 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': '', 'origin': '', - 'origin-when-crossorigin': '', + 'origin-when-cross-origin': '', 'no-referrer-when-downgrade': '' } }, @@ -91,28 +91,28 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=unsafe-url&type=form', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-crossorigin&type=form', + 'origin-when-cross-origin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-cross-origin&type=form', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=no-referrer-when-downgrade&type=form' }, 'http-to-https': { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=https&policy=unsafe-url&type=form', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com', + 'origin-when-cross-origin': 'http://example.com', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer-when-downgrade&type=form' }, 'https-to-http': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=http&policy=unsafe-url&type=form', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com', + 'origin-when-cross-origin': 'https://example.com', 'no-referrer-when-downgrade': '' }, 'https-to-https': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=unsafe-url&type=form', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-crossorigin&type=form', + 'origin-when-cross-origin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-cross-origin&type=form', 'no-referrer-when-downgrade': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=no-referrer-when-downgrade&type=form' } }, @@ -122,28 +122,28 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=unsafe-url&type=window.location', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-crossorigin&type=window.location', + 'origin-when-cross-origin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-cross-origin&type=window.location', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=http&policy=no-referrer-when-downgrade&type=window.location' }, 'http-to-https': { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=https&policy=unsafe-url&type=window.location', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com', + 'origin-when-cross-origin': 'http://example.com', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer-when-downgrade&type=window.location' }, 'https-to-http': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=http&policy=unsafe-url&type=window.location', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com', + 'origin-when-cross-origin': 'https://example.com', 'no-referrer-when-downgrade': '' }, 'https-to-https': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=unsafe-url&type=window.location', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-crossorigin&type=window.location', + 'origin-when-cross-origin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-cross-origin&type=window.location', 'no-referrer-when-downgrade': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-2nd-level-iframe&scheme-from=https&scheme-to=https&policy=no-referrer-when-downgrade&type=window.location' } }, @@ -152,28 +152,28 @@ var expectedResults = { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=unsafe-url', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-crossorigin', + 'origin-when-cross-origin': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=origin-when-cross-origin', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=http&policy=no-referrer-when-downgrade' }, 'http-to-https': { 'no-referrer': '', 'unsafe-url': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=unsafe-url', 'origin': 'http://example.com', - 'origin-when-crossorigin': 'http://example.com', + 'origin-when-cross-origin': 'http://example.com', 'no-referrer-when-downgrade': 'http://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=http&scheme-to=https&policy=no-referrer-when-downgrade' }, 'https-to-http': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=http&policy=unsafe-url', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com', + 'origin-when-cross-origin': 'https://example.com', 'no-referrer-when-downgrade': '' }, 'https-to-https': { 'no-referrer': '', 'unsafe-url': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=unsafe-url', 'origin': 'https://example.com', - 'origin-when-crossorigin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-crossorigin', + 'origin-when-cross-origin': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=origin-when-cross-origin', 'no-referrer-when-downgrade': 'https://example.com/tests/dom/base/test/bug704320.sjs?action=create-1st-level-iframe&scheme-from=https&scheme-to=https&policy=no-referrer-when-downgrade' } } diff --git a/dom/base/test/test_bug704320_policyset.html b/dom/base/test/test_bug704320_policyset.html index 537c8e6f6d1b..411ce94721f8 100644 --- a/dom/base/test/test_bug704320_policyset.html +++ b/dom/base/test/test_bug704320_policyset.html @@ -9,6 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=704320 Test policies for Bug 704320 +