dom/browser-element/mochitest/browserElement_BackForward.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the public domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Bug 741755 - Test that canGo{Back,Forward} and go{Forward,Back} work with
michael@0 5 // <iframe mozbrowser>.
michael@0 6
michael@0 7 "use strict";
michael@0 8 SimpleTest.waitForExplicitFinish();
michael@0 9 browserElementTestHelpers.setEnabledPref(true);
michael@0 10 browserElementTestHelpers.addPermission();
michael@0 11
michael@0 12 var iframe;
michael@0 13 function addOneShotIframeEventListener(event, fn) {
michael@0 14 function wrapper(e) {
michael@0 15 iframe.removeEventListener(event, wrapper);
michael@0 16 fn(e);
michael@0 17 };
michael@0 18
michael@0 19 iframe.addEventListener(event, wrapper);
michael@0 20 }
michael@0 21
michael@0 22 function runTest() {
michael@0 23 iframe = document.createElement('iframe');
michael@0 24 SpecialPowers.wrap(iframe).mozbrowser = true;
michael@0 25
michael@0 26 addOneShotIframeEventListener('mozbrowserloadend', function() {
michael@0 27 SimpleTest.executeSoon(test2);
michael@0 28 });
michael@0 29
michael@0 30 iframe.src = browserElementTestHelpers.emptyPage1;
michael@0 31 document.body.appendChild(iframe);
michael@0 32 }
michael@0 33
michael@0 34 function checkCanGoBackAndForward(canGoBack, canGoForward, nextTest) {
michael@0 35 var seenCanGoBackResult = false;
michael@0 36 iframe.getCanGoBack().onsuccess = function(e) {
michael@0 37 is(seenCanGoBackResult, false, "onsuccess handler shouldn't be called twice.");
michael@0 38 seenCanGoBackResult = true;
michael@0 39 is(e.target.result, canGoBack);
michael@0 40 maybeRunNextTest();
michael@0 41 };
michael@0 42
michael@0 43 var seenCanGoForwardResult = false;
michael@0 44 iframe.getCanGoForward().onsuccess = function(e) {
michael@0 45 is(seenCanGoForwardResult, false, "onsuccess handler shouldn't be called twice.");
michael@0 46 seenCanGoForwardResult = true;
michael@0 47 is(e.target.result, canGoForward);
michael@0 48 maybeRunNextTest();
michael@0 49 };
michael@0 50
michael@0 51 function maybeRunNextTest() {
michael@0 52 if (seenCanGoBackResult && seenCanGoForwardResult) {
michael@0 53 nextTest();
michael@0 54 }
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 function test2() {
michael@0 59 checkCanGoBackAndForward(false, false, test3);
michael@0 60 }
michael@0 61
michael@0 62 function test3() {
michael@0 63 addOneShotIframeEventListener('mozbrowserloadend', function() {
michael@0 64 checkCanGoBackAndForward(true, false, test4);
michael@0 65 });
michael@0 66
michael@0 67 SimpleTest.executeSoon(function() {
michael@0 68 iframe.src = browserElementTestHelpers.emptyPage2;
michael@0 69 });
michael@0 70 }
michael@0 71
michael@0 72 function test4() {
michael@0 73 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
michael@0 74 is(e.detail, browserElementTestHelpers.emptyPage3);
michael@0 75 checkCanGoBackAndForward(true, false, test5);
michael@0 76 });
michael@0 77
michael@0 78 SimpleTest.executeSoon(function() {
michael@0 79 iframe.src = browserElementTestHelpers.emptyPage3;
michael@0 80 });
michael@0 81 }
michael@0 82
michael@0 83 function test5() {
michael@0 84 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
michael@0 85 is(e.detail, browserElementTestHelpers.emptyPage2);
michael@0 86 checkCanGoBackAndForward(true, true, test6);
michael@0 87 });
michael@0 88 iframe.goBack();
michael@0 89 }
michael@0 90
michael@0 91 function test6() {
michael@0 92 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
michael@0 93 is(e.detail, browserElementTestHelpers.emptyPage1);
michael@0 94 checkCanGoBackAndForward(false, true, SimpleTest.finish);
michael@0 95 });
michael@0 96 iframe.goBack();
michael@0 97 }
michael@0 98
michael@0 99 addEventListener('testready', runTest);

mercurial