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