1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_Stop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 709759 - Test the stop ability of <iframe mozbrowser>. 1.8 + 1.9 +// The img that is loaded will never be returned and will block 1.10 +// the page from loading, the timeout ensures that the page is 1.11 +// actually blocked from loading, once stop is called the 1.12 +// image load will be cancaelled and mozbrowserloadend should be called. 1.13 + 1.14 +"use strict"; 1.15 +SimpleTest.waitForExplicitFinish(); 1.16 +browserElementTestHelpers.setEnabledPref(true); 1.17 +browserElementTestHelpers.addPermission(); 1.18 + 1.19 +var iframe; 1.20 +var stopped = false; 1.21 +var imgSrc = 'http://test/tests/dom/browser-element/mochitest/file_bug709759.sjs'; 1.22 + 1.23 +function runTest() { 1.24 + iframe = document.createElement('iframe'); 1.25 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.26 + 1.27 + iframe.addEventListener('mozbrowserloadend', loadend); 1.28 + iframe.src = 'data:text/html,<html>' + 1.29 + '<body><img src="' + imgSrc + '" /></body></html>'; 1.30 + 1.31 + document.body.appendChild(iframe); 1.32 + 1.33 + setTimeout(function() { 1.34 + stopped = true; 1.35 + iframe.stop(); 1.36 + }, 200); 1.37 +} 1.38 + 1.39 +function loadend() { 1.40 + ok(stopped, 'Iframes network connections were stopped'); 1.41 + 1.42 + // Wait 1 second and make sure there isn't a mozbrowsererror after stop(); 1.43 + iframe.addEventListener('mozbrowsererror', handleError); 1.44 + window.setTimeout(function() { 1.45 + iframe.removeEventListener('mozbrowsererror', handleError); 1.46 + SimpleTest.finish(); 1.47 + }, 1000); 1.48 +} 1.49 + 1.50 +function handleError() { 1.51 + ok(false, "mozbrowsererror should not be fired"); 1.52 +} 1.53 + 1.54 +addEventListener('testready', runTest);