1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/tests/buster/buster-view.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 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 view = 1.10 +{ 1.11 + onRun : function() 1.12 + { 1.13 + runQueue.mArray = new Array(); 1.14 + var sels = this.boxObject.view.selection,a=new Object(),b=new Object(),k; 1.15 + var rowResource, name, path; 1.16 + for (k=0;k<sels.getRangeCount();k++){ 1.17 + sels.getRangeAt(k,a,b); 1.18 + for (var l=a.value;l<=b.value;l++) { 1.19 + rowResource = this.builder.getResourceAtIndex(l); 1.20 + itemCache.getItem(rowResource); 1.21 + } 1.22 + } 1.23 + runQueue.run(); 1.24 + }, 1.25 + displayTest : function() 1.26 + { 1.27 + var current = this.boxObject.view.selection.currentIndex; 1.28 + var rowResource = this.builder.getResourceAtIndex(current); 1.29 + var item = itemCache.getItem(rowResource); 1.30 + }, 1.31 + browseForRDF : function() 1.32 + { 1.33 + var fp = doCreateRDFFP('Xalan Description File', 1.34 + nsIFilePicker.modeOpen); 1.35 + var res = fp.show(); 1.36 + 1.37 + if (res == nsIFilePicker.returnOK) { 1.38 + var furl = fp.fileURL; 1.39 + this.setDataSource(fp.fileURL.spec); 1.40 + } 1.41 + }, 1.42 + dump_Good : function() 1.43 + { 1.44 + var enumi = this.mResultDS.GetSources(krTypeSucc, kGood, true); 1.45 + var k = 0; 1.46 + while (enumi.hasMoreElements()) { 1.47 + k += 1; 1.48 + dump(enumi.getNext().QueryInterface(nsIRDFResource).Value+"\n"); 1.49 + } 1.50 + dump("found "+k+" good tests\n"); 1.51 + }, 1.52 + prune_ds : function() 1.53 + { 1.54 + if (this.mResultDS) { 1.55 + this.mResultDS.QueryInterface(nsIRDFPurgeableDataSource).Sweep(); 1.56 + } 1.57 + regressionStats.init() 1.58 + itemCache.mArray = new Array(); 1.59 + }, 1.60 + setDataSource : function(aSpec) 1.61 + { 1.62 + var baseSpec; 1.63 + if (aSpec) { 1.64 + baseSpec = aSpec; 1.65 + } 1.66 + else { 1.67 + baseSpec = document.getElementById("xalan_rdf").value; 1.68 + } 1.69 + if (this.mXalanDS && this.mXalanDS.URI == baseSpec) { 1.70 + this.mXalanDS.QueryInterface(nsIRDFRemoteDataSource); 1.71 + this.mXalanDS.Refresh(true); 1.72 + } 1.73 + else { 1.74 + if (this.mXalanDS) { 1.75 + this.database.RemoveDataSource(view.mXalanDS); 1.76 + } 1.77 + this.mXalanDS = kRDFSvc.GetDataSourceBlocking(baseSpec); 1.78 + if (!this.mXalanDS) { 1.79 + alert("Unable do load DataSource: "+baseSpec); 1.80 + return; 1.81 + } 1.82 + this.database.AddDataSource(this.mXalanDS); 1.83 + } 1.84 + regressionStats.init(); 1.85 + if (!this.mResultDS) { 1.86 + this.mResultDS = doCreate(kRDFInMemContractID, 1.87 + nsIRDFDataSource); 1.88 + this.database.AddDataSource(view.mResultDS); 1.89 + if (!this.mResultDS) { 1.90 + alert("Unable to create result InMemDatasource"); 1.91 + return; 1.92 + } 1.93 + } 1.94 + 1.95 + this.builder.rebuild(); 1.96 + document.getElementById("xalan_rdf").value = baseSpec; 1.97 + runItem.prototype.kXalan.init(runItem.prototype.kXalan.URLTYPE_STANDARD, 1.98 + 0, baseSpec, null, null); 1.99 + }, 1.100 + loadHtml : function(aUrl, aListener) 1.101 + { 1.102 + const nsIIRequestor = Components.interfaces.nsIInterfaceRequestor; 1.103 + const nsIWebProgress = Components.interfaces.nsIWebProgress; 1.104 + var req = this.mIframe.webNavigation.QueryInterface(nsIIRequestor); 1.105 + var prog = req.getInterface(nsIWebProgress); 1.106 + prog.addProgressListener(aListener, nsIWebProgress.NOTIFY_ALL); 1.107 + this.mIframe.webNavigation.loadURI(aUrl, 0,null,null,null); 1.108 + }, 1.109 + fillItemContext : function() 1.110 + { 1.111 + var index = view.boxObject.view.selection.currentIndex; 1.112 + var res = view.builder.getResourceAtIndex(index); 1.113 + var purp = view.mXalanDS.GetTarget(res, krTypePurp, true); 1.114 + return (purp != null); 1.115 + } 1.116 +} 1.117 + 1.118 +regressionStats = 1.119 +{ 1.120 + observe: function(aSubject, aTopic, aData) 1.121 + { 1.122 + if (aTopic != 'success') { 1.123 + return; 1.124 + } 1.125 + var arc = (aData == "true") ? krTypeSuccCount : krTypeFailCount; 1.126 + this.assertNewCount(aSubject, arc, 1); 1.127 + }, 1.128 + init: function() 1.129 + { 1.130 + if (this.mRegressionDS) { 1.131 + this.mRegressionDS.QueryInterface(nsIRDFPurgeableDataSource).Sweep(); 1.132 + } 1.133 + else { 1.134 + this.mRegressionDS = 1.135 + doCreate(kRDFInMemContractID, nsIRDFDataSource); 1.136 + view.database.AddDataSource(this.mRegressionDS); 1.137 + } 1.138 + }, 1.139 + getParent: function(aDS, aSource) 1.140 + { 1.141 + // parent chached? 1.142 + var parent = this.mRegressionDS.GetTarget(aSource, krTypeParent, true); 1.143 + if (!parent) { 1.144 + var labels = view.mXalanDS.ArcLabelsIn(aSource); 1.145 + while (labels.hasMoreElements()) { 1.146 + var arc = labels.getNext().QueryInterface(nsIRDFResource); 1.147 + if (arc.Value.match(this.mChildRE)) { 1.148 + parent = view.mXalanDS.GetSource(arc, aSource, true); 1.149 + // cache the parent 1.150 + this.mRegressionDS.Assert(aSource, krTypeParent, 1.151 + parent, true); 1.152 + } 1.153 + } 1.154 + } 1.155 + return parent; 1.156 + }, 1.157 + assertNewCount: function(aSource, aArc, aIncrement) 1.158 + { 1.159 + var root = kRDFSvc.GetResource('urn:root'); 1.160 + var count = 0; 1.161 + // parent chached? 1.162 + var parent = this.getParent(view.XalanDS, aSource); 1.163 + while (parent && !parent.EqualsNode(root)) { 1.164 + var countRes = view.mResultDS.GetTarget(parent, aArc, true); 1.165 + if (countRes) { 1.166 + count = countRes.QueryInterface(nsIRDFInt).Value; 1.167 + } 1.168 + var newCountRes = kRDFSvc.GetIntLiteral(count + aIncrement); 1.169 + if (!newCountRes) { 1.170 + return; 1.171 + } 1.172 + 1.173 + if (countRes) { 1.174 + view.mResultDS.Change(parent, aArc, countRes, newCountRes); 1.175 + } 1.176 + else { 1.177 + view.mResultDS.Assert(parent, aArc, newCountRes, true); 1.178 + } 1.179 + parent = this.getParent(view.XalanDS, parent); 1.180 + } 1.181 + }, 1.182 + mRegressionDS: 0, 1.183 + mChildRE: /http:\/\/www\.w3\.org\/1999\/02\/22-rdf-syntax-ns#_/ 1.184 +} 1.185 + 1.186 +function rdfObserve(aSubject, aTopic, aData) 1.187 +{ 1.188 + if (aTopic == "success") { 1.189 + var target = (aData == "true") ? kGood : kBad; 1.190 + view.mResultDS.Assert(aSubject, krTypeSucc, target, true); 1.191 + 1.192 + regressionStats.observe(aSubject, aTopic, aData); 1.193 + } 1.194 +} 1.195 + 1.196 +runItem.prototype.kObservers.push(rdfObserve);