|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Bug 742944 - Test that window.open works with <iframe mozbrowser>. |
|
5 |
|
6 "use strict"; |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 function runTest() { |
|
12 var iframe = document.createElement('iframe'); |
|
13 SpecialPowers.wrap(iframe).mozbrowser = true; |
|
14 |
|
15 var gotPopup = false; |
|
16 iframe.addEventListener('mozbrowseropenwindow', function(e) { |
|
17 is(gotPopup, false, 'Should get just one popup.'); |
|
18 gotPopup = true; |
|
19 |
|
20 document.body.appendChild(e.detail.frameElement); |
|
21 |
|
22 ok(/file_browserElement_Open2\.html$/.test(e.detail.url), |
|
23 "Popup's URL (got " + e.detail.url + ")"); |
|
24 is(e.detail.name, "name"); |
|
25 is(e.detail.features, "dialog=1"); |
|
26 }); |
|
27 |
|
28 iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { |
|
29 ok(gotPopup, 'Got mozbrowseropenwindow event before showmodalprompt event.'); |
|
30 if (e.detail.message.indexOf("success:") == 0) { |
|
31 ok(true, e.detail.message); |
|
32 } |
|
33 else if (e.detail.message.indexOf("failure:") == 0) { |
|
34 ok(false, e.detail.message); |
|
35 } |
|
36 else if (e.detail.message == "finish") { |
|
37 SimpleTest.finish(); |
|
38 } |
|
39 else { |
|
40 ok(false, "Got invalid message: " + e.detail.message); |
|
41 } |
|
42 }); |
|
43 |
|
44 /** |
|
45 * file_browserElementOpen1 does |
|
46 * |
|
47 * window.open('file_browserElement_Open2.html', 'name', 'dialog=1') |
|
48 * |
|
49 * then adds an event listener to the opened window and waits for onload. |
|
50 * |
|
51 * Onload, we fire a few alerts saying "success:REASON" or "failure:REASON". |
|
52 * Finally, we fire a "finish" alert, which ends the test. |
|
53 */ |
|
54 iframe.src = 'file_browserElement_Open1.html'; |
|
55 document.body.appendChild(iframe); |
|
56 } |
|
57 |
|
58 addEventListener('testready', runTest); |