|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that data: URIs work with mozbrowserlocationchange events. |
|
5 |
|
6 "use strict"; |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 function runTest() { |
|
12 var iframe1 = document.createElement('iframe'); |
|
13 SpecialPowers.wrap(iframe1).mozbrowser = true; |
|
14 iframe1.id = 'iframe1'; |
|
15 iframe1.addEventListener('mozbrowserloadend', function if1_loadend() { |
|
16 iframe1.removeEventListener('mozbrowserloadend', if1_loadend); |
|
17 ok(true, 'Got first loadend event.'); |
|
18 SimpleTest.executeSoon(runTest2); |
|
19 }); |
|
20 iframe1.src = browserElementTestHelpers.emptyPage1; |
|
21 document.body.appendChild(iframe1); |
|
22 |
|
23 var iframe2 = document.createElement('iframe'); |
|
24 iframe2.id = 'iframe2'; |
|
25 document.body.appendChild(iframe2); |
|
26 } |
|
27 |
|
28 function runTest2() { |
|
29 var iframe1 = document.getElementById('iframe1'); |
|
30 var iframe2 = document.getElementById('iframe2'); |
|
31 |
|
32 var sawLoadEnd = false; |
|
33 var sawLocationChange = false; |
|
34 |
|
35 iframe1.addEventListener('mozbrowserlocationchange', function(e) { |
|
36 ok(e.isTrusted, 'Event should be trusted.'); |
|
37 ok(!sawLocationChange, 'Just one locationchange event.'); |
|
38 ok(!sawLoadEnd, 'locationchange before load.'); |
|
39 is(e.detail, 'data:text/html,1', "event's reported location"); |
|
40 sawLocationChange = true; |
|
41 }); |
|
42 |
|
43 iframe1.addEventListener('mozbrowserloadend', function() { |
|
44 ok(sawLocationChange, 'Loadend after locationchange.'); |
|
45 ok(!sawLoadEnd, 'Just one loadend event.'); |
|
46 sawLoadEnd = true; |
|
47 }); |
|
48 |
|
49 function iframe2Load() { |
|
50 if (!sawLoadEnd || !sawLocationChange) { |
|
51 // Spin if iframe1 hasn't loaded yet. |
|
52 SimpleTest.executeSoon(iframe2Load); |
|
53 return; |
|
54 } |
|
55 ok(true, 'Got iframe2 load.'); |
|
56 SimpleTest.finish(); |
|
57 } |
|
58 iframe2.addEventListener('load', iframe2Load); |
|
59 |
|
60 |
|
61 iframe1.src = 'data:text/html,1'; |
|
62 |
|
63 // Load something into iframe2 to check that it doesn't trigger a |
|
64 // locationchange for our iframe1 listener. |
|
65 iframe2.src = browserElementTestHelpers.emptyPage2; |
|
66 } |
|
67 |
|
68 addEventListener('testready', runTest); |