1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_DOMRequestError.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test if DOMRequest returned by an iframe gets an error callback when 1.8 +// the iframe is not in the DOM. 1.9 +"use strict"; 1.10 + 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +browserElementTestHelpers.setEnabledPref(true); 1.13 +browserElementTestHelpers.addPermission(); 1.14 + 1.15 +function runTest() { 1.16 + var iframe1 = document.createElement('iframe'); 1.17 + SpecialPowers.wrap(iframe1).mozbrowser = true; 1.18 + iframe1.src = 'data:text/html,<html>' + 1.19 + '<body style="background:green">hello</body></html>'; 1.20 + document.body.appendChild(iframe1); 1.21 + 1.22 + function testIframe(beforeRun, isErrorExpected, nextTest) { 1.23 + return function() { 1.24 + var error = false; 1.25 + if (beforeRun) 1.26 + beforeRun(); 1.27 + function testEnd() { 1.28 + is(isErrorExpected, error); 1.29 + SimpleTest.executeSoon(nextTest); 1.30 + } 1.31 + 1.32 + var domRequest = iframe1.getScreenshot(1000, 1000); 1.33 + domRequest.onsuccess = function(e) { 1.34 + testEnd(); 1.35 + } 1.36 + domRequest.onerror = function(e) { 1.37 + error = true; 1.38 + testEnd(); 1.39 + } 1.40 + }; 1.41 + } 1.42 + 1.43 + function iframeLoadedHandler() { 1.44 + iframe1.removeEventListener('mozbrowserloadend', iframeLoadedHandler); 1.45 + // Test 1: iframe is in the DOM. 1.46 + // Test 2: iframe is removed from the DOM. 1.47 + // Test 3: iframe is added back into the DOM. 1.48 + var test3 = testIframe( 1.49 + function() { 1.50 + document.body.appendChild(iframe1); 1.51 + }, false, 1.52 + function() { 1.53 + SimpleTest.finish(); 1.54 + }) 1.55 + ; 1.56 + var test2 = testIframe(function() { 1.57 + document.body.removeChild(iframe1); 1.58 + }, true, test3); 1.59 + var test1 = testIframe(null, false, test2); 1.60 + SimpleTest.executeSoon(test1); 1.61 + } 1.62 + 1.63 + iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler); 1.64 +} 1.65 + 1.66 +addEventListener('testready', runTest);