|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
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. |
|
6 |
|
7 "use strict"; |
|
8 SimpleTest.waitForExplicitFinish(); |
|
9 browserElementTestHelpers.setEnabledPref(true); |
|
10 browserElementTestHelpers.addPermission(); |
|
11 |
|
12 var iframe; |
|
13 var popupFrame; |
|
14 function runTest() { |
|
15 iframe = document.createElement('iframe'); |
|
16 SpecialPowers.wrap(iframe).mozbrowser = true; |
|
17 |
|
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'); |
|
24 |
|
25 // Called when file_browserElement_OpenNamed2.html loads into popupFrame. |
|
26 popupFrame.addEventListener('mozbrowsershowmodalprompt', function promptlistener(e) { |
|
27 popupFrame.removeEventListener('mozbrowsershowmodalprompt', promptlistener); |
|
28 |
|
29 ok(gotPopup, 'Got openwindow event before showmodalprompt event.'); |
|
30 is(e.detail.message, 'success: loaded'); |
|
31 SimpleTest.executeSoon(test2); |
|
32 }); |
|
33 |
|
34 document.body.appendChild(popupFrame); |
|
35 }); |
|
36 |
|
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 } |
|
47 |
|
48 function test2() { |
|
49 popupFrame.addEventListener('mozbrowsershowmodalprompt', function(e) { |
|
50 is(e.detail.message, 'success: loaded'); |
|
51 SimpleTest.finish(); |
|
52 }); |
|
53 |
|
54 iframe.src = 'file_browserElement_OpenNamed.html?test2'; |
|
55 } |
|
56 |
|
57 addEventListener('testready', runTest); |