Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 807056 - [Browser] Clear History doesn't clear back/forward history in open tabs |
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 purgeHistory(nextTest) { |
michael@0 | 35 | var seenCanGoBackResult = false; |
michael@0 | 36 | var seenCanGoForwardResult = false; |
michael@0 | 37 | |
michael@0 | 38 | iframe.purgeHistory().onsuccess = function(e) { |
michael@0 | 39 | ok(true, "The history has been purged"); |
michael@0 | 40 | |
michael@0 | 41 | iframe.getCanGoBack().onsuccess = function(e) { |
michael@0 | 42 | is(e.target.result, false, "Iframe cannot go back"); |
michael@0 | 43 | seenCanGoBackResult = true; |
michael@0 | 44 | maybeRunNextTest(); |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | iframe.getCanGoForward().onsuccess = function(e) { |
michael@0 | 48 | is(e.target.result, false, "Iframe cannot go forward"); |
michael@0 | 49 | seenCanGoForwardResult = true; |
michael@0 | 50 | maybeRunNextTest(); |
michael@0 | 51 | }; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | function maybeRunNextTest() { |
michael@0 | 55 | if (seenCanGoBackResult && seenCanGoForwardResult) { |
michael@0 | 56 | nextTest(); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function test2() { |
michael@0 | 62 | purgeHistory(test3); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function test3() { |
michael@0 | 66 | addOneShotIframeEventListener('mozbrowserloadend', function() { |
michael@0 | 67 | purgeHistory(test4); |
michael@0 | 68 | }); |
michael@0 | 69 | |
michael@0 | 70 | SimpleTest.executeSoon(function() { |
michael@0 | 71 | iframe.src = browserElementTestHelpers.emptyPage2; |
michael@0 | 72 | }); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function test4() { |
michael@0 | 76 | addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { |
michael@0 | 77 | is(e.detail, browserElementTestHelpers.emptyPage3); |
michael@0 | 78 | purgeHistory(SimpleTest.finish); |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | SimpleTest.executeSoon(function() { |
michael@0 | 82 | iframe.src = browserElementTestHelpers.emptyPage3; |
michael@0 | 83 | }); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | addEventListener('testready', runTest); |