dom/browser-element/mochitest/browserElement_OpenWindowRejected2.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Bug 742944 - Do window.open from inside <iframe mozbrowser>.  But then
     5 // reject the call.  This shouldn't cause problems (crashes, leaks).
     6 //
     7 // This is the same as OpenWindowRejected, except we "reject" the popup by not
     8 // adding the iframe element to our DOM, instead of by not calling
     9 // preventDefault() on the event.
    11 "use strict";
    12 SimpleTest.waitForExplicitFinish();
    13 browserElementTestHelpers.setEnabledPref(true);
    14 browserElementTestHelpers.addPermission();
    16 function runTest() {
    17   var iframe = document.createElement('iframe');
    18   SpecialPowers.wrap(iframe).mozbrowser = true;
    20   iframe.addEventListener('mozbrowseropenwindow', function(e) {
    21     ok(e.detail.url.indexOf('does_not_exist.html') != -1,
    22        'Opened URL; got ' + e.detail.url);
    23     is(e.detail.name, '');
    24     is(e.detail.features, '');
    26     // Call preventDefault, but don't add the iframe to the DOM.  This still
    27     // amounts to rejecting the popup.
    28     e.preventDefault();
    29   });
    31   iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
    32     var msg = e.detail.message;
    33     if (msg.indexOf('success:') == 0) {
    34       ok(true, msg);
    35     }
    36     else if (msg == 'finish') {
    37       SimpleTest.finish();
    38     }
    39     else {
    40       ok(false, msg);
    41     }
    42   });
    44   iframe.src = 'file_browserElement_OpenWindowRejected.html';
    45 }
    47 addEventListener('testready', runTest);

mercurial