Bug 1414070 - Specify whether the URL is a test or reference when instructing reftest-content.js to load a new URL. r=dholbert draft
authorJonathan Watt <jwatt@jwatt.org>
Thu, 02 Nov 2017 21:56:38 +0000
changeset 693049 40f98155bd4c4f8bdfce66cc18c34a4aefe9e158
parent 692768 4d3dc7f1d15d2794494bdb801551cd111b4c7fa3
child 738930 12b3ca6c80bd054874f111958860c166e2361bbd
push id87686
push userbmo:jwatt@jwatt.org
push dateFri, 03 Nov 2017 23:43:04 +0000
reviewersdholbert
bugs1414070
milestone58.0a1
Bug 1414070 - Specify whether the URL is a test or reference when instructing reftest-content.js to load a new URL. r=dholbert As part of this change, the confusingly named global variable 'state' is renamed to'currentURLTargetType', and named "enum" values are assigned to it rather than raw integers. MozReview-Commit-ID: mcO1scvZGD
layout/tools/reftest/globals.jsm
layout/tools/reftest/reftest-content.js
layout/tools/reftest/reftest.jsm
--- a/layout/tools/reftest/globals.jsm
+++ b/layout/tools/reftest/globals.jsm
@@ -20,16 +20,20 @@ for (let [key, val] of Object.entries({
   TYPE_REFTEST_EQUAL: '==',
   TYPE_REFTEST_NOTEQUAL: '!=',
   TYPE_LOAD: 'load',     // test without a reference (just test that it does
                          // not assert, crash, hang, or leak)
   TYPE_SCRIPT: 'script', // test contains individual test results
   TYPE_PRINT: 'print',   // test and reference will be printed to PDF's and
                          // compared structurally
 
+  // keep this in sync with reftest-content.js
+  URL_TARGET_TYPE_TEST: 0,      // first url
+  URL_TARGET_TYPE_REFERENCE: 1, // second url, if any
+
   // The order of these constants matters, since when we have a status
   // listed for a *manifest*, we combine the status with the status for
   // the test by using the *larger*.
   // FIXME: In the future, we may also want to use this rule for combining
   // statuses that are on the same line (rather than making the last one
   // win).
   EXPECTED_PASS: 0,
   EXPECTED_FAIL: 1,
@@ -97,18 +101,18 @@ for (let [key, val] of Object.entries({
       // Known problems...
       KnownFail : 0,
       AssertionKnown: 0,
       Random : 0,
       Skip: 0,
       Slow: 0,
     },
     totalTests: 0,
-    state: undefined,
     currentURL: undefined,
+    currentURLTargetType: undefined,
     testLog: [],
     logLevel: undefined,
     logFile: null,
     logger: undefined,
     server: undefined,
     count: 0,
     assertionCount: 0,
 
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -34,16 +34,17 @@ var gHaveCanvasSnapshot = false;
 // "MozPaintWait" and "MozPaintWaitFinished" events that signal when it's OK
 // to take snapshots. We cannot take a snapshot while the number of
 // "MozPaintWait" events fired exceeds the number of "MozPaintWaitFinished"
 // events fired. We count the number of such excess events here. When
 // the counter reaches zero we call gExplicitPendingPaintsCompleteHook.
 var gExplicitPendingPaintCount = 0;
 var gExplicitPendingPaintsCompleteHook;
 var gCurrentURL;
+var gCurrentURLTargetType;
 var gCurrentTestType;
 var gTimeoutHook = null;
 var gFailureTimeout = null;
 var gFailureReason;
 var gAssertionCount = 0;
 
 var gDebug;
 var gVerbose = false;
@@ -52,16 +53,20 @@ var gCurrentTestStartTime;
 var gClearingForAssertionCheck = false;
 
 const TYPE_LOAD = 'load';  // test without a reference (just test that it does
                            // not assert, crash, hang, or leak)
 const TYPE_SCRIPT = 'script'; // test contains individual test results
 const TYPE_PRINT = 'print'; // test and reference will be printed to PDF's and
                             // compared structurally
 
+// keep this in sync with globals.jsm
+const URL_TARGET_TYPE_TEST = 0;      // first url
+const URL_TARGET_TYPE_REFERENCE = 1; // second url, if any
+
 function markupDocumentViewer() {
     return docShell.contentViewer;
 }
 
 function webNavigation() {
     return docShell.QueryInterface(CI.nsIWebNavigation);
 }
 
@@ -137,33 +142,34 @@ function SetFailureTimeout(cb, timeout)
     } else {
       cb();
     }
   }
 
   gFailureTimeout = setTimeout(wrapper, timeout);
 }
 
-function StartTestURI(type, uri, timeout)
+function StartTestURI(type, uri, uriTargetType, timeout)
 {
     // The GC is only able to clean up compartments after the CC runs. Since
     // the JS ref tests disable the normal browser chrome and do not otherwise
     // create substatial DOM garbage, the CC tends not to run enough normally.
     windowUtils().runNextCollectorTimer();
 
     // Reset gExplicitPendingPaintCount in case there was a timeout or
     // the count is out of sync for some other reason
     if (gExplicitPendingPaintCount != 0) {
         LogWarning("Resetting gExplicitPendingPaintCount to zero (currently " +
                    gExplicitPendingPaintCount + "\n");
         gExplicitPendingPaintCount = 0;
     }
 
     gCurrentTestType = type;
     gCurrentURL = uri;
+    gCurrentURLTargetType = uriTargetType;
 
     gCurrentTestStartTime = Date.now();
     if (gFailureTimeout != null) {
         SendException("program error managing timeouts\n");
     }
     SetFailureTimeout(LoadFailed, timeout);
 
     LoadURI(gCurrentURL);
@@ -946,16 +952,17 @@ function RecordResult()
     LogInfo("RecordResult fired");
 
     var currentTestRunTime = Date.now() - gCurrentTestStartTime;
 
     clearTimeout(gFailureTimeout);
     gFailureReason = null;
     gFailureTimeout = null;
     gCurrentURL = null;
+    gCurrentURLTargetType = undefined;
 
     if (gCurrentTestType == TYPE_PRINT) {
         printToPdf(function (status, fileName) {
             SendPrintResult(currentTestRunTime, status, fileName);
             FinishTestItem();
         });
         return;
     }
@@ -1106,43 +1113,45 @@ function RegisterMessageListeners()
         function (m) { RecvLoadScriptTest(m.json.uri, m.json.timeout); }
     );
     addMessageListener(
         "reftest:LoadPrintTest",
         function (m) { RecvLoadPrintTest(m.json.uri, m.json.timeout); }
     );
     addMessageListener(
         "reftest:LoadTest",
-        function (m) { RecvLoadTest(m.json.type, m.json.uri, m.json.timeout); }
+        function (m) { RecvLoadTest(m.json.type, m.json.uri,
+                                    m.json.uriTargetType,
+                                    m.json.timeout); }
     );
     addMessageListener(
         "reftest:ResetRenderingState",
         function (m) { RecvResetRenderingState(); }
     );
 }
 
 function RecvClear()
 {
     gClearingForAssertionCheck = true;
     LoadURI(BLANK_URL_FOR_CLEARING);
 }
 
-function RecvLoadTest(type, uri, timeout)
+function RecvLoadTest(type, uri, uriTargetType, timeout)
 {
-    StartTestURI(type, uri, timeout);
+    StartTestURI(type, uri, uriTargetType, timeout);
 }
 
 function RecvLoadScriptTest(uri, timeout)
 {
-    StartTestURI(TYPE_SCRIPT, uri, timeout);
+    StartTestURI(TYPE_SCRIPT, uri, URL_TARGET_TYPE_TEST, timeout);
 }
 
 function RecvLoadPrintTest(uri, timeout)
 {
-    StartTestURI(TYPE_PRINT, uri, timeout);
+    StartTestURI(TYPE_PRINT, uri, URL_TARGET_TYPE_TEST, timeout);
 }
 
 function RecvResetRenderingState()
 {
     resetZoom();
     resetDisplayportAndViewport();
 }
 
--- a/layout/tools/reftest/reftest.jsm
+++ b/layout/tools/reftest/reftest.jsm
@@ -599,31 +599,35 @@ function StartCurrentTest()
             g.windowUtils.enterChaosMode();
         }
         if (!g.urls[0].needsFocus) {
             Blur();
         }
         var currentTest = g.totalTests - g.urls.length;
         g.containingWindow.document.title = "reftest: " + currentTest + " / " + g.totalTests +
             " (" + Math.floor(100 * (currentTest / g.totalTests)) + "%)";
-        StartCurrentURI(1);
+        StartCurrentURI(URL_TARGET_TYPE_TEST);
     }
 }
 
-function StartCurrentURI(aState)
+function StartCurrentURI(aURLTargetType)
 {
-    g.state = aState;
-    g.currentURL = g.urls[0]["url" + aState].spec;
+    const isStartingRef = (aURLTargetType == URL_TARGET_TYPE_REFERENCE);
+
+    g.currentURL = g.urls[0][isStartingRef ? "url2" : "url1"].spec;
+    g.currentURLTargetType = aURLTargetType;
 
     RestoreChangedPreferences();
 
     var prefs = Components.classes["@mozilla.org/preferences-service;1"].
         getService(Components.interfaces.nsIPrefBranch);
 
-    var prefSettings = g.urls[0]["prefSettings" + aState];
+    const prefSettings =
+      g.urls[0][isStartingRef ? "prefSettings2" : "prefSettings1"];
+
     if (prefSettings.length > 0) {
         var badPref = undefined;
         try {
             prefSettings.forEach(function(ps) {
                 var oldVal;
                 if (ps.type == PREF_BOOLEAN) {
                     try {
                         oldVal = prefs.getBoolPref(ps.name);
@@ -703,17 +707,17 @@ function StartCurrentURI(aState)
                 " (" + Math.floor(100 * (currentTest / g.totalTests)) + "%)\n");
         TestBuffer("START " + g.currentURL);
         var type = g.urls[0].type
         if (TYPE_SCRIPT == type) {
             SendLoadScriptTest(g.currentURL, g.loadTimeout);
         } else if (TYPE_PRINT == type) {
             SendLoadPrintTest(g.currentURL, g.loadTimeout);
         } else {
-            SendLoadTest(type, g.currentURL, g.loadTimeout);
+            SendLoadTest(type, g.currentURL, g.currentURLTargetType, g.loadTimeout);
         }
     }
 }
 
 function DoneTests()
 {
     logger.suiteEnd({'results': g.testResults});
     g.suiteStarted = false
@@ -889,25 +893,25 @@ function RecordResult(testRunTime, error
     if (g.urls[0].type == TYPE_LOAD) {
         ++g.testResults.LoadOnly;
         logger.testStatus(g.urls[0].identifier, "(LOAD ONLY)", "PASS", "PASS");
         g.currentCanvas = null;
         FinishTestItem();
         return;
     }
     if (g.urls[0].type == TYPE_PRINT) {
-        switch (g.state) {
-        case 1:
+        switch (g.currentURLTargetType) {
+        case URL_TARGET_TYPE_TEST:
             // First document has been loaded.
             g.testPrintOutput = typeSpecificResults;
             // Proceed to load the second document.
             CleanUpCrashDumpFiles();
-            StartCurrentURI(2);
+            StartCurrentURI(URL_TARGET_TYPE_REFERENCE);
             break;
-        case 2:
+        case URL_TARGET_TYPE_REFERENCE:
             let pathToTestPdf = g.testPrintOutput;
             let pathToRefPdf = typeSpecificResults;
             comparePdfs(pathToTestPdf, pathToRefPdf, function(error, results) {
                 let expected = g.urls[0].expected;
                 // TODO: We should complain here if results is empty!
                 // (If it's empty, we'll spuriously succeed, regardless of
                 // our expectations)
                 if (error) {
@@ -995,42 +999,42 @@ function RecordResult(testRunTime, error
         if (anyFailed && expected == EXPECTED_PASS) {
             FlushTestBuffer();
         }
 
         FinishTestItem();
         return;
     }
 
-    if (g.urls[0]["prefSettings" + g.state].length == 0 &&
-        g.uriCanvases[g.currentURL]) {
+    const isRecordingRef =
+      (g.currentURLTargetType == URL_TARGET_TYPE_REFERENCE);
+    const prefSettings =
+      g.urls[0][isRecordingRef ? "prefSettings2" : "prefSettings1"];
+
+    if (prefSettings.length == 0 && g.uriCanvases[g.currentURL]) {
         g.currentCanvas = g.uriCanvases[g.currentURL];
     }
     if (g.currentCanvas == null) {
         logger.error(g.currentURL, "program error managing snapshots");
         ++g.testResults.Exception;
     }
-    if (g.state == 1) {
-        g.canvas1 = g.currentCanvas;
-    } else {
-        g.canvas2 = g.currentCanvas;
-    }
+    g[isRecordingRef ? "canvas2" : "canvas1"] = g.currentCanvas;
     g.currentCanvas = null;
 
     ResetRenderingState();
 
-    switch (g.state) {
-        case 1:
+    switch (g.currentURLTargetType) {
+        case URL_TARGET_TYPE_TEST:
             // First document has been loaded.
             // Proceed to load the second document.
 
             CleanUpCrashDumpFiles();
-            StartCurrentURI(2);
+            StartCurrentURI(URL_TARGET_TYPE_REFERENCE);
             break;
-        case 2:
+        case URL_TARGET_TYPE_REFERENCE:
             // Both documents have been loaded. Compare the renderings and see
             // if the comparison result matches the expected result specified
             // in the manifest.
 
             // number of different pixels
             var differences;
             // whether the two renderings match:
             var equal;
@@ -1538,20 +1542,22 @@ function SendLoadScriptTest(uri, timeout
 }
 
 function SendLoadPrintTest(uri, timeout)
 {
     g.browserMessageManager.sendAsyncMessage("reftest:LoadPrintTest",
                                             { uri: uri, timeout: timeout });
 }
 
-function SendLoadTest(type, uri, timeout)
+function SendLoadTest(type, uri, uriType, timeout)
 {
     g.browserMessageManager.sendAsyncMessage("reftest:LoadTest",
-                                            { type: type, uri: uri, timeout: timeout }
+                                            { type: type, uri: uri,
+                                              uriTargetType: uriType,
+                                              timeout: timeout }
     );
 }
 
 function SendResetRenderingState()
 {
     g.browserMessageManager.sendAsyncMessage("reftest:ResetRenderingState");
 }