Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the public domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Test if DOMRequest returned by an iframe gets an error callback when |
michael@0 | 5 | // the iframe is not in the DOM. |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 9 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 10 | browserElementTestHelpers.addPermission(); |
michael@0 | 11 | |
michael@0 | 12 | function runTest() { |
michael@0 | 13 | var iframe1 = document.createElement('iframe'); |
michael@0 | 14 | SpecialPowers.wrap(iframe1).mozbrowser = true; |
michael@0 | 15 | iframe1.src = 'data:text/html,<html>' + |
michael@0 | 16 | '<body style="background:green">hello</body></html>'; |
michael@0 | 17 | document.body.appendChild(iframe1); |
michael@0 | 18 | |
michael@0 | 19 | function testIframe(beforeRun, isErrorExpected, nextTest) { |
michael@0 | 20 | return function() { |
michael@0 | 21 | var error = false; |
michael@0 | 22 | if (beforeRun) |
michael@0 | 23 | beforeRun(); |
michael@0 | 24 | function testEnd() { |
michael@0 | 25 | is(isErrorExpected, error); |
michael@0 | 26 | SimpleTest.executeSoon(nextTest); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | var domRequest = iframe1.getScreenshot(1000, 1000); |
michael@0 | 30 | domRequest.onsuccess = function(e) { |
michael@0 | 31 | testEnd(); |
michael@0 | 32 | } |
michael@0 | 33 | domRequest.onerror = function(e) { |
michael@0 | 34 | error = true; |
michael@0 | 35 | testEnd(); |
michael@0 | 36 | } |
michael@0 | 37 | }; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function iframeLoadedHandler() { |
michael@0 | 41 | iframe1.removeEventListener('mozbrowserloadend', iframeLoadedHandler); |
michael@0 | 42 | // Test 1: iframe is in the DOM. |
michael@0 | 43 | // Test 2: iframe is removed from the DOM. |
michael@0 | 44 | // Test 3: iframe is added back into the DOM. |
michael@0 | 45 | var test3 = testIframe( |
michael@0 | 46 | function() { |
michael@0 | 47 | document.body.appendChild(iframe1); |
michael@0 | 48 | }, false, |
michael@0 | 49 | function() { |
michael@0 | 50 | SimpleTest.finish(); |
michael@0 | 51 | }) |
michael@0 | 52 | ; |
michael@0 | 53 | var test2 = testIframe(function() { |
michael@0 | 54 | document.body.removeChild(iframe1); |
michael@0 | 55 | }, true, test3); |
michael@0 | 56 | var test1 = testIframe(null, false, test2); |
michael@0 | 57 | SimpleTest.executeSoon(test1); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | addEventListener('testready', runTest); |