Make reftest use onload rather than nsIWebProgressListener, and make it time out after load failure. b=369319 r=robcee

This commit is contained in:
dbaron%dbaron.org 2007-02-12 02:21:18 +00:00
Родитель 54de5410e3
Коммит ffb5d69ec4
1 изменённых файлов: 33 добавлений и 67 удалений

Просмотреть файл

@ -46,12 +46,14 @@ const IO_SERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
const NS_LOCALFILEINPUTSTREAM_CONTRACTID = const NS_LOCALFILEINPUTSTREAM_CONTRACTID =
"@mozilla.org/network/file-input-stream;1"; "@mozilla.org/network/file-input-stream;1";
const LOAD_FAILURE_TIMEOUT = 10000; // ms
var gBrowser; var gBrowser;
var gProgressListener;
var gCanvas; var gCanvas;
var gURLs; var gURLs;
var gState; var gState;
var gPart1Key; var gPart1Key;
var gFailureTimeout;
const EXPECTED_PASS = 0; const EXPECTED_PASS = 0;
const EXPECTED_FAIL = 1; const EXPECTED_FAIL = 1;
@ -60,9 +62,8 @@ const EXPECTED_RANDOM = 2;
function OnRefTestLoad() function OnRefTestLoad()
{ {
gBrowser = document.getElementById("browser"); gBrowser = document.getElementById("browser");
gProgressListener = new RefTestProgressListener;
gBrowser.webProgress.addProgressListener(gProgressListener, gBrowser.addEventListener("load", OnDocumentLoad, true);
CI.nsIWebProgress.NOTIFY_STATE_NETWORK);
gCanvas = document.createElementNS(XHTML_NS, "canvas"); gCanvas = document.createElementNS(XHTML_NS, "canvas");
var windowElem = document.documentElement; var windowElem = document.documentElement;
@ -71,7 +72,7 @@ function OnRefTestLoad()
try { try {
ReadTopManifest(window.arguments[0]); ReadTopManifest(window.arguments[0]);
StartCurrentURI(); StartCurrentTest();
} catch (ex) { } catch (ex) {
gBrowser.loadURI('data:text/plain,' + ex); gBrowser.loadURI('data:text/plain,' + ex);
} }
@ -79,7 +80,7 @@ function OnRefTestLoad()
function OnRefTestUnload() function OnRefTestUnload()
{ {
gBrowser.webProgress.removeProgressListener(gProgressListener); gBrowser.removeEventListener("load", OnDocumentLoad, true);
} }
function ReadTopManifest(aFileURL) function ReadTopManifest(aFileURL)
@ -164,10 +165,20 @@ function ReadManifest(aURL)
} while (more); } while (more);
} }
function StartCurrentURI() function StartCurrentTest()
{ {
gState = 1; if (gURLs.length == 0)
gBrowser.loadURI(gURLs[0].url1.spec); DoneTests();
else
StartCurrentURI(1);
}
function StartCurrentURI(aState)
{
gFailureTimeout = setTimeout(LoadFailed, LOAD_FAILURE_TIMEOUT);
gState = aState;
gBrowser.loadURI(gURLs[0]["url" + aState].spec);
} }
function DoneTests() function DoneTests()
@ -186,6 +197,12 @@ function IFrameToKey()
return gCanvas.toDataURL(); return gCanvas.toDataURL();
} }
function OnDocumentLoad()
{
clearTimeout(gFailureTimeout);
setTimeout(DocumentLoaded, 0);
}
function DocumentLoaded() function DocumentLoaded()
{ {
var key = IFrameToKey(); var key = IFrameToKey();
@ -193,8 +210,7 @@ function DocumentLoaded()
case 1: case 1:
gPart1Key = key; gPart1Key = key;
gState = 2; StartCurrentURI(2);
gBrowser.loadURI(gURLs[0].url2.spec);
break; break;
case 2: case 2:
var equal = (key == gPart1Key); var equal = (key == gPart1Key);
@ -229,67 +245,17 @@ function DocumentLoaded()
gPart1Key = undefined; gPart1Key = undefined;
gURLs.shift(); gURLs.shift();
if (gURLs.length == 0) StartCurrentTest();
DoneTests();
else
StartCurrentURI();
break; break;
default: default:
throw "Unexpected state." throw "Unexpected state."
} }
} }
function RefTestProgressListener() function LoadFailed()
{ {
} dump("REFTEST UNEXPECTED FAIL (LOADING): " +
gURLs[0]["url" + gState].spec + "\n");
RefTestProgressListener.prototype = { gURLs.shift();
StartCurrentTest();
QueryInterface : function(aIID)
{
if (aIID.equals(CI.nsIWebProgressListener) ||
aIID.equals(CI.nsISupportsWeakReference) ||
aIID.equals(CI.nsISupports))
return this;
throw CR.NS_NOINTERFACE;
},
// nsIWebProgressListener implementation
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
{
if (!(aStateFlags & CI.nsIWebProgressListener.STATE_IS_NETWORK) ||
aWebProgress != gBrowser.webProgress)
return;
if (aStateFlags & CI.nsIWebProgressListener.STATE_START) {
this.mLoading = true;
} else if (aStateFlags & CI.nsIWebProgressListener.STATE_STOP) {
if (this.mLoading) {
this.mLoading = false;
// Let other things happen in the first 20ms, since this
// doesn't really seem to be when the page is done loading.
setTimeout(DocumentLoaded, 20);
}
}
},
onProgressChange : function(aWebProgress, aRequest,
aCurSelfProgress, aMaxSelfProgress,
aCurTotalProgress, aMaxTotalProgress)
{
},
onLocationChange : function(aWebProgress, aRequest, aLocation)
{
},
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
{
},
onSecurityChange : function(aWebProgress, aRequest, aState)
{
},
mLoading : false
} }