Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Bug 807056 - [Browser] Clear History doesn't clear back/forward history in open tabs
5 // <iframe mozbrowser>.
7 "use strict";
8 SimpleTest.waitForExplicitFinish();
9 browserElementTestHelpers.setEnabledPref(true);
10 browserElementTestHelpers.addPermission();
12 var iframe;
13 function addOneShotIframeEventListener(event, fn) {
14 function wrapper(e) {
15 iframe.removeEventListener(event, wrapper);
16 fn(e);
17 };
19 iframe.addEventListener(event, wrapper);
20 }
22 function runTest() {
23 iframe = document.createElement('iframe');
24 SpecialPowers.wrap(iframe).mozbrowser = true;
26 addOneShotIframeEventListener('mozbrowserloadend', function() {
27 SimpleTest.executeSoon(test2);
28 });
30 iframe.src = browserElementTestHelpers.emptyPage1;
31 document.body.appendChild(iframe);
32 }
34 function purgeHistory(nextTest) {
35 var seenCanGoBackResult = false;
36 var seenCanGoForwardResult = false;
38 iframe.purgeHistory().onsuccess = function(e) {
39 ok(true, "The history has been purged");
41 iframe.getCanGoBack().onsuccess = function(e) {
42 is(e.target.result, false, "Iframe cannot go back");
43 seenCanGoBackResult = true;
44 maybeRunNextTest();
45 };
47 iframe.getCanGoForward().onsuccess = function(e) {
48 is(e.target.result, false, "Iframe cannot go forward");
49 seenCanGoForwardResult = true;
50 maybeRunNextTest();
51 };
52 };
54 function maybeRunNextTest() {
55 if (seenCanGoBackResult && seenCanGoForwardResult) {
56 nextTest();
57 }
58 }
59 }
61 function test2() {
62 purgeHistory(test3);
63 }
65 function test3() {
66 addOneShotIframeEventListener('mozbrowserloadend', function() {
67 purgeHistory(test4);
68 });
70 SimpleTest.executeSoon(function() {
71 iframe.src = browserElementTestHelpers.emptyPage2;
72 });
73 }
75 function test4() {
76 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) {
77 is(e.detail, browserElementTestHelpers.emptyPage3);
78 purgeHistory(SimpleTest.finish);
79 });
81 SimpleTest.executeSoon(function() {
82 iframe.src = browserElementTestHelpers.emptyPage3;
83 });
84 }
86 addEventListener('testready', runTest);