|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Bug 741755 - Test that canGo{Back,Forward} and go{Forward,Back} work with |
|
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 checkCanGoBackAndForward(canGoBack, canGoForward, nextTest) { |
|
35 var seenCanGoBackResult = false; |
|
36 iframe.getCanGoBack().onsuccess = function(e) { |
|
37 is(seenCanGoBackResult, false, "onsuccess handler shouldn't be called twice."); |
|
38 seenCanGoBackResult = true; |
|
39 is(e.target.result, canGoBack); |
|
40 maybeRunNextTest(); |
|
41 }; |
|
42 |
|
43 var seenCanGoForwardResult = false; |
|
44 iframe.getCanGoForward().onsuccess = function(e) { |
|
45 is(seenCanGoForwardResult, false, "onsuccess handler shouldn't be called twice."); |
|
46 seenCanGoForwardResult = true; |
|
47 is(e.target.result, canGoForward); |
|
48 maybeRunNextTest(); |
|
49 }; |
|
50 |
|
51 function maybeRunNextTest() { |
|
52 if (seenCanGoBackResult && seenCanGoForwardResult) { |
|
53 nextTest(); |
|
54 } |
|
55 } |
|
56 } |
|
57 |
|
58 function test2() { |
|
59 checkCanGoBackAndForward(false, false, test3); |
|
60 } |
|
61 |
|
62 function test3() { |
|
63 addOneShotIframeEventListener('mozbrowserloadend', function() { |
|
64 checkCanGoBackAndForward(true, false, test4); |
|
65 }); |
|
66 |
|
67 SimpleTest.executeSoon(function() { |
|
68 iframe.src = browserElementTestHelpers.emptyPage2; |
|
69 }); |
|
70 } |
|
71 |
|
72 function test4() { |
|
73 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { |
|
74 is(e.detail, browserElementTestHelpers.emptyPage3); |
|
75 checkCanGoBackAndForward(true, false, test5); |
|
76 }); |
|
77 |
|
78 SimpleTest.executeSoon(function() { |
|
79 iframe.src = browserElementTestHelpers.emptyPage3; |
|
80 }); |
|
81 } |
|
82 |
|
83 function test5() { |
|
84 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { |
|
85 is(e.detail, browserElementTestHelpers.emptyPage2); |
|
86 checkCanGoBackAndForward(true, true, test6); |
|
87 }); |
|
88 iframe.goBack(); |
|
89 } |
|
90 |
|
91 function test6() { |
|
92 addOneShotIframeEventListener('mozbrowserlocationchange', function(e) { |
|
93 is(e.detail, browserElementTestHelpers.emptyPage1); |
|
94 checkCanGoBackAndForward(false, true, SimpleTest.finish); |
|
95 }); |
|
96 iframe.goBack(); |
|
97 } |
|
98 |
|
99 addEventListener('testready', runTest); |