1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/tests/XSLTMark/XSLTMark-test.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +var gParser = new DOMParser; 1.10 +var gTimeout; 1.11 + 1.12 +function Test(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) 1.13 +{ 1.14 + this.mTitle = aTitle; 1.15 + this.mObserver = aObserver; 1.16 + this.mTotal = aNumber; 1.17 + this.mDone = 0; 1.18 + var xmlcontent = loadFile(aSourceURL); 1.19 + var xslcontent = loadFile(aStyleURL); 1.20 + this.mSource = gParser.parseFromString(xmlcontent, 'application/xml'); 1.21 + this.mStyle = gParser.parseFromString(xslcontent, 'application/xml'); 1.22 +} 1.23 + 1.24 +function runTest(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) 1.25 +{ 1.26 + test = new Test(aTitle, aSourceURL, aStyleURL, aNumber, 1.27 + aObserver); 1.28 + gTimeout = setTimeout(onNextTransform, 100, test, 0); 1.29 +} 1.30 + 1.31 +function onNextTransform(aTest, aNumber) 1.32 +{ 1.33 + var proc = new XSLTProcessor; 1.34 + var startTime = Date.now(); 1.35 + proc.importStylesheet(aTest.mStyle); 1.36 + var res = proc.transformToDocument(aTest.mSource); 1.37 + var endTime = Date.now(); 1.38 + aNumber++; 1.39 + var progress = aNumber / aTest.mTotal * 100; 1.40 + if (aTest.mObserver) { 1.41 + aTest.mObserver.progress(aTest.mTitle, endTime - startTime, 1.42 + progress); 1.43 + } 1.44 + if (aNumber < aTest.mTotal) { 1.45 + gTimeout = setTimeout(onNextTransform, 100, aTest, aNumber); 1.46 + } else if (aTest.mObserver) { 1.47 + aTest.mObserver.done(aTest.mTitle); 1.48 + } 1.49 +}