dom/browser-element/mochitest/browserElement_Stop.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Bug 709759 - Test the stop ability of <iframe mozbrowser>.
     6 // The img that is loaded will never be returned and will block
     7 // the page from loading, the timeout ensures that the page is
     8 // actually blocked from loading, once stop is called the
     9 // image load will be cancaelled and mozbrowserloadend should be called.
    11 "use strict";
    12 SimpleTest.waitForExplicitFinish();
    13 browserElementTestHelpers.setEnabledPref(true);
    14 browserElementTestHelpers.addPermission();
    16 var iframe;
    17 var stopped = false;
    18 var imgSrc = 'http://test/tests/dom/browser-element/mochitest/file_bug709759.sjs';
    20 function runTest() {
    21   iframe = document.createElement('iframe');
    22   SpecialPowers.wrap(iframe).mozbrowser = true;
    24   iframe.addEventListener('mozbrowserloadend', loadend);
    25   iframe.src = 'data:text/html,<html>' +
    26     '<body><img src="' + imgSrc + '" /></body></html>';
    28   document.body.appendChild(iframe);
    30   setTimeout(function() {
    31     stopped = true;
    32     iframe.stop();
    33   }, 200);
    34 }
    36 function loadend() {
    37   ok(stopped, 'Iframes network connections were stopped');
    39   // Wait 1 second and make sure there isn't a mozbrowsererror after stop();
    40   iframe.addEventListener('mozbrowsererror', handleError);
    41   window.setTimeout(function() {
    42     iframe.removeEventListener('mozbrowsererror', handleError);
    43     SimpleTest.finish();
    44   }, 1000);
    45 }
    47 function handleError() {
    48   ok(false, "mozbrowsererror should not be fired");
    49 }
    51 addEventListener('testready', runTest);

mercurial