mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 765192 - Fix broken test. r=dolske
There were a couple of things wrong here: 1 - The whole recursive frame load waiting thing was totally unnecessary. Load doesn't fire on the window until all descendant iframes have loaded. 2 - The chrome event handler wasn't filtering by target, which it should. This is probably to blame for the intermittent orange. 3 - Setting window.location during document load actually invokes window.location.replace. 4 - Session history navigation seems to have weird behavior when called from an onload handler. I wanted to investigate this further, but I've already spent too much time on this. SimpleTest.executeSoon() seems to do the trick here.
This commit is contained in:
parent
832b4cf1ef
commit
552dcd7d67
@ -12,51 +12,13 @@ function isActive(aWindow) {
|
||||
return docshell.isActive;
|
||||
}
|
||||
|
||||
function oneShotListener(aElem, aType, aCallback) {
|
||||
aElem.addEventListener(aType, function () {
|
||||
aElem.removeEventListener(aType, arguments.callee, true);
|
||||
|
||||
// aCallback is executed asynchronously, which is handy because load
|
||||
// events fire before mIsDocumentLoaded is actually set to true. :(
|
||||
executeSoon(aCallback);
|
||||
}, true);
|
||||
}
|
||||
|
||||
// Returns a closure that iteratively (BFS) waits for all
|
||||
// of the descendant frames of aInitialWindow to finish loading,
|
||||
// then calls aFinalCallback.
|
||||
function frameLoadWaiter(aInitialWindow, aFinalCallback) {
|
||||
|
||||
// The window we're currently waiting on
|
||||
var curr = aInitialWindow;
|
||||
|
||||
// The windows we need to wait for
|
||||
var waitQueue = [];
|
||||
|
||||
// The callback to call when we're all done
|
||||
var finalCallback = aFinalCallback;
|
||||
|
||||
function frameLoadCallback() {
|
||||
|
||||
// Push any subframes of what we just got
|
||||
for (var i = 0; i < curr.frames.length; ++i)
|
||||
waitQueue.push(curr.frames[i]);
|
||||
|
||||
// Handle the next window in the queue
|
||||
if (waitQueue.length >= 1) {
|
||||
curr = waitQueue.shift();
|
||||
if (curr.document.readyState == "complete")
|
||||
frameLoadCallback();
|
||||
else
|
||||
oneShotListener(curr, "load", frameLoadCallback);
|
||||
function oneShotListener(aBrowser, aType, aCallback) {
|
||||
aBrowser.addEventListener(aType, function (evt) {
|
||||
if (evt.target != aBrowser.contentDocument)
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, we're all done. Call the final callback
|
||||
finalCallback();
|
||||
}
|
||||
|
||||
return frameLoadCallback;
|
||||
aBrowser.removeEventListener(aType, arguments.callee, true);
|
||||
aCallback();
|
||||
}, true);
|
||||
}
|
||||
|
||||
// Entry point from Mochikit
|
||||
@ -103,7 +65,7 @@ function step2() {
|
||||
ctx.tab2 = gBrowser.addTab(testPath + "bug343515_pg2.html");
|
||||
ctx.tab2Browser = gBrowser.getBrowserForTab(ctx.tab2);
|
||||
ctx.tab2Window = ctx.tab2Browser.contentWindow;
|
||||
oneShotListener(ctx.tab2Browser, "load", frameLoadWaiter(ctx.tab2Window, step3));
|
||||
oneShotListener(ctx.tab2Browser, "load", step3);
|
||||
}
|
||||
|
||||
function step3() {
|
||||
@ -119,8 +81,12 @@ function step3() {
|
||||
ok(!isActive(ctx.tab2Window.frames[1]), "Tab2 iframe 1 should be inactive");
|
||||
|
||||
// Navigate tab 2 to a different page
|
||||
ctx.tab2Window.location = testPath + "bug343515_pg3.html";
|
||||
oneShotListener(ctx.tab2Browser, "load", frameLoadWaiter(ctx.tab2Window, step4));
|
||||
// Note that we need to use setAttribute('src', ...) here rather than setting
|
||||
// window.location, because this function gets called in an onload handler, and
|
||||
// per spec setting window.location during onload is equivalent to calling
|
||||
// window.replace.
|
||||
ctx.tab2Browser.setAttribute('src', testPath + "bug343515_pg3.html");
|
||||
oneShotListener(ctx.tab2Browser, "load", step4);
|
||||
}
|
||||
|
||||
function step4() {
|
||||
@ -149,8 +115,8 @@ function step4() {
|
||||
ok(isActive(ctx.tab2Window.frames[1]), "Tab2 iframe 1 should be active");
|
||||
|
||||
// Go back
|
||||
oneShotListener(ctx.tab2Browser, "pageshow", frameLoadWaiter(ctx.tab2Window, step5));
|
||||
ctx.tab2Browser.goBack();
|
||||
oneShotListener(ctx.tab2Browser, "pageshow", step5);
|
||||
SimpleTest.executeSoon(function() {ctx.tab2Browser.goBack();});
|
||||
|
||||
}
|
||||
|
||||
@ -167,8 +133,8 @@ function step5() {
|
||||
gBrowser.selectedTab = ctx.tab1;
|
||||
|
||||
// Navigate to page 3
|
||||
ctx.tab1Window.location = testPath + "bug343515_pg3.html";
|
||||
oneShotListener(ctx.tab1Browser, "load", frameLoadWaiter(ctx.tab1Window, step6));
|
||||
ctx.tab1Browser.setAttribute('src', testPath + "bug343515_pg3.html");
|
||||
oneShotListener(ctx.tab1Browser, "load", step6);
|
||||
}
|
||||
|
||||
function step6() {
|
||||
@ -184,10 +150,8 @@ function step6() {
|
||||
ok(!isActive(ctx.tab2Window.frames[1]), "Tab2 iframe 1 should be inactive");
|
||||
|
||||
// Go forward on tab 2
|
||||
oneShotListener(ctx.tab2Browser, "pageshow", frameLoadWaiter(ctx.tab2Window, step7));
|
||||
var tab2docshell = ctx.tab2Window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation);
|
||||
tab2docshell.goForward();
|
||||
oneShotListener(ctx.tab2Browser, "pageshow", step7);
|
||||
SimpleTest.executeSoon(function() {ctx.tab2Browser.goForward();});
|
||||
}
|
||||
|
||||
function step7() {
|
||||
|
Loading…
Reference in New Issue
Block a user