1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_OpenNamed.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 742944 - In <iframe mozbrowser>, test that if we call window.open twice 1.8 +// with the same name, we get only one mozbrowseropenwindow event. 1.9 + 1.10 +"use strict"; 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +browserElementTestHelpers.setEnabledPref(true); 1.13 +browserElementTestHelpers.addPermission(); 1.14 + 1.15 +var iframe; 1.16 +var popupFrame; 1.17 +function runTest() { 1.18 + iframe = document.createElement('iframe'); 1.19 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.20 + 1.21 + var gotPopup = false; 1.22 + iframe.addEventListener('mozbrowseropenwindow', function(e) { 1.23 + is(gotPopup, false, 'Should get just one popup.'); 1.24 + gotPopup = true; 1.25 + popupFrame = e.detail.frameElement; 1.26 + is(popupFrame.getAttribute('name'), 'OpenNamed'); 1.27 + 1.28 + // Called when file_browserElement_OpenNamed2.html loads into popupFrame. 1.29 + popupFrame.addEventListener('mozbrowsershowmodalprompt', function promptlistener(e) { 1.30 + popupFrame.removeEventListener('mozbrowsershowmodalprompt', promptlistener); 1.31 + 1.32 + ok(gotPopup, 'Got openwindow event before showmodalprompt event.'); 1.33 + is(e.detail.message, 'success: loaded'); 1.34 + SimpleTest.executeSoon(test2); 1.35 + }); 1.36 + 1.37 + document.body.appendChild(popupFrame); 1.38 + }); 1.39 + 1.40 + // OpenNamed.html will call 1.41 + // 1.42 + // window.open('file_browserElement_OpenNamed2.html', 'OpenNamed'). 1.43 + // 1.44 + // Once that popup loads, we reload OpenNamed.html. That will call 1.45 + // window.open again, but we shouldn't get another openwindow event, because 1.46 + // we're opening into the same named window. 1.47 + iframe.src = 'file_browserElement_OpenNamed.html'; 1.48 + document.body.appendChild(iframe); 1.49 +} 1.50 + 1.51 +function test2() { 1.52 + popupFrame.addEventListener('mozbrowsershowmodalprompt', function(e) { 1.53 + is(e.detail.message, 'success: loaded'); 1.54 + SimpleTest.finish(); 1.55 + }); 1.56 + 1.57 + iframe.src = 'file_browserElement_OpenNamed.html?test2'; 1.58 +} 1.59 + 1.60 +addEventListener('testready', runTest);