Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Test if DOMRequest returned by an iframe gets an error callback when
5 // the iframe is not in the DOM.
6 "use strict";
8 SimpleTest.waitForExplicitFinish();
9 browserElementTestHelpers.setEnabledPref(true);
10 browserElementTestHelpers.addPermission();
12 function runTest() {
13 var iframe1 = document.createElement('iframe');
14 SpecialPowers.wrap(iframe1).mozbrowser = true;
15 iframe1.src = 'data:text/html,<html>' +
16 '<body style="background:green">hello</body></html>';
17 document.body.appendChild(iframe1);
19 function testIframe(beforeRun, isErrorExpected, nextTest) {
20 return function() {
21 var error = false;
22 if (beforeRun)
23 beforeRun();
24 function testEnd() {
25 is(isErrorExpected, error);
26 SimpleTest.executeSoon(nextTest);
27 }
29 var domRequest = iframe1.getScreenshot(1000, 1000);
30 domRequest.onsuccess = function(e) {
31 testEnd();
32 }
33 domRequest.onerror = function(e) {
34 error = true;
35 testEnd();
36 }
37 };
38 }
40 function iframeLoadedHandler() {
41 iframe1.removeEventListener('mozbrowserloadend', iframeLoadedHandler);
42 // Test 1: iframe is in the DOM.
43 // Test 2: iframe is removed from the DOM.
44 // Test 3: iframe is added back into the DOM.
45 var test3 = testIframe(
46 function() {
47 document.body.appendChild(iframe1);
48 }, false,
49 function() {
50 SimpleTest.finish();
51 })
52 ;
53 var test2 = testIframe(function() {
54 document.body.removeChild(iframe1);
55 }, true, test3);
56 var test1 = testIframe(null, false, test2);
57 SimpleTest.executeSoon(test1);
58 }
60 iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler);
61 }
63 addEventListener('testready', runTest);