1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_BackForward.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 741755 - Test that canGo{Back,Forward} and go{Forward,Back} work with 1.8 +// <iframe mozbrowser>. 1.9 + 1.10 +"use strict"; 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +browserElementTestHelpers.setEnabledPref(true); 1.13 +browserElementTestHelpers.addPermission(); 1.14 + 1.15 +var iframe; 1.16 +function addOneShotIframeEventListener(event, fn) { 1.17 + function wrapper(e) { 1.18 + iframe.removeEventListener(event, wrapper); 1.19 + fn(e); 1.20 + }; 1.21 + 1.22 + iframe.addEventListener(event, wrapper); 1.23 +} 1.24 + 1.25 +function runTest() { 1.26 + iframe = document.createElement('iframe'); 1.27 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.28 + 1.29 + addOneShotIframeEventListener('mozbrowserloadend', function() { 1.30 + SimpleTest.executeSoon(test2); 1.31 + }); 1.32 + 1.33 + iframe.src = browserElementTestHelpers.emptyPage1; 1.34 + document.body.appendChild(iframe); 1.35 +} 1.36 + 1.37 +function checkCanGoBackAndForward(canGoBack, canGoForward, nextTest) { 1.38 + var seenCanGoBackResult = false; 1.39 + iframe.getCanGoBack().onsuccess = function(e) { 1.40 + is(seenCanGoBackResult, false, "onsuccess handler shouldn't be called twice."); 1.41 + seenCanGoBackResult = true; 1.42 + is(e.target.result, canGoBack); 1.43 + maybeRunNextTest(); 1.44 + }; 1.45 + 1.46 + var seenCanGoForwardResult = false; 1.47 + iframe.getCanGoForward().onsuccess = function(e) { 1.48 + is(seenCanGoForwardResult, false, "onsuccess handler shouldn't be called twice."); 1.49 + seenCanGoForwardResult = true; 1.50 + is(e.target.result, canGoForward); 1.51 + maybeRunNextTest(); 1.52 + }; 1.53 + 1.54 + function maybeRunNextTest() { 1.55 + if (seenCanGoBackResult && seenCanGoForwardResult) { 1.56 + nextTest(); 1.57 + } 1.58 + } 1.59 +} 1.60 + 1.61 +function test2() { 1.62 + checkCanGoBackAndForward(false, false, test3); 1.63 +} 1.64 + 1.65 +function test3() { 1.66 + addOneShotIframeEventListener('mozbrowserloadend', function() { 1.67 + checkCanGoBackAndForward(true, false, test4); 1.68 + }); 1.69 + 1.70 + SimpleTest.executeSoon(function() { 1.71 + iframe.src = browserElementTestHelpers.emptyPage2; 1.72 + }); 1.73 +} 1.74 + 1.75 +function test4() { 1.76 + addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { 1.77 + is(e.detail, browserElementTestHelpers.emptyPage3); 1.78 + checkCanGoBackAndForward(true, false, test5); 1.79 + }); 1.80 + 1.81 + SimpleTest.executeSoon(function() { 1.82 + iframe.src = browserElementTestHelpers.emptyPage3; 1.83 + }); 1.84 +} 1.85 + 1.86 +function test5() { 1.87 + addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { 1.88 + is(e.detail, browserElementTestHelpers.emptyPage2); 1.89 + checkCanGoBackAndForward(true, true, test6); 1.90 + }); 1.91 + iframe.goBack(); 1.92 +} 1.93 + 1.94 +function test6() { 1.95 + addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { 1.96 + is(e.detail, browserElementTestHelpers.emptyPage1); 1.97 + checkCanGoBackAndForward(false, true, SimpleTest.finish); 1.98 + }); 1.99 + iframe.goBack(); 1.100 +} 1.101 + 1.102 +addEventListener('testready', runTest);