|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Bug 829486 - Add mozdocumentbrowserfirstpaint event. |
|
5 "use strict"; |
|
6 |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 var iframe; |
|
12 |
|
13 function runTestQueue(queue) { |
|
14 if (queue.length == 0) { |
|
15 SimpleTest.finish(); |
|
16 return; |
|
17 } |
|
18 |
|
19 var gotFirstPaint = false; |
|
20 var gotFirstLocationChange = false; |
|
21 var test = queue.shift(); |
|
22 |
|
23 function runNext() { |
|
24 iframe.removeEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler); |
|
25 iframe.removeEventListener('mozbrowserloadend', loadendhandler); |
|
26 runTestQueue(queue); |
|
27 } |
|
28 |
|
29 function documentfirstpainthandler(e) { |
|
30 ok(!gotFirstPaint, "Got firstpaint only once"); |
|
31 gotFirstPaint = true; |
|
32 if (gotFirstLocationChange) { |
|
33 runNext(); |
|
34 } |
|
35 } |
|
36 |
|
37 function loadendhandler(e) { |
|
38 gotFirstLocationChange = true; |
|
39 if (gotFirstPaint) { |
|
40 runNext(); |
|
41 } |
|
42 } |
|
43 |
|
44 iframe.addEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler); |
|
45 iframe.addEventListener('mozbrowserloadend', loadendhandler); |
|
46 |
|
47 test(); |
|
48 } |
|
49 |
|
50 function testChangeLocation() { |
|
51 iframe.src = browserElementTestHelpers.emptyPage1 + "?2"; |
|
52 } |
|
53 |
|
54 function testReload() { |
|
55 iframe.reload(); |
|
56 } |
|
57 |
|
58 function testFirstLoad() { |
|
59 document.body.appendChild(iframe); |
|
60 iframe.src = browserElementTestHelpers.emptyPage1; |
|
61 } |
|
62 |
|
63 function runTest() { |
|
64 iframe = document.createElement('iframe'); |
|
65 SpecialPowers.wrap(iframe).mozbrowser = true; |
|
66 |
|
67 runTestQueue([testFirstLoad, testReload, testChangeLocation]); |
|
68 } |
|
69 |
|
70 addEventListener('testready', runTest); |