зеркало из https://github.com/mozilla/pjs.git
Bug 113778; enhancing window open testto add some features and change to report median on tinderbox; r=mcafee
This commit is contained in:
Родитель
43c32c2824
Коммит
d9e648a061
|
@ -8,15 +8,65 @@ const SERVER_URL = "http://jrgm.mcom.com/cgi-bin/window-open-2.0/openreport.p
|
|||
const OPENER_DELAY = 1000;
|
||||
|
||||
// three phases: single open/close; overlapped open/close; open-all/close-all
|
||||
const PHASE_ONE = 10;
|
||||
const PHASE_TWO = 0;
|
||||
const PHASE_THREE = 0;
|
||||
var PHASE_ONE = 10;
|
||||
var PHASE_TWO = 0;
|
||||
var PHASE_THREE = 0;
|
||||
|
||||
// keep this many windows concurrently open during overlapped phase
|
||||
const OVERLAP_COUNT = 3;
|
||||
var OVERLAP_COUNT = 3;
|
||||
|
||||
// repeat three phases CYCLES times
|
||||
const CYCLES = 1;
|
||||
var CYCLES = 1;
|
||||
|
||||
// autoclose flag
|
||||
var AUTOCLOSE = 1;
|
||||
|
||||
// Chrome url for child windows.
|
||||
var KID_CHROME = null;
|
||||
var SAVED_CHROME = null;
|
||||
|
||||
// URL options and correspnding vars.
|
||||
const options = [ [ "phase1", "PHASE_ONE", false ],
|
||||
[ "phase2", "PHASE_TWO", false ],
|
||||
[ "phase3", "PHASE_THREE", false ],
|
||||
[ "overlap", "OVERLAP_COUNT", false ],
|
||||
[ "cycles", "CYCLES", false ],
|
||||
[ "chrome", "KID_CHROME", true ],
|
||||
[ "close", "AUTOCLOSE", false ] ];
|
||||
|
||||
// Note: You can attach search options to the url for this file to control
|
||||
// any of the options in the array above. E.g., specifying
|
||||
// mozilla -chrome "file:///D|/mozilla/xpfe/test/winopen.xul?phase1=16&close=0"
|
||||
// will run this script with PHASE_ONE=16 and AUTOCLOSE=0.
|
||||
//
|
||||
// On Win32, you must enclose the -chrome option in quotes in order pass funny Win32 shell
|
||||
// characters such as '&' or '|'!
|
||||
|
||||
var opts = window.location.search.substring(1).split( '&' );
|
||||
for ( opt in opts ) {
|
||||
for ( var i in options ) {
|
||||
if ( opts[opt].indexOf( options[i][0]+"=" ) == 0 ) {
|
||||
var newVal = opts[opt].split( '=' )[ 1 ];
|
||||
// wrap with quotes, if required.
|
||||
if ( options[i][2] ) {
|
||||
newVal = '"' + newVal + '"';
|
||||
}
|
||||
eval( options[i][1] + "=" + newVal + ";" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var prefs = null;
|
||||
|
||||
if ( KID_CHROME ) {
|
||||
// Reset browser.chromeURL so it points to KID_CHROME.
|
||||
// This will cause window.open in openWindow to open that chrome.
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService( Components.interfaces.nsIPrefBranch );
|
||||
SAVED_CHROME = prefs.getCharPref( "browser.chromeURL" );
|
||||
prefs.setCharPref( "browser.chromeURL", KID_CHROME );
|
||||
}
|
||||
|
||||
const CYCLE_SIZE = PHASE_ONE + PHASE_TWO + PHASE_THREE;
|
||||
const MAX_INDEX = CYCLE_SIZE * CYCLES; // total number of windows to open
|
||||
|
@ -104,6 +154,19 @@ function reapWindows() {
|
|||
}
|
||||
}
|
||||
|
||||
function calcMedian( numbers ) {
|
||||
if ( numbers.length == 0 ) {
|
||||
return 0;
|
||||
} else if ( numbers.length == 1 ) {
|
||||
return numbers[0];
|
||||
} else if ( numbers.length == 2 ) {
|
||||
return ( numbers[0] + numbers[1] ) / 2;
|
||||
} else {
|
||||
numbers.sort( function (a,b){ return a-b; } );
|
||||
var n = Math.floor( numbers.length / 2 );
|
||||
return numbers.length % 2 ? numbers[n] : ( numbers[n-1] + numbers[n] ) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
function reportResults() {
|
||||
//XXX need to create a client-side method to do this?
|
||||
|
@ -119,24 +182,63 @@ function reportResults() {
|
|||
//window.open(reportURL, "test-results");
|
||||
var avgOpenTime = 0;
|
||||
var minOpenTime = 99999;
|
||||
var maxOpenTime = 0;
|
||||
var medOpenTime = calcMedian( openingTimes.slice(1) );
|
||||
// ignore first open
|
||||
for (i = 1; i < MAX_INDEX; i++) {
|
||||
avgOpenTime += openingTimes[i];
|
||||
if ( minOpenTime > openingTimes[i] ) {
|
||||
minOpenTime = openingTimes[i];
|
||||
}
|
||||
if ( maxOpenTime < openingTimes[i] ) {
|
||||
maxOpenTime = openingTimes[i];
|
||||
}
|
||||
}
|
||||
avgOpenTime = Math.round(avgOpenTime / (MAX_INDEX - 1));
|
||||
dump("openingTimes="+openingTimes.slice(1)+"\n");
|
||||
dump("avgOpenTime:" + avgOpenTime + "\n" );
|
||||
dump("__xulWinOpenTime:" + minOpenTime + "\n");
|
||||
window.close();
|
||||
dump("minOpenTime:" + minOpenTime + "\n" );
|
||||
dump("maxOpenTime:" + maxOpenTime + "\n" );
|
||||
dump("medOpenTime:" + medOpenTime + "\n" );
|
||||
dump("__xulWinOpenTime:" + medOpenTime + "\n");
|
||||
// Close the root window, if required.
|
||||
if ( AUTOCLOSE ) {
|
||||
window.close();
|
||||
} else {
|
||||
document.getElementById("formTimes").value = openingTimes.slice(1);
|
||||
document.getElementById("formAvg").value = avgOpenTime;
|
||||
document.getElementById("formMin").value = minOpenTime;
|
||||
document.getElementById("formMax").value = maxOpenTime;
|
||||
document.getElementById("formMed").value = medOpenTime;
|
||||
document.getElementById("formAgain").setAttribute( "disabled", "false" );
|
||||
}
|
||||
}
|
||||
|
||||
function tryAgain() {
|
||||
document.getElementById("formAgain").setAttribute( "disabled", "true" );
|
||||
windowList = [];
|
||||
startingTimes = [];
|
||||
openingTimes = [];
|
||||
closingTimes = [];
|
||||
currentIndex = 0;
|
||||
openWindow();
|
||||
}
|
||||
|
||||
function restoreChromeURL() {
|
||||
// Restore browser.chromeURL pref.
|
||||
if ( KID_CHROME && SAVED_CHROME.length ) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
prefs.setCharPref( "browser.chromeURL", SAVED_CHROME );
|
||||
}
|
||||
}
|
||||
|
||||
function openWindow() {
|
||||
startingTimes[currentIndex] = (new Date()).getTime();
|
||||
windowList[currentIndex] = window.open(KID_URL, currentIndex);
|
||||
var path = window.location.pathname.substring( 0, window.location.pathname.lastIndexOf('/') );
|
||||
var url = window.location.protocol + "//" +
|
||||
window.location.hostname + path + "/" +
|
||||
KID_URL;
|
||||
windowList[currentIndex] = window.open(url, currentIndex);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
orient="vertical"
|
||||
height="250"
|
||||
width="250"
|
||||
height="300"
|
||||
width="400"
|
||||
windowtype="opener:test"
|
||||
onunload="restoreChromeURL();"
|
||||
onload="scheduleNextWindow();">
|
||||
|
||||
<script src="winopen.js" type="application/x-javascript"></script>
|
||||
|
@ -35,5 +36,41 @@ This will open a series of browser windows, either "one at a
|
|||
<separator class="thick"/>
|
||||
</groupbox>
|
||||
|
||||
<groupbox orient="vertical">
|
||||
<caption label="Results"/>
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row autostretch="never" valign="middle">
|
||||
<text value="Times (ignoring the first):"/>
|
||||
<textbox id="formTimes" size="45" value=""/>
|
||||
</row>
|
||||
<row autostretch="never" valign="middle">
|
||||
<text value="Txul (median):"/>
|
||||
<hbox>
|
||||
<textbox id="formMed" size="6" value=""/>
|
||||
<spring/>
|
||||
<button id="formAgain" onclick="tryAgain();" label="Try again" disabled="true"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row autostretch="never" valign="middle">
|
||||
<text value="Avg:"/>
|
||||
<hbox><textbox id="formAvg" size="6" value=""/></hbox>
|
||||
</row>
|
||||
<row autostretch="never" valign="middle">
|
||||
<text value="Min:"/>
|
||||
<hbox><textbox id="formMin" size="6" value=""/></hbox>
|
||||
</row>
|
||||
<row autostretch="never" valign="middle">
|
||||
<text value="Max:"/>
|
||||
<hbox><textbox id="formMax" size="6" value=""/></hbox>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</groupbox>
|
||||
|
||||
</window>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче