dom/browser-element/mochitest/browserElement_OpenNamed.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 - In <iframe mozbrowser>, test that if we call window.open twice
     5 // with the same name, we get only one mozbrowseropenwindow event.
     7 "use strict";
     8 SimpleTest.waitForExplicitFinish();
     9 browserElementTestHelpers.setEnabledPref(true);
    10 browserElementTestHelpers.addPermission();
    12 var iframe;
    13 var popupFrame;
    14 function runTest() {
    15   iframe = document.createElement('iframe');
    16   SpecialPowers.wrap(iframe).mozbrowser = true;
    18   var gotPopup = false;
    19   iframe.addEventListener('mozbrowseropenwindow', function(e) {
    20     is(gotPopup, false, 'Should get just one popup.');
    21     gotPopup = true;
    22     popupFrame = e.detail.frameElement;
    23     is(popupFrame.getAttribute('name'), 'OpenNamed');
    25     // Called when file_browserElement_OpenNamed2.html loads into popupFrame.
    26     popupFrame.addEventListener('mozbrowsershowmodalprompt', function promptlistener(e) {
    27       popupFrame.removeEventListener('mozbrowsershowmodalprompt', promptlistener);
    29       ok(gotPopup, 'Got openwindow event before showmodalprompt event.');
    30       is(e.detail.message, 'success: loaded');
    31       SimpleTest.executeSoon(test2);
    32     });
    34     document.body.appendChild(popupFrame);
    35   });
    37   // OpenNamed.html will call
    38   //
    39   //    window.open('file_browserElement_OpenNamed2.html', 'OpenNamed').
    40   //
    41   // Once that popup loads, we reload OpenNamed.html.  That will call
    42   // window.open again, but we shouldn't get another openwindow event, because
    43   // we're opening into the same named window.
    44   iframe.src = 'file_browserElement_OpenNamed.html';
    45   document.body.appendChild(iframe);
    46 }
    48 function test2() {
    49   popupFrame.addEventListener('mozbrowsershowmodalprompt', function(e) {
    50     is(e.detail.message, 'success: loaded');
    51     SimpleTest.finish();
    52   });
    54   iframe.src = 'file_browserElement_OpenNamed.html?test2';
    55 }
    57 addEventListener('testready', runTest);

mercurial