Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | var gParser = new DOMParser; |
michael@0 | 7 | var gTimeout; |
michael@0 | 8 | |
michael@0 | 9 | function Test(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) |
michael@0 | 10 | { |
michael@0 | 11 | this.mTitle = aTitle; |
michael@0 | 12 | this.mObserver = aObserver; |
michael@0 | 13 | this.mTotal = aNumber; |
michael@0 | 14 | this.mDone = 0; |
michael@0 | 15 | var xmlcontent = loadFile(aSourceURL); |
michael@0 | 16 | var xslcontent = loadFile(aStyleURL); |
michael@0 | 17 | this.mSource = gParser.parseFromString(xmlcontent, 'application/xml'); |
michael@0 | 18 | this.mStyle = gParser.parseFromString(xslcontent, 'application/xml'); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function runTest(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) |
michael@0 | 22 | { |
michael@0 | 23 | test = new Test(aTitle, aSourceURL, aStyleURL, aNumber, |
michael@0 | 24 | aObserver); |
michael@0 | 25 | gTimeout = setTimeout(onNextTransform, 100, test, 0); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function onNextTransform(aTest, aNumber) |
michael@0 | 29 | { |
michael@0 | 30 | var proc = new XSLTProcessor; |
michael@0 | 31 | var startTime = Date.now(); |
michael@0 | 32 | proc.importStylesheet(aTest.mStyle); |
michael@0 | 33 | var res = proc.transformToDocument(aTest.mSource); |
michael@0 | 34 | var endTime = Date.now(); |
michael@0 | 35 | aNumber++; |
michael@0 | 36 | var progress = aNumber / aTest.mTotal * 100; |
michael@0 | 37 | if (aTest.mObserver) { |
michael@0 | 38 | aTest.mObserver.progress(aTest.mTitle, endTime - startTime, |
michael@0 | 39 | progress); |
michael@0 | 40 | } |
michael@0 | 41 | if (aNumber < aTest.mTotal) { |
michael@0 | 42 | gTimeout = setTimeout(onNextTransform, 100, aTest, aNumber); |
michael@0 | 43 | } else if (aTest.mObserver) { |
michael@0 | 44 | aTest.mObserver.done(aTest.mTitle); |
michael@0 | 45 | } |
michael@0 | 46 | } |