1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_PurgeHistory.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 807056 - [Browser] Clear History doesn't clear back/forward history in open tabs 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 purgeHistory(nextTest) { 1.38 + var seenCanGoBackResult = false; 1.39 + var seenCanGoForwardResult = false; 1.40 + 1.41 + iframe.purgeHistory().onsuccess = function(e) { 1.42 + ok(true, "The history has been purged"); 1.43 + 1.44 + iframe.getCanGoBack().onsuccess = function(e) { 1.45 + is(e.target.result, false, "Iframe cannot go back"); 1.46 + seenCanGoBackResult = true; 1.47 + maybeRunNextTest(); 1.48 + }; 1.49 + 1.50 + iframe.getCanGoForward().onsuccess = function(e) { 1.51 + is(e.target.result, false, "Iframe cannot go forward"); 1.52 + seenCanGoForwardResult = true; 1.53 + maybeRunNextTest(); 1.54 + }; 1.55 + }; 1.56 + 1.57 + function maybeRunNextTest() { 1.58 + if (seenCanGoBackResult && seenCanGoForwardResult) { 1.59 + nextTest(); 1.60 + } 1.61 + } 1.62 +} 1.63 + 1.64 +function test2() { 1.65 + purgeHistory(test3); 1.66 +} 1.67 + 1.68 +function test3() { 1.69 + addOneShotIframeEventListener('mozbrowserloadend', function() { 1.70 + purgeHistory(test4); 1.71 + }); 1.72 + 1.73 + SimpleTest.executeSoon(function() { 1.74 + iframe.src = browserElementTestHelpers.emptyPage2; 1.75 + }); 1.76 +} 1.77 + 1.78 +function test4() { 1.79 + addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { 1.80 + is(e.detail, browserElementTestHelpers.emptyPage3); 1.81 + purgeHistory(SimpleTest.finish); 1.82 + }); 1.83 + 1.84 + SimpleTest.executeSoon(function() { 1.85 + iframe.src = browserElementTestHelpers.emptyPage3; 1.86 + }); 1.87 +} 1.88 + 1.89 +addEventListener('testready', runTest);