Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 | // Bug 709759 - Test the stop ability of <iframe mozbrowser>. |
michael@0 | 5 | |
michael@0 | 6 | // The img that is loaded will never be returned and will block |
michael@0 | 7 | // the page from loading, the timeout ensures that the page is |
michael@0 | 8 | // actually blocked from loading, once stop is called the |
michael@0 | 9 | // image load will be cancaelled and mozbrowserloadend should be called. |
michael@0 | 10 | |
michael@0 | 11 | "use strict"; |
michael@0 | 12 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 13 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 14 | browserElementTestHelpers.addPermission(); |
michael@0 | 15 | |
michael@0 | 16 | var iframe; |
michael@0 | 17 | var stopped = false; |
michael@0 | 18 | var imgSrc = 'http://test/tests/dom/browser-element/mochitest/file_bug709759.sjs'; |
michael@0 | 19 | |
michael@0 | 20 | function runTest() { |
michael@0 | 21 | iframe = document.createElement('iframe'); |
michael@0 | 22 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 23 | |
michael@0 | 24 | iframe.addEventListener('mozbrowserloadend', loadend); |
michael@0 | 25 | iframe.src = 'data:text/html,<html>' + |
michael@0 | 26 | '<body><img src="' + imgSrc + '" /></body></html>'; |
michael@0 | 27 | |
michael@0 | 28 | document.body.appendChild(iframe); |
michael@0 | 29 | |
michael@0 | 30 | setTimeout(function() { |
michael@0 | 31 | stopped = true; |
michael@0 | 32 | iframe.stop(); |
michael@0 | 33 | }, 200); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function loadend() { |
michael@0 | 37 | ok(stopped, 'Iframes network connections were stopped'); |
michael@0 | 38 | |
michael@0 | 39 | // Wait 1 second and make sure there isn't a mozbrowsererror after stop(); |
michael@0 | 40 | iframe.addEventListener('mozbrowsererror', handleError); |
michael@0 | 41 | window.setTimeout(function() { |
michael@0 | 42 | iframe.removeEventListener('mozbrowsererror', handleError); |
michael@0 | 43 | SimpleTest.finish(); |
michael@0 | 44 | }, 1000); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function handleError() { |
michael@0 | 48 | ok(false, "mozbrowsererror should not be fired"); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | addEventListener('testready', runTest); |