Bug 1329045 part 2: Convert some global variables to local variables, in test_use_with_hsts.html. r?xidorn
(Before we introduced async/await in this test, some of these needed to be
global, because they were used in several callbacks.)
MozReview-Commit-ID: 7mDzmUx1jQ
--- a/dom/svg/test/test_use_with_hsts.html
+++ b/dom/svg/test/test_use_with_hsts.html
@@ -42,22 +42,16 @@ https://bugzilla.mozilla.org/show_bug.cg
const iframe = document.getElementById("myIframe");
const iframeWin = iframe.contentWindow;
// URI for our testcase with 'use' element, via HTTP and HTTPS:
const insecureURI = "http://example.com/tests/dom/svg/test/use-with-hsts-helper.html";
const secureURI = "https://example.com/tests/dom/svg/test/use-with-hsts-helper.html";
- // Snapshots that we'll populate below:
- var blankSnapshot; // Snapshot of blank iframe.
- var refSnapshot; // Snapshot of lime reference rendering in iframe.
- var secureSnapshot; // Snapshot of testcase using HTTPS.
- var upgradedSnapshot; // Snapshot of testcase using HTTP-upgraded-to-HTTPS.
-
// Bookkeeping to be sure receiveMessage is called as many times as we expect:
var numPostMessageCalls = 0;
const expectedNumPostMessageCalls = 2; // (We load the helper file twice.)
// Helper function, called via postMessage, to check iframe's actual location:
function receiveMessage(event) {
is(event.data, secureURI, "iframe should end up viewing secure URI");
numPostMessageCalls++;
@@ -74,52 +68,52 @@ https://bugzilla.mozilla.org/show_bug.cg
});
}
// MAIN TEST CODE BEGINS HERE.
async function runTest() {
// Capture a snapshot with nothing in the iframe, so we can do a
// sanity-check not-equal comparison against our reference case, to be
// sure we're rendering anything at all:
- blankSnapshot = snapshotWindow(iframeWin);
+ let blankSnapshot = snapshotWindow(iframeWin);
// Load & snapshot a reference case (fully lime):
await LoadIframeAsync("data:text/html,<body style='background:lime'>");
- refSnapshot = snapshotWindow(iframeWin);
+ let refSnapshot = snapshotWindow(iframeWin);
// Ensure reference snapshot looks different from blank snapshot:
assertSnapshots(refSnapshot, blankSnapshot,
false /*not equal*/, null /*no fuzz*/,
"refSnapshot", "blankSnapshot");
// OK, assuming we've got a valid refSnapshot, we can now proceed to
// capture test screenshots.
// Register a postMessage handler, so that iframe can report its location:
window.addEventListener("message", receiveMessage, false);
// Load & snapshot secure (HTTPS) version of testcase, & check against ref:
await LoadIframeAsync(secureURI);
- secureSnapshot = snapshotWindow(iframeWin);
+ let secureSnapshot = snapshotWindow(iframeWin);
assertSnapshots(secureSnapshot, refSnapshot,
true /*equal*/, null /*no fuzz*/,
"secureSnapshot", "refSnapshot");
// Load insecure (HTTP) version of testcase (which should get
// automatically upgraded to secure (HTTPS) under the hood):
await LoadIframeAsync(insecureURI);
// Double-check that iframe is really pointed at insecure URI, to be sure
// we're actually exercising HSTS. (Note that receiveMessage() will make
// sure it's been upgraded to a secure HTTPS URI under the hood.)
is(iframe.src, insecureURI,
"test should've attempted to load insecure HTTP URI, to exercise HSTS");
// Capture snapshot of iframe showing upgraded-to-HTTPS version of testcase:
- upgradedSnapshot = snapshotWindow(iframeWin);
+ let upgradedSnapshot = snapshotWindow(iframeWin);
assertSnapshots(upgradedSnapshot, refSnapshot,
true /*equal*/, null /*no fuzz*/,
"upgradedSnapshot", "refSnapshot");
// Check that the iframe did actually invoke our postMessage handler (which
// is where we verify that the HSTS upgrade actually happened):
is(numPostMessageCalls, expectedNumPostMessageCalls,
"didn't receive as many messages from child iframe as expected");