Bug 1329045 part 2: Convert some global variables to local variables, in test_use_with_hsts.html. r?xidorn draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 06 Jan 2017 13:03:22 -0800
changeset 457141 548a4f37ed226cd13296db48fd92e1457c83fccb
parent 457140 6ce65cd43840d2314f351629d55822c6e440c26d
child 541396 3439104a30137d2e29f0811ce32c347a6d6a6b20
push id40684
push userdholbert@mozilla.com
push dateFri, 06 Jan 2017 21:03:46 +0000
reviewersxidorn
bugs1329045
milestone53.0a1
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
dom/svg/test/test_use_with_hsts.html
--- 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");