diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /layout/tools/tests | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'layout/tools/tests')
-rw-r--r-- | layout/tools/tests/content_dumping.html | 101 | ||||
-rw-r--r-- | layout/tools/tests/debug_utils.html | 111 | ||||
-rw-r--r-- | layout/tools/tests/regression_tests.html | 132 | ||||
-rw-r--r-- | layout/tools/tests/regression_tests.js | 553 |
4 files changed, 897 insertions, 0 deletions
diff --git a/layout/tools/tests/content_dumping.html b/layout/tools/tests/content_dumping.html new file mode 100644 index 000000000..d89b802a3 --- /dev/null +++ b/layout/tools/tests/content_dumping.html @@ -0,0 +1,101 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> +<html> +<head> + <title>Control Frame</title> +</head> + +<script type="application/javascript"> + +const nsILayoutDebuggingTools = Components.interfaces.nsILayoutDebuggingTools; +var gDebugTools; + +function Init() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools = Components.classes["@mozilla.org/layout-debug/layout-debuggingtools;1"].createInstance(nsILayoutDebuggingTools); + gDebugTools.init(window.frames.pageframe); +} + +function SetShowFrameBorders(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.visualDebugging = inShow; +} + +function SetShowEventTargetBorders(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.visualEventDebugging = inShow; +} + +function SetShowReflowStats(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.reflowCounts = inShow; +} + +function DumpFrames() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpFrames(); +} + +function DumpContent() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpContent(); +} + +function DumpViews() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpViews(); +} + +function DumpWebShells() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpWebShells(); +} + +function InputKey(inEvent) +{ + if (inEvent.keyCode == KeyEvent.DOM_VK_RETURN) + { + var pageFrame = window.frames.pageframe; + pageFrame.location.href = document.dumpform.urlfield.value; + inEvent.preventDefault(); // avoid form submit on hitting return + } +} + +function IframeLoaded() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + document.dumpform.urlfield.value = window.frames.pageframe.location.href; +} +</script> + +<body onload="Init()"> + +<form name="dumpform"> +<div style="margin-bottom: 5px"> +URL: <input type="text" size="100" name="urlfield" value="http://www.mozilla.org" onkeypress="InputKey(event)"></input> +</div> +<div> +<input type="button" value="Dump Frames" onclick="DumpFrames()"> +<input type="button" value="Dump Content" onclick="DumpContent()"> +<input type="button" value="Dump Views" onclick="DumpViews()"> +<input type="button" value="Dump WebShells" onclick="DumpWebShells()"> + +<input type="checkbox" id="showBordersCheck" name="showBordersCheck" + onchange="SetShowFrameBorders(document.dumpform.showBordersCheck.checked)"></input> +<label for="showBordersCheck">Show Frame Borders</label> +</div> +</form> + +<iframe name="pageframe" style="border: 1px solid black; width:800px; height:800px;" onload="IframeLoaded()"></iframe> + +</body> +</html> + diff --git a/layout/tools/tests/debug_utils.html b/layout/tools/tests/debug_utils.html new file mode 100644 index 000000000..4c2ba98c5 --- /dev/null +++ b/layout/tools/tests/debug_utils.html @@ -0,0 +1,111 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> +<html> +<head> + <title>Layout Debug Utilities</title> +</head> +<script type="application/javascript"> + +const nsILayoutDebuggingTools = Components.interfaces.nsILayoutDebuggingTools; +var gDebugTools; + +function Init() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools = Components.classes["@mozilla.org/layout-debug/layout-debuggingtools;1"].createInstance(nsILayoutDebuggingTools); + gDebugTools.init(window); +} + +function SetShowFrameBorders(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.visualDebugging = inShow; +} + +function SetShowEventTargetBorders(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.visualEventDebugging = inShow; +} + +function SetShowReflowStats(inShow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.reflowCounts = inShow; +} + +function DumpFrames() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpFrames(); +} + +function DumpContent() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpContent(); +} + +function DumpViews() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpViews(); +} + +function DumpWebShells() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + gDebugTools.dumpWebShells(); +} + +</script> + +<body onload="Init()"> +<h1>Layout Debug Utils</h1> + +<p>Note that these only work in debug builds</h1> + +<h2>Global settings</h2> + +<form name="globalsform"> +<div> +<input type="checkbox" id="showBordersCheck" name="showBordersCheck" + onchange="SetShowFrameBorders(document.globalsform.showBordersCheck.checked)"></input> +<label for="showBordersCheck">Show Frame Borders</label> +</div> +<div> +<input type="checkbox" + id="showEventTargetCheck" + name="showEventTargetCheck" + onchange="SetShowEventTargetBorders(document.globalsform.showEventTargetCheck.checked)"></input> +<label for="showEventTargetCheck">Show Event Target Borders</label> +</div> +</form> + +<h2>Per-Window settings</h2> + +<form name="windowform"> +<input type="checkbox" + id="showReflowStatsCheck" + name="showReflowStatsCheck" + onchange="SetShowReflowStats(document.windowform.showReflowStatsCheck.checked)"></input> +<label for="showReflowStatsCheck">Show Reflow Stats</label> +</form> + +<h2>Dumping</h2> + +<form name="dumpform"> +<div> +<input type="button" value="Dump Frames" onclick="DumpFrames()"> +<input type="button" value="Dump Content" onclick="DumpContent()"> +<input type="button" value="Dump Views" onclick="DumpViews()"> +<input type="button" value="Dump WebShells" onclick="DumpWebShells()"> +</div> + +</form> + + + +</body> +</html> + diff --git a/layout/tools/tests/regression_tests.html b/layout/tools/tests/regression_tests.html new file mode 100644 index 000000000..8eff8fc77 --- /dev/null +++ b/layout/tools/tests/regression_tests.html @@ -0,0 +1,132 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> +<html> +<head> + <title>Layout Regression Test Harness</title> +</head> + +<style> +p.note +{ + background-color: #FFFFDD; + border: 2px solid red; + padding: 10px; +} + +div.indent +{ + margin-left: 20px; + padding: 5px; +} + +#tests +{ + border: 1px solid black; + margin: 10px; +} + +#results +{ + border: 1px solid black; + margin: 10px; + overflow: auto; + height: 200px; +} +</style> + +<script src="regression_tests.js" type="application/javascript"> +<!-- + +//--> +</script> + +<body onload="DoOnload();"> + +<h1>Layout Regression Test Harness</h1> + +<p class="note"> +The JavaScript in this file requires that you grant it XPConnect access, +via the dialog that appears when you first load the file. Note that the code +herein creates directories and files, so there is the possibility that it +may do damage to the contents of your hard disk. You have been warned! +</p> + +<h2>Tests</h2> +<div id="tests"> +<form name="testForm"> + <div class="indent"> + <input type="radio" name="testType" id="singleFileRadio" checked="true" onclick="UpdateRunTestsButton()"></input><label for="singleFileRadio">Single testcase</label> + <div class="indent"> + URL: <input id="singleTestFileInput" name="singleTestFileInput" type="text" size="80" oninput="UpdateRunTestsButton()"></input> + <input type="button" onclick="ChooseTestcaseFile();" value="Choose File..."> + </div> + </div> + + <div class="indent"> + <input type="radio" name="testType" id="dirsRadio" onclick="UpdateRunTestsButton()"></input><label for="dirsRadio">Local Directories</label> + <div class="indent"> + <select id="testDirsSelect" size="5" style="width: 200pt"> + <option>None selected</option> + </select><br> + <input type="button" value="Add..." onclick="AppendTestcaseDir();"> + <input type="button" value="Remove" onclick="RemoveTestcaseDir();"> + </div> + </div> + + <div class="indent"> + <hr> + <table cellpadding="5px"> + <thead> + <tr> + <td><strong>Do what</strong></td> + <td><strong>Output file locations</strong></td> + </tr> + </thead> + <tr> + <td> + <div><input id="baselineRadio" type="radio" name="doWhat" onclick="UpdateRunTestsButton()" checked="true"></input><label for="baselineRadio">Baseline</label></div> + <div><input id="verifyRadio" type="radio" name="doWhat" onclick="UpdateRunTestsButton()"></input><label for="verifyRadio">Verify</label></div> + <div><input id="verifCompRadio" type="radio" name="doWhat" onclick="UpdateRunTestsButton()"></input><label for="verifCompRadio">Verify and Compare</label></div> + <div><input id="compRadio" type="radio" name="doWhat" onclick="UpdateRunTestsButton()"></input><label for="compRadio">Compare</label></div> + </td> + <td valign="top"> + <table cellpadding="4px"> + <tr> + <td></td> + <td></td> + <td>File extensions</td> + </tr> + <tr> + <td align="right">Baseline:</td> + <td><input id="baselineOutputDir" name="baselineOutputDir" type="text" size="40" disabled="true"></input> + <input type="button" onclick="gBaselineOutputDir = ChooseOutputDirectory('baselineOutputDir'); UpdateRunTestsButton();" value="Choose..."></td> + <td><input type="text" size="6" name="baselineFileExtension" value=".bas"></input> (like ".bas")</td> + </tr> + <tr> + <td align="right">Verify:</td> + <td><input id="verifyOutputDir" name="verifyOutputDir" type="text" size="40" disabled="true"></input> + <input type="button" onclick="gVerifyOutputDir = ChooseOutputDirectory('verifyOutputDir'); UpdateRunTestsButton();" value="Choose..."></td> + <td><input type="text" size="6" name="verifyFileExtension" value=".ver"></input>(like ".ver")</td> + </tr> + </table> + </td> + </tr> + </table> + </div> + <div class="indent"> + <hr> + <input type="Button" name="runTests" value="Run the Tests!" onclick="RunTests();"> + </div> + + </div> + +</form> +</div> + +<h2>Results</h2> +<div id="results"> +</div> + +</body> +</html> + diff --git a/layout/tools/tests/regression_tests.js b/layout/tools/tests/regression_tests.js new file mode 100644 index 000000000..19003b08f --- /dev/null +++ b/layout/tools/tests/regression_tests.js @@ -0,0 +1,553 @@ + + +const nsIFilePicker = Components.interfaces.nsIFilePicker; +const nsILayoutRegressionTester = Components.interfaces.nsILayoutRegressionTester; + +const kTestTypeBaseline = 1; +const kTestTypeVerify = 2; +const kTestTypeVerifyAndCompare = 3; +const kTestTypeCompare = 4; + +const kTestSourceSingleFile = 1; +const kTestSourceDirList = 2; + +var gTestcaseDirArray = new Array; // array of nsILocalFiles + +var gBaselineOutputDir; // nsIFile +var gVerifyOutputDir; // nsIFile + +var gBaselineFileExtension; // string +var gVerifyFileExtension; // string + +var gTestType; // baseline, verify, compare etc. + +var gTestWindow; +var gTestURLs = new Array; +var gTestURLsIndex; + +function DoOnload() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + // clear any values that the form manager may have unhelpfully filled in + document.testForm.singleTestFileInput.value = ""; + document.testForm.baselineOutputDir.value = ""; + document.testForm.verifyOutputDir.value = ""; + + InitFormFromPrefs(); + + UpdateRunTestsButton(); +} + +function InitFormFromPrefs() +{ + // load prefs + try { + var testURL = GetStringPref("nglayout.debug.testcaseURL"); + document.testForm.singleTestFileInput.value = testURL; + + var baselineDirURL = GetStringPref("nglayout.debug.baselineDirURL"); + gBaselineOutputDir = GetFileFromURISpec(baselineDirURL); + document.testForm.baselineOutputDir.value = gBaselineOutputDir.path; + + var verifyDirURL = GetStringPref("nglayout.debug.verifyDirURL"); + gVerifyOutputDir = GetFileFromURISpec(verifyDirURL); + document.testForm.verifyOutputDir.value = gVerifyOutputDir.path; + + var dirIndex = 0; + while (true) // we'll throw when we reach a nonexistent pref + { + var curDir = GetStringPref("nglayout.debug.testcaseDir" + dirIndex); + var dirFileSpec = GetFileFromURISpec(curDir); + gTestcaseDirArray.push(dirFileSpec); + dirIndex ++; + } + } + catch(e) + { + } + + RebuildTestDirsSelect(); +} + +function SaveFormToPrefs() +{ + SaveStringPref("nglayout.debug.testcaseURL", document.testForm.singleTestFileInput.value); + + // save prefs + if (gBaselineOutputDir) + { + var baselineDirURL = GetURISpecFromFile(gBaselineOutputDir); + SaveStringPref("nglayout.debug.baselineDirURL", baselineDirURL); + } + + if (gVerifyOutputDir) + { + var verifyDirURL = GetURISpecFromFile(gVerifyOutputDir); + SaveStringPref("nglayout.debug.verifyDirURL", verifyDirURL); + } + + var dirIndex; + for (dirIndex = 0; dirIndex < gTestcaseDirArray.length; dirIndex ++) + { + var curURL = GetURISpecFromFile(gTestcaseDirArray[dirIndex]); + SaveStringPref("nglayout.debug.testcaseDir" + dirIndex, curURL); + } + try + { + // clear prefs for higher indices until we throw + while (1) + { + ClearPref("nglayout.debug.testcaseDir" + dirIndex); + } + } + catch(e) + { + } + +} + +function GetURISpecFromFile(inFile) +{ + var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); + var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler); + return fileHandler.getURLSpecFromFile(inFile); +} + +function GetFileFromURISpec(uriSpec) +{ + var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); + var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler); + return fileHandler.getFileFromURLSpec(uriSpec); +} + +function SaveStringPref(inPrefName, inPrefValue) +{ + var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + prefs.setCharPref(inPrefName, inPrefValue); +} + +function GetStringPref(inPrefName) +{ + var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + return prefs.getCharPref(inPrefName); +} + +function ClearPref(inPrefName) +{ + var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + prefs.clearUserPref(inPrefName); +} + +function WriteOutput(aText, aReplace, aColorString) +{ + var outputDiv = document.getElementById("results"); + + if (aReplace) + ClearOutput(); + + var childDiv = document.createElement("div"); + var textNode = document.createTextNode(aText); + childDiv.appendChild(textNode); + childDiv.setAttribute("style", "color: " + aColorString + ";"); + outputDiv.appendChild(childDiv); +} + +function ClearOutput() +{ + var outputDiv = document.getElementById("results"); + var curChild; + while (curChild = outputDiv.firstChild) + outputDiv.removeChild(curChild); +} + +// returns an nsIFile +function PickDirectory() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); + fp.init(window, "Pick a directory", nsIFilePicker.modeGetFolder); + var result = fp.show(); + if (result == nsIFilePicker.returnCancel) + throw("User cancelled"); + + var chosenDir = fp.file; + return chosenDir; +} + + +// returns a url string +function PickFileURL() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); + fp.init(window, "Pick a directory", nsIFilePicker.modeOpen); + fp.appendFilters(nsIFilePicker.filterHTML + nsIFilePicker.filterText); + + var result = fp.show(); + if (result == nsIFilePicker.returnCancel) + throw("User cancelled"); + + return fp.fileURL.spec; +} + +function RebuildTestDirsSelect() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var dirsSelect = document.getElementById("testDirsSelect"); + + // rebuild it from gTestcaseDirArray + while (dirsSelect.length) + dirsSelect.remove(0); + + var i; + for (i = 0; i < gTestcaseDirArray.length; i ++) + { + var curDir = gTestcaseDirArray[i]; + + var optionElement = document.createElement("option"); + var textNode = document.createTextNode(curDir.leafName); + + optionElement.appendChild(textNode); + dirsSelect.add(optionElement, null); + } + + UpdateRunTestsButton(); +} + +// set the 'single testcase' file +function ChooseTestcaseFile() +{ + var dirInput = document.getElementById("singleTestFileInput"); + dirInput.value = PickFileURL(); + + UpdateRunTestsButton(); +} + +function AppendTestcaseDir() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + var chosenDir = PickDirectory(); + // does the array already contain this dir? + var i; + for (i = 0; i < gTestcaseDirArray.length; i ++) + { + var curElement = gTestcaseDirArray[i]; + if (curElement.equals(chosenDir)) // nsIFile::Equals + return; + } + + gTestcaseDirArray[gTestcaseDirArray.length] = chosenDir; + RebuildTestDirsSelect(); +} + +function RemoveTestcaseDir() +{ + var dirsSelect = document.getElementById("testDirsSelect"); + if (dirsSelect.selectedIndex != -1) + { + gTestcaseDirArray.splice(dirsSelect.selectedIndex, 1); + RebuildTestDirsSelect(); + } +} + +function InputOptionsValid() +{ + if (document.testForm.testType[0].checked) + { + // need a test file + var testcaseURL = document.testForm.singleTestFileInput.value; + if (testcaseURL.length == 0) return false; + } + else if (document.testForm.testType[1].checked) + { + // need at least one dir + if (gTestcaseDirArray.length == 0) return false; + } + else + return false; + + return true; +} + +function OutputOptionsValid() +{ + var testType = GetTestType(); + + switch (testType) + { + case kTestTypeBaseline: + if (!gBaselineOutputDir) return false; + break; + + case kTestTypeVerify: + if (!gVerifyOutputDir) return false; + break; + + case kTestTypeVerifyAndCompare: + case kTestTypeCompare: + if (!gBaselineOutputDir || !gVerifyOutputDir) return false; + break; + } + + return true; +} + +function UpdateRunTestsButton() +{ + var testType = GetTestType(); + var dataValid = OutputOptionsValid(); + if (testType != kTestTypeCompare) + dataValid &= InputOptionsValid(); + document.testForm.runTests.disabled = !dataValid; +} + +// returns nsIFile, sets the input value +function ChooseOutputDirectory(inputElementID) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var chosenDir = PickDirectory(); + + var inputElement = document.getElementById(inputElementID); + inputElement.value = chosenDir.path; + + return chosenDir; +} + + +function CompareFrameDumps(testFileBasename, baselineDir, baselineExt, verifyDir, verifyExt) +{ + var debugObject = Components.classes["@mozilla.org/layout-debug/regressiontester;1"].createInstance(nsILayoutRegressionTester); + + var baseFile = baselineDir.clone(); + baseFile.append(testFileBasename + baselineExt); + + var verifyFile = verifyDir.clone(); + verifyFile.append(testFileBasename + verifyExt); + + var filesDiffer = debugObject.compareFrameModels(baseFile, verifyFile, nsILayoutRegressionTester.COMPARE_FLAGS_BRIEF); + if (filesDiffer) + { + WriteOutput("Test file '" + baseFile.leafName + "' failed", false, "red"); + } + else + { + WriteOutput("Test file '" + baseFile.leafName + "' passed", false, "green"); + } +} + +function DumpFrames(testWindow, testFileName, outputDir, outputFileExtension) +{ + var debugObject = Components.classes["@mozilla.org/layout-debug/regressiontester;1"].createInstance(nsILayoutRegressionTester); + + var outputFile = outputDir.clone(); + outputFile.append(testFileName.replace(".html", outputFileExtension)); + + dump("Dumping frame model for " + testFileName + " to " + outputFile.leafName + "\n"); + var result = debugObject.dumpFrameModel(testWindow, outputFile, nsILayoutRegressionTester.DUMP_FLAGS_MASK_DEFAULT); + if (result != 0) + { + WriteOutput("dumpFrameModel for " + testFileName + " failed", false, "orange"); + } +} + +function LoadTestURL(testWindow, theURL) +{ + dump("Loading test " + theURL + "\n"); + // we use a 1/2 second delay to give time for async reflows to happen + testWindow.onload = setTimeout("HandleTestWindowLoad(gTestWindow)", 1000); + testWindow.location.href = theURL; +} + +function HandleTestWindowLoad(testWindow) +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + var outputDir; + var outputFileExtension; + var runCompare = false; + + switch (gTestType) + { + case kTestTypeBaseline: + outputDir = gBaselineOutputDir; + outputFileExtension = gBaselineFileExtension; + break; + + case kTestTypeVerify: + outputDir = gVerifyOutputDir; + outputFileExtension = gVerifyFileExtension; + break; + + case kTestTypeVerifyAndCompare: + outputDir = gVerifyOutputDir; + outputFileExtension = gVerifyFileExtension; + runCompare = true; + break; + + case kTestTypeCompare: + dump("Should never get here"); + break; + } + + var loadedURL = testWindow.location.href; + var loadedFile = loadedURL.substring(loadedURL.lastIndexOf('/') + 1); + + DumpFrames(testWindow, loadedFile, outputDir, outputFileExtension); + + if (runCompare) + { + var testFileBasename = loadedFile.replace(".html", ""); + CompareFrameDumps(testFileBasename, gBaselineOutputDir, gBaselineFileExtension, gVerifyOutputDir, gVerifyFileExtension); + } + + // now fire of the next one, if we have one + var nextURL = gTestURLs[gTestURLsIndex++]; + if (nextURL) + LoadTestURL(testWindow, nextURL); + else + testWindow.close(); +} + + +function AddDirectoryEntriesToTestList(inDirFile, inRequiredExtension) +{ + var enumerator = inDirFile.directoryEntries; + + while (enumerator.hasMoreElements()) + { + var curFile = enumerator.getNext(); + curFile = curFile.QueryInterface(Components.interfaces.nsIFile); + + var leafName = curFile.leafName; + if (leafName.indexOf(inRequiredExtension) != -1) + { + var fileURI = GetURISpecFromFile(curFile); + gTestURLs.push(fileURI); + } + } +} + + +// returns an array of filenames +function DirectoryEntriesToArray(inDirFile, inRequiredExtension) +{ + var fileArray = new Array; + + var enumerator = inDirFile.directoryEntries; + while (enumerator.hasMoreElements()) + { + var curFile = enumerator.getNext(); + curFile = curFile.QueryInterface(Components.interfaces.nsIFile); + var leafName = curFile.leafName; + if (leafName.indexOf(inRequiredExtension) != -1) + { + fileArray.push(leafName); + } + } + + return fileArray; +} + + +function BuildTestURLsList(testSourceType) +{ + // clear the array + gTestURLs.splice(0, gTestURLs.length); + gTestURLsIndex = 0; + + if (testSourceType == kTestSourceSingleFile) + { + var testURL = document.testForm.singleTestFileInput.value; + if (testURL.substr(-5) != ".html") + { + // append /index.html if we have to + if (testURL.substr(-1) != "/") + testURL += "/"; + testURL += "index.html"; + } + gTestURLs[0] = testURL; + } + else + { + for (var i = 0; i < gTestcaseDirArray.length; i++) + { + var dirFile = gTestcaseDirArray[i]; // nsIFile for the dir + AddDirectoryEntriesToTestList(dirFile, ".html"); + } + } +} + +function CompareFilesInDir(inBaseDir, inBaseExtension, inVerifyDir, inVerifyExtension) +{ + var comapareFiles = DirectoryEntriesToArray(inBaseDir, inBaseExtension); + + for (var i = 0; i < comapareFiles.length; i ++) + { + var curFilename = comapareFiles[i]; + var testFileBasename = curFilename.replace(inBaseExtension, ""); + CompareFrameDumps(testFileBasename, inBaseDir, inBaseExtension, inVerifyDir, inVerifyExtension); + } +} + +function GetTestType() +{ + if (document.testForm.doWhat[0].checked) + return kTestTypeBaseline; + + if (document.testForm.doWhat[1].checked) + return kTestTypeVerify; + + if (document.testForm.doWhat[2].checked) + return kTestTypeVerifyAndCompare; + + if (document.testForm.doWhat[3].checked) + return kTestTypeCompare; + + return 0; +} + +function RunTests() +{ + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + ClearOutput(); + SaveFormToPrefs(); + + var testSourceType; + if (document.testForm.testType[0].checked) + testSourceType = kTestSourceSingleFile; + else + testSourceType = kTestSourceDirList; + + gTestType = GetTestType(); + + gBaselineFileExtension = document.testForm.baselineFileExtension.value; + gVerifyFileExtension = document.testForm.verifyFileExtension.value; + + if (gTestType == kTestTypeCompare) + { + // to compare, we'll just run through all the files in the + // baseline and verify dirs, and compare those that exist in + // both. + CompareFilesInDir(gBaselineOutputDir, gBaselineFileExtension, gVerifyOutputDir, gVerifyFileExtension); + } + else + { + BuildTestURLsList(testSourceType); + + gTestWindow = window.open("about:blank", "Test window", + "width=800,height=600,status=yes,toolbars=no"); + + // start the first load + var testURL = gTestURLs[0]; + gTestURLsIndex = 1; + LoadTestURL(gTestWindow, testURL); + } + +} + + |