Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | |
michael@0 | 2 | |
michael@0 | 3 | const nsIFilePicker = Components.interfaces.nsIFilePicker; |
michael@0 | 4 | const nsILayoutRegressionTester = Components.interfaces.nsILayoutRegressionTester; |
michael@0 | 5 | |
michael@0 | 6 | const kTestTypeBaseline = 1; |
michael@0 | 7 | const kTestTypeVerify = 2; |
michael@0 | 8 | const kTestTypeVerifyAndCompare = 3; |
michael@0 | 9 | const kTestTypeCompare = 4; |
michael@0 | 10 | |
michael@0 | 11 | const kTestSourceSingleFile = 1; |
michael@0 | 12 | const kTestSourceDirList = 2; |
michael@0 | 13 | |
michael@0 | 14 | var gTestcaseDirArray = new Array; // array of nsILocalFiles |
michael@0 | 15 | |
michael@0 | 16 | var gBaselineOutputDir; // nsIFile |
michael@0 | 17 | var gVerifyOutputDir; // nsIFile |
michael@0 | 18 | |
michael@0 | 19 | var gBaselineFileExtension; // string |
michael@0 | 20 | var gVerifyFileExtension; // string |
michael@0 | 21 | |
michael@0 | 22 | var gTestType; // baseline, verify, compare etc. |
michael@0 | 23 | |
michael@0 | 24 | var gTestWindow; |
michael@0 | 25 | var gTestURLs = new Array; |
michael@0 | 26 | var gTestURLsIndex; |
michael@0 | 27 | |
michael@0 | 28 | function DoOnload() |
michael@0 | 29 | { |
michael@0 | 30 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 31 | |
michael@0 | 32 | // clear any values that the form manager may have unhelpfully filled in |
michael@0 | 33 | document.testForm.singleTestFileInput.value = ""; |
michael@0 | 34 | document.testForm.baselineOutputDir.value = ""; |
michael@0 | 35 | document.testForm.verifyOutputDir.value = ""; |
michael@0 | 36 | |
michael@0 | 37 | InitFormFromPrefs(); |
michael@0 | 38 | |
michael@0 | 39 | UpdateRunTestsButton(); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function InitFormFromPrefs() |
michael@0 | 43 | { |
michael@0 | 44 | // load prefs |
michael@0 | 45 | try { |
michael@0 | 46 | var testURL = GetStringPref("nglayout.debug.testcaseURL"); |
michael@0 | 47 | document.testForm.singleTestFileInput.value = testURL; |
michael@0 | 48 | |
michael@0 | 49 | var baselineDirURL = GetStringPref("nglayout.debug.baselineDirURL"); |
michael@0 | 50 | gBaselineOutputDir = GetFileFromURISpec(baselineDirURL); |
michael@0 | 51 | document.testForm.baselineOutputDir.value = gBaselineOutputDir.path; |
michael@0 | 52 | |
michael@0 | 53 | var verifyDirURL = GetStringPref("nglayout.debug.verifyDirURL"); |
michael@0 | 54 | gVerifyOutputDir = GetFileFromURISpec(verifyDirURL); |
michael@0 | 55 | document.testForm.verifyOutputDir.value = gVerifyOutputDir.path; |
michael@0 | 56 | |
michael@0 | 57 | var dirIndex = 0; |
michael@0 | 58 | while (true) // we'll throw when we reach a nonexistent pref |
michael@0 | 59 | { |
michael@0 | 60 | var curDir = GetStringPref("nglayout.debug.testcaseDir" + dirIndex); |
michael@0 | 61 | var dirFileSpec = GetFileFromURISpec(curDir); |
michael@0 | 62 | gTestcaseDirArray.push(dirFileSpec); |
michael@0 | 63 | dirIndex ++; |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | catch(e) |
michael@0 | 67 | { |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | RebuildTestDirsSelect(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function SaveFormToPrefs() |
michael@0 | 74 | { |
michael@0 | 75 | SaveStringPref("nglayout.debug.testcaseURL", document.testForm.singleTestFileInput.value); |
michael@0 | 76 | |
michael@0 | 77 | // save prefs |
michael@0 | 78 | if (gBaselineOutputDir) |
michael@0 | 79 | { |
michael@0 | 80 | var baselineDirURL = GetURISpecFromFile(gBaselineOutputDir); |
michael@0 | 81 | SaveStringPref("nglayout.debug.baselineDirURL", baselineDirURL); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | if (gVerifyOutputDir) |
michael@0 | 85 | { |
michael@0 | 86 | var verifyDirURL = GetURISpecFromFile(gVerifyOutputDir); |
michael@0 | 87 | SaveStringPref("nglayout.debug.verifyDirURL", verifyDirURL); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | var dirIndex; |
michael@0 | 91 | for (dirIndex = 0; dirIndex < gTestcaseDirArray.length; dirIndex ++) |
michael@0 | 92 | { |
michael@0 | 93 | var curURL = GetURISpecFromFile(gTestcaseDirArray[dirIndex]); |
michael@0 | 94 | SaveStringPref("nglayout.debug.testcaseDir" + dirIndex, curURL); |
michael@0 | 95 | } |
michael@0 | 96 | try |
michael@0 | 97 | { |
michael@0 | 98 | // clear prefs for higher indices until we throw |
michael@0 | 99 | while (1) |
michael@0 | 100 | { |
michael@0 | 101 | ClearPref("nglayout.debug.testcaseDir" + dirIndex); |
michael@0 | 102 | } |
michael@0 | 103 | } |
michael@0 | 104 | catch(e) |
michael@0 | 105 | { |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function GetURISpecFromFile(inFile) |
michael@0 | 111 | { |
michael@0 | 112 | var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); |
michael@0 | 113 | var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler); |
michael@0 | 114 | return fileHandler.getURLSpecFromFile(inFile); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function GetFileFromURISpec(uriSpec) |
michael@0 | 118 | { |
michael@0 | 119 | var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); |
michael@0 | 120 | var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler); |
michael@0 | 121 | return fileHandler.getFileFromURLSpec(uriSpec); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function SaveStringPref(inPrefName, inPrefValue) |
michael@0 | 125 | { |
michael@0 | 126 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 127 | prefs.setCharPref(inPrefName, inPrefValue); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function GetStringPref(inPrefName) |
michael@0 | 131 | { |
michael@0 | 132 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 133 | return prefs.getCharPref(inPrefName); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function ClearPref(inPrefName) |
michael@0 | 137 | { |
michael@0 | 138 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 139 | prefs.clearUserPref(inPrefName); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | function WriteOutput(aText, aReplace, aColorString) |
michael@0 | 143 | { |
michael@0 | 144 | var outputDiv = document.getElementById("results"); |
michael@0 | 145 | |
michael@0 | 146 | if (aReplace) |
michael@0 | 147 | ClearOutput(); |
michael@0 | 148 | |
michael@0 | 149 | var childDiv = document.createElement("div"); |
michael@0 | 150 | var textNode = document.createTextNode(aText); |
michael@0 | 151 | childDiv.appendChild(textNode); |
michael@0 | 152 | childDiv.setAttribute("style", "color: " + aColorString + ";"); |
michael@0 | 153 | outputDiv.appendChild(childDiv); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | function ClearOutput() |
michael@0 | 157 | { |
michael@0 | 158 | var outputDiv = document.getElementById("results"); |
michael@0 | 159 | var curChild; |
michael@0 | 160 | while (curChild = outputDiv.firstChild) |
michael@0 | 161 | outputDiv.removeChild(curChild); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | // returns an nsIFile |
michael@0 | 165 | function PickDirectory() |
michael@0 | 166 | { |
michael@0 | 167 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 168 | |
michael@0 | 169 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); |
michael@0 | 170 | fp.init(window, "Pick a directory", nsIFilePicker.modeGetFolder); |
michael@0 | 171 | var result = fp.show(); |
michael@0 | 172 | if (result == nsIFilePicker.returnCancel) |
michael@0 | 173 | throw("User cancelled"); |
michael@0 | 174 | |
michael@0 | 175 | var chosenDir = fp.file; |
michael@0 | 176 | return chosenDir; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | |
michael@0 | 180 | // returns a url string |
michael@0 | 181 | function PickFileURL() |
michael@0 | 182 | { |
michael@0 | 183 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 184 | |
michael@0 | 185 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); |
michael@0 | 186 | fp.init(window, "Pick a directory", nsIFilePicker.modeOpen); |
michael@0 | 187 | fp.appendFilters(nsIFilePicker.filterHTML + nsIFilePicker.filterText); |
michael@0 | 188 | |
michael@0 | 189 | var result = fp.show(); |
michael@0 | 190 | if (result == nsIFilePicker.returnCancel) |
michael@0 | 191 | throw("User cancelled"); |
michael@0 | 192 | |
michael@0 | 193 | return fp.fileURL.spec; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | function RebuildTestDirsSelect() |
michael@0 | 197 | { |
michael@0 | 198 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 199 | var dirsSelect = document.getElementById("testDirsSelect"); |
michael@0 | 200 | |
michael@0 | 201 | // rebuild it from gTestcaseDirArray |
michael@0 | 202 | while (dirsSelect.length) |
michael@0 | 203 | dirsSelect.remove(0); |
michael@0 | 204 | |
michael@0 | 205 | var i; |
michael@0 | 206 | for (i = 0; i < gTestcaseDirArray.length; i ++) |
michael@0 | 207 | { |
michael@0 | 208 | var curDir = gTestcaseDirArray[i]; |
michael@0 | 209 | |
michael@0 | 210 | var optionElement = document.createElement("option"); |
michael@0 | 211 | var textNode = document.createTextNode(curDir.leafName); |
michael@0 | 212 | |
michael@0 | 213 | optionElement.appendChild(textNode); |
michael@0 | 214 | dirsSelect.add(optionElement, null); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | UpdateRunTestsButton(); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | // set the 'single testcase' file |
michael@0 | 221 | function ChooseTestcaseFile() |
michael@0 | 222 | { |
michael@0 | 223 | var dirInput = document.getElementById("singleTestFileInput"); |
michael@0 | 224 | dirInput.value = PickFileURL(); |
michael@0 | 225 | |
michael@0 | 226 | UpdateRunTestsButton(); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | function AppendTestcaseDir() |
michael@0 | 230 | { |
michael@0 | 231 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 232 | |
michael@0 | 233 | var chosenDir = PickDirectory(); |
michael@0 | 234 | // does the array already contain this dir? |
michael@0 | 235 | var i; |
michael@0 | 236 | for (i = 0; i < gTestcaseDirArray.length; i ++) |
michael@0 | 237 | { |
michael@0 | 238 | var curElement = gTestcaseDirArray[i]; |
michael@0 | 239 | if (curElement.equals(chosenDir)) // nsIFile::Equals |
michael@0 | 240 | return; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | gTestcaseDirArray[gTestcaseDirArray.length] = chosenDir; |
michael@0 | 244 | RebuildTestDirsSelect(); |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | function RemoveTestcaseDir() |
michael@0 | 248 | { |
michael@0 | 249 | var dirsSelect = document.getElementById("testDirsSelect"); |
michael@0 | 250 | if (dirsSelect.selectedIndex != -1) |
michael@0 | 251 | { |
michael@0 | 252 | gTestcaseDirArray.splice(dirsSelect.selectedIndex, 1); |
michael@0 | 253 | RebuildTestDirsSelect(); |
michael@0 | 254 | } |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | function InputOptionsValid() |
michael@0 | 258 | { |
michael@0 | 259 | if (document.testForm.testType[0].checked) |
michael@0 | 260 | { |
michael@0 | 261 | // need a test file |
michael@0 | 262 | var testcaseURL = document.testForm.singleTestFileInput.value; |
michael@0 | 263 | if (testcaseURL.length == 0) return false; |
michael@0 | 264 | } |
michael@0 | 265 | else if (document.testForm.testType[1].checked) |
michael@0 | 266 | { |
michael@0 | 267 | // need at least one dir |
michael@0 | 268 | if (gTestcaseDirArray.length == 0) return false; |
michael@0 | 269 | } |
michael@0 | 270 | else |
michael@0 | 271 | return false; |
michael@0 | 272 | |
michael@0 | 273 | return true; |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | function OutputOptionsValid() |
michael@0 | 277 | { |
michael@0 | 278 | var testType = GetTestType(); |
michael@0 | 279 | |
michael@0 | 280 | switch (testType) |
michael@0 | 281 | { |
michael@0 | 282 | case kTestTypeBaseline: |
michael@0 | 283 | if (!gBaselineOutputDir) return false; |
michael@0 | 284 | break; |
michael@0 | 285 | |
michael@0 | 286 | case kTestTypeVerify: |
michael@0 | 287 | if (!gVerifyOutputDir) return false; |
michael@0 | 288 | break; |
michael@0 | 289 | |
michael@0 | 290 | case kTestTypeVerifyAndCompare: |
michael@0 | 291 | case kTestTypeCompare: |
michael@0 | 292 | if (!gBaselineOutputDir || !gVerifyOutputDir) return false; |
michael@0 | 293 | break; |
michael@0 | 294 | } |
michael@0 | 295 | |
michael@0 | 296 | return true; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | function UpdateRunTestsButton() |
michael@0 | 300 | { |
michael@0 | 301 | var testType = GetTestType(); |
michael@0 | 302 | var dataValid = OutputOptionsValid(); |
michael@0 | 303 | if (testType != kTestTypeCompare) |
michael@0 | 304 | dataValid &= InputOptionsValid(); |
michael@0 | 305 | document.testForm.runTests.disabled = !dataValid; |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | // returns nsIFile, sets the input value |
michael@0 | 309 | function ChooseOutputDirectory(inputElementID) |
michael@0 | 310 | { |
michael@0 | 311 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 312 | var chosenDir = PickDirectory(); |
michael@0 | 313 | |
michael@0 | 314 | var inputElement = document.getElementById(inputElementID); |
michael@0 | 315 | inputElement.value = chosenDir.path; |
michael@0 | 316 | |
michael@0 | 317 | return chosenDir; |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | |
michael@0 | 321 | function CompareFrameDumps(testFileBasename, baselineDir, baselineExt, verifyDir, verifyExt) |
michael@0 | 322 | { |
michael@0 | 323 | var debugObject = Components.classes["@mozilla.org/layout-debug/regressiontester;1"].createInstance(nsILayoutRegressionTester); |
michael@0 | 324 | |
michael@0 | 325 | var baseFile = baselineDir.clone(); |
michael@0 | 326 | baseFile.append(testFileBasename + baselineExt); |
michael@0 | 327 | |
michael@0 | 328 | var verifyFile = verifyDir.clone(); |
michael@0 | 329 | verifyFile.append(testFileBasename + verifyExt); |
michael@0 | 330 | |
michael@0 | 331 | var filesDiffer = debugObject.compareFrameModels(baseFile, verifyFile, nsILayoutRegressionTester.COMPARE_FLAGS_BRIEF); |
michael@0 | 332 | if (filesDiffer) |
michael@0 | 333 | { |
michael@0 | 334 | WriteOutput("Test file '" + baseFile.leafName + "' failed", false, "red"); |
michael@0 | 335 | } |
michael@0 | 336 | else |
michael@0 | 337 | { |
michael@0 | 338 | WriteOutput("Test file '" + baseFile.leafName + "' passed", false, "green"); |
michael@0 | 339 | } |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | function DumpFrames(testWindow, testFileName, outputDir, outputFileExtension) |
michael@0 | 343 | { |
michael@0 | 344 | var debugObject = Components.classes["@mozilla.org/layout-debug/regressiontester;1"].createInstance(nsILayoutRegressionTester); |
michael@0 | 345 | |
michael@0 | 346 | var outputFile = outputDir.clone(); |
michael@0 | 347 | outputFile.append(testFileName.replace(".html", outputFileExtension)); |
michael@0 | 348 | |
michael@0 | 349 | dump("Dumping frame model for " + testFileName + " to " + outputFile.leafName + "\n"); |
michael@0 | 350 | var result = debugObject.dumpFrameModel(testWindow, outputFile, nsILayoutRegressionTester.DUMP_FLAGS_MASK_DEFAULT); |
michael@0 | 351 | if (result != 0) |
michael@0 | 352 | { |
michael@0 | 353 | WriteOutput("dumpFrameModel for " + testFileName + " failed", false, "orange"); |
michael@0 | 354 | } |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | function LoadTestURL(testWindow, theURL) |
michael@0 | 358 | { |
michael@0 | 359 | dump("Loading test " + theURL + "\n"); |
michael@0 | 360 | // we use a 1/2 second delay to give time for async reflows to happen |
michael@0 | 361 | testWindow.onload = setTimeout("HandleTestWindowLoad(gTestWindow)", 1000); |
michael@0 | 362 | testWindow.location.href = theURL; |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | function HandleTestWindowLoad(testWindow) |
michael@0 | 366 | { |
michael@0 | 367 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 368 | |
michael@0 | 369 | var outputDir; |
michael@0 | 370 | var outputFileExtension; |
michael@0 | 371 | var runCompare = false; |
michael@0 | 372 | |
michael@0 | 373 | switch (gTestType) |
michael@0 | 374 | { |
michael@0 | 375 | case kTestTypeBaseline: |
michael@0 | 376 | outputDir = gBaselineOutputDir; |
michael@0 | 377 | outputFileExtension = gBaselineFileExtension; |
michael@0 | 378 | break; |
michael@0 | 379 | |
michael@0 | 380 | case kTestTypeVerify: |
michael@0 | 381 | outputDir = gVerifyOutputDir; |
michael@0 | 382 | outputFileExtension = gVerifyFileExtension; |
michael@0 | 383 | break; |
michael@0 | 384 | |
michael@0 | 385 | case kTestTypeVerifyAndCompare: |
michael@0 | 386 | outputDir = gVerifyOutputDir; |
michael@0 | 387 | outputFileExtension = gVerifyFileExtension; |
michael@0 | 388 | runCompare = true; |
michael@0 | 389 | break; |
michael@0 | 390 | |
michael@0 | 391 | case kTestTypeCompare: |
michael@0 | 392 | dump("Should never get here"); |
michael@0 | 393 | break; |
michael@0 | 394 | } |
michael@0 | 395 | |
michael@0 | 396 | var loadedURL = testWindow.location.href; |
michael@0 | 397 | var loadedFile = loadedURL.substring(loadedURL.lastIndexOf('/') + 1); |
michael@0 | 398 | |
michael@0 | 399 | DumpFrames(testWindow, loadedFile, outputDir, outputFileExtension); |
michael@0 | 400 | |
michael@0 | 401 | if (runCompare) |
michael@0 | 402 | { |
michael@0 | 403 | var testFileBasename = loadedFile.replace(".html", ""); |
michael@0 | 404 | CompareFrameDumps(testFileBasename, gBaselineOutputDir, gBaselineFileExtension, gVerifyOutputDir, gVerifyFileExtension); |
michael@0 | 405 | } |
michael@0 | 406 | |
michael@0 | 407 | // now fire of the next one, if we have one |
michael@0 | 408 | var nextURL = gTestURLs[gTestURLsIndex++]; |
michael@0 | 409 | if (nextURL) |
michael@0 | 410 | LoadTestURL(testWindow, nextURL); |
michael@0 | 411 | else |
michael@0 | 412 | testWindow.close(); |
michael@0 | 413 | } |
michael@0 | 414 | |
michael@0 | 415 | |
michael@0 | 416 | function AddDirectoryEntriesToTestList(inDirFile, inRequiredExtension) |
michael@0 | 417 | { |
michael@0 | 418 | var enumerator = inDirFile.directoryEntries; |
michael@0 | 419 | |
michael@0 | 420 | while (enumerator.hasMoreElements()) |
michael@0 | 421 | { |
michael@0 | 422 | var curFile = enumerator.getNext(); |
michael@0 | 423 | curFile = curFile.QueryInterface(Components.interfaces.nsIFile); |
michael@0 | 424 | |
michael@0 | 425 | var leafName = curFile.leafName; |
michael@0 | 426 | if (leafName.indexOf(inRequiredExtension) != -1) |
michael@0 | 427 | { |
michael@0 | 428 | var fileURI = GetURISpecFromFile(curFile); |
michael@0 | 429 | gTestURLs.push(fileURI); |
michael@0 | 430 | } |
michael@0 | 431 | } |
michael@0 | 432 | } |
michael@0 | 433 | |
michael@0 | 434 | |
michael@0 | 435 | // returns an array of filenames |
michael@0 | 436 | function DirectoryEntriesToArray(inDirFile, inRequiredExtension) |
michael@0 | 437 | { |
michael@0 | 438 | var fileArray = new Array; |
michael@0 | 439 | |
michael@0 | 440 | var enumerator = inDirFile.directoryEntries; |
michael@0 | 441 | while (enumerator.hasMoreElements()) |
michael@0 | 442 | { |
michael@0 | 443 | var curFile = enumerator.getNext(); |
michael@0 | 444 | curFile = curFile.QueryInterface(Components.interfaces.nsIFile); |
michael@0 | 445 | var leafName = curFile.leafName; |
michael@0 | 446 | if (leafName.indexOf(inRequiredExtension) != -1) |
michael@0 | 447 | { |
michael@0 | 448 | fileArray.push(leafName); |
michael@0 | 449 | } |
michael@0 | 450 | } |
michael@0 | 451 | |
michael@0 | 452 | return fileArray; |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | |
michael@0 | 456 | function BuildTestURLsList(testSourceType) |
michael@0 | 457 | { |
michael@0 | 458 | // clear the array |
michael@0 | 459 | gTestURLs.splice(0, gTestURLs.length); |
michael@0 | 460 | gTestURLsIndex = 0; |
michael@0 | 461 | |
michael@0 | 462 | if (testSourceType == kTestSourceSingleFile) |
michael@0 | 463 | { |
michael@0 | 464 | var testURL = document.testForm.singleTestFileInput.value; |
michael@0 | 465 | if (testURL.substr(-5) != ".html") |
michael@0 | 466 | { |
michael@0 | 467 | // append /index.html if we have to |
michael@0 | 468 | if (testURL.substr(-1) != "/") |
michael@0 | 469 | testURL += "/"; |
michael@0 | 470 | testURL += "index.html"; |
michael@0 | 471 | } |
michael@0 | 472 | gTestURLs[0] = testURL; |
michael@0 | 473 | } |
michael@0 | 474 | else |
michael@0 | 475 | { |
michael@0 | 476 | for (var i = 0; i < gTestcaseDirArray.length; i++) |
michael@0 | 477 | { |
michael@0 | 478 | var dirFile = gTestcaseDirArray[i]; // nsIFile for the dir |
michael@0 | 479 | AddDirectoryEntriesToTestList(dirFile, ".html"); |
michael@0 | 480 | } |
michael@0 | 481 | } |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | function CompareFilesInDir(inBaseDir, inBaseExtension, inVerifyDir, inVerifyExtension) |
michael@0 | 485 | { |
michael@0 | 486 | var comapareFiles = DirectoryEntriesToArray(inBaseDir, inBaseExtension); |
michael@0 | 487 | |
michael@0 | 488 | for (var i = 0; i < comapareFiles.length; i ++) |
michael@0 | 489 | { |
michael@0 | 490 | var curFilename = comapareFiles[i]; |
michael@0 | 491 | var testFileBasename = curFilename.replace(inBaseExtension, ""); |
michael@0 | 492 | CompareFrameDumps(testFileBasename, inBaseDir, inBaseExtension, inVerifyDir, inVerifyExtension); |
michael@0 | 493 | } |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | function GetTestType() |
michael@0 | 497 | { |
michael@0 | 498 | if (document.testForm.doWhat[0].checked) |
michael@0 | 499 | return kTestTypeBaseline; |
michael@0 | 500 | |
michael@0 | 501 | if (document.testForm.doWhat[1].checked) |
michael@0 | 502 | return kTestTypeVerify; |
michael@0 | 503 | |
michael@0 | 504 | if (document.testForm.doWhat[2].checked) |
michael@0 | 505 | return kTestTypeVerifyAndCompare; |
michael@0 | 506 | |
michael@0 | 507 | if (document.testForm.doWhat[3].checked) |
michael@0 | 508 | return kTestTypeCompare; |
michael@0 | 509 | |
michael@0 | 510 | return 0; |
michael@0 | 511 | } |
michael@0 | 512 | |
michael@0 | 513 | function RunTests() |
michael@0 | 514 | { |
michael@0 | 515 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
michael@0 | 516 | |
michael@0 | 517 | ClearOutput(); |
michael@0 | 518 | SaveFormToPrefs(); |
michael@0 | 519 | |
michael@0 | 520 | var testSourceType; |
michael@0 | 521 | if (document.testForm.testType[0].checked) |
michael@0 | 522 | testSourceType = kTestSourceSingleFile; |
michael@0 | 523 | else |
michael@0 | 524 | testSourceType = kTestSourceDirList; |
michael@0 | 525 | |
michael@0 | 526 | gTestType = GetTestType(); |
michael@0 | 527 | |
michael@0 | 528 | gBaselineFileExtension = document.testForm.baselineFileExtension.value; |
michael@0 | 529 | gVerifyFileExtension = document.testForm.verifyFileExtension.value; |
michael@0 | 530 | |
michael@0 | 531 | if (gTestType == kTestTypeCompare) |
michael@0 | 532 | { |
michael@0 | 533 | // to compare, we'll just run through all the files in the |
michael@0 | 534 | // baseline and verify dirs, and compare those that exist in |
michael@0 | 535 | // both. |
michael@0 | 536 | CompareFilesInDir(gBaselineOutputDir, gBaselineFileExtension, gVerifyOutputDir, gVerifyFileExtension); |
michael@0 | 537 | } |
michael@0 | 538 | else |
michael@0 | 539 | { |
michael@0 | 540 | BuildTestURLsList(testSourceType); |
michael@0 | 541 | |
michael@0 | 542 | gTestWindow = window.open("about:blank", "Test window", |
michael@0 | 543 | "width=800,height=600,status=yes,toolbars=no"); |
michael@0 | 544 | |
michael@0 | 545 | // start the first load |
michael@0 | 546 | var testURL = gTestURLs[0]; |
michael@0 | 547 | gTestURLsIndex = 1; |
michael@0 | 548 | LoadTestURL(gTestWindow, testURL); |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | } |
michael@0 | 552 | |
michael@0 | 553 |