2012-06-21 18:23:48 +00:00
|
|
|
/* Any copyright is dedicated to the public domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2012-06-21 18:23:48 +00:00
|
|
|
// Bug 741755 - Test that canGo{Back,Forward} and go{Forward,Back} work with
|
|
|
|
// <iframe mozbrowser>.
|
2012-06-21 18:23:48 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-03-28 19:51:10 +00:00
|
|
|
browserElementTestHelpers.setEnabledPref(true);
|
|
|
|
browserElementTestHelpers.addPermission();
|
2012-06-21 18:23:48 +00:00
|
|
|
|
|
|
|
var iframe;
|
2012-06-21 18:23:48 +00:00
|
|
|
function addOneShotIframeEventListener(event, fn) {
|
|
|
|
function wrapper(e) {
|
|
|
|
iframe.removeEventListener(event, wrapper);
|
|
|
|
fn(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
iframe.addEventListener(event, wrapper);
|
|
|
|
}
|
|
|
|
|
2012-06-21 18:23:48 +00:00
|
|
|
function runTest() {
|
|
|
|
iframe = document.createElement('iframe');
|
2014-10-31 02:39:15 +00:00
|
|
|
iframe.setAttribute('mozbrowser', 'true');
|
2012-06-21 18:23:48 +00:00
|
|
|
|
2012-06-21 18:23:48 +00:00
|
|
|
addOneShotIframeEventListener('mozbrowserloadend', function() {
|
2012-06-21 18:23:48 +00:00
|
|
|
SimpleTest.executeSoon(test2);
|
|
|
|
});
|
|
|
|
|
|
|
|
iframe.src = browserElementTestHelpers.emptyPage1;
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkCanGoBackAndForward(canGoBack, canGoForward, nextTest) {
|
|
|
|
var seenCanGoBackResult = false;
|
|
|
|
iframe.getCanGoBack().onsuccess = function(e) {
|
|
|
|
is(seenCanGoBackResult, false, "onsuccess handler shouldn't be called twice.");
|
|
|
|
seenCanGoBackResult = true;
|
|
|
|
is(e.target.result, canGoBack);
|
|
|
|
maybeRunNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
var seenCanGoForwardResult = false;
|
|
|
|
iframe.getCanGoForward().onsuccess = function(e) {
|
|
|
|
is(seenCanGoForwardResult, false, "onsuccess handler shouldn't be called twice.");
|
|
|
|
seenCanGoForwardResult = true;
|
|
|
|
is(e.target.result, canGoForward);
|
|
|
|
maybeRunNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
function maybeRunNextTest() {
|
|
|
|
if (seenCanGoBackResult && seenCanGoForwardResult) {
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test2() {
|
2012-06-21 18:23:48 +00:00
|
|
|
checkCanGoBackAndForward(false, false, test3);
|
2012-06-21 18:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test3() {
|
2012-06-21 18:23:48 +00:00
|
|
|
addOneShotIframeEventListener('mozbrowserloadend', function() {
|
|
|
|
checkCanGoBackAndForward(true, false, test4);
|
|
|
|
});
|
|
|
|
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
iframe.src = browserElementTestHelpers.emptyPage2;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function test4() {
|
|
|
|
addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
|
|
|
|
is(e.detail, browserElementTestHelpers.emptyPage3);
|
|
|
|
checkCanGoBackAndForward(true, false, test5);
|
|
|
|
});
|
|
|
|
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
iframe.src = browserElementTestHelpers.emptyPage3;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function test5() {
|
|
|
|
addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
|
|
|
|
is(e.detail, browserElementTestHelpers.emptyPage2);
|
|
|
|
checkCanGoBackAndForward(true, true, test6);
|
|
|
|
});
|
|
|
|
iframe.goBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test6() {
|
|
|
|
addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
|
|
|
|
is(e.detail, browserElementTestHelpers.emptyPage1);
|
|
|
|
checkCanGoBackAndForward(false, true, SimpleTest.finish);
|
2012-06-21 18:23:48 +00:00
|
|
|
});
|
2012-06-21 18:23:48 +00:00
|
|
|
iframe.goBack();
|
2012-06-21 18:23:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 19:51:10 +00:00
|
|
|
addEventListener('testready', runTest);
|