Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Bug 789392 - Test that apps frames can trigger mozbrowserclose by calling
5 // window.close(), but browser frames cannot.
6 "use strict";
8 SimpleTest.waitForExplicitFinish();
9 browserElementTestHelpers.setEnabledPref(true);
10 browserElementTestHelpers.addPermission();
11 SpecialPowers.addPermission("embed-apps", true, window.document);
13 addEventListener('unload', function() {
14 SpecialPowers.removePermission("embed-apps", window.document);
15 });
17 function runTest() {
18 // Our app frame and browser frame load the same content. That content calls
19 // window.close() and then alert(). We should get a mozbrowserclose event on
20 // the app frame before the mozbrowsershowmodalprompt, but not on the browser
21 // frame.
23 var appFrame = document.createElement('iframe');
24 SpecialPowers.wrap(appFrame).mozbrowser = true;
25 appFrame.setAttribute('mozapp', 'http://example.org/manifest.webapp');
27 var browserFrame = document.createElement('iframe');
28 SpecialPowers.wrap(browserFrame).mozbrowser = true;
30 var gotAppFrameClose = false;
31 appFrame.addEventListener('mozbrowserclose', function() {
32 ok(true, "Got close from app frame.");
33 gotAppFrameClose = true;
34 });
36 var gotAppFrameAlert = false;
37 appFrame.addEventListener('mozbrowsershowmodalprompt', function() {
38 ok(gotAppFrameClose, "Should have gotten app frame close by now.");
39 ok(!gotAppFrameAlert, "Just one alert from the app frame.");
40 gotAppFrameAlert = true;
41 if (gotBrowserFrameAlert && gotAppFrameAlert) {
42 SimpleTest.finish();
43 }
44 });
46 browserFrame.addEventListener('mozbrowserclose', function() {
47 ok(false, "Got close from browser frame.");
48 });
50 var gotBrowserFrameAlert = false;
51 browserFrame.addEventListener('mozbrowsershowmodalprompt', function() {
52 ok(!gotBrowserFrameAlert, "Just one browser frame alert.");
53 gotBrowserFrameAlert = true;
54 if (gotBrowserFrameAlert && gotAppFrameAlert) {
55 SimpleTest.finish();
56 }
57 });
59 document.body.appendChild(appFrame);
60 document.body.appendChild(browserFrame);
62 appFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html';
63 browserFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html';
64 }
66 // The test harness sets dom.allow_scripts_to_close_windows to true (as of
67 // writing, anyway). But that means that browser tabs can close themselves,
68 // which is what we want to test /can't/ happen! For the purposes of this
69 // test (and normal browser operation), this pref should be false.
70 addEventListener('testready', function() {
71 SpecialPowers.pushPrefEnv({'set': [['dom.allow_scripts_to_close_windows', false]]}, runTest);
72 });