michael@0: /* Any copyright is dedicated to the public domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Bug 789392 - Test that apps frames can trigger mozbrowserclose by calling michael@0: // window.close(), but browser frames cannot. michael@0: "use strict"; michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: browserElementTestHelpers.setEnabledPref(true); michael@0: browserElementTestHelpers.addPermission(); michael@0: SpecialPowers.addPermission("embed-apps", true, window.document); michael@0: michael@0: addEventListener('unload', function() { michael@0: SpecialPowers.removePermission("embed-apps", window.document); michael@0: }); michael@0: michael@0: function runTest() { michael@0: // Our app frame and browser frame load the same content. That content calls michael@0: // window.close() and then alert(). We should get a mozbrowserclose event on michael@0: // the app frame before the mozbrowsershowmodalprompt, but not on the browser michael@0: // frame. michael@0: michael@0: var appFrame = document.createElement('iframe'); michael@0: SpecialPowers.wrap(appFrame).mozbrowser = true; michael@0: appFrame.setAttribute('mozapp', 'http://example.org/manifest.webapp'); michael@0: michael@0: var browserFrame = document.createElement('iframe'); michael@0: SpecialPowers.wrap(browserFrame).mozbrowser = true; michael@0: michael@0: var gotAppFrameClose = false; michael@0: appFrame.addEventListener('mozbrowserclose', function() { michael@0: ok(true, "Got close from app frame."); michael@0: gotAppFrameClose = true; michael@0: }); michael@0: michael@0: var gotAppFrameAlert = false; michael@0: appFrame.addEventListener('mozbrowsershowmodalprompt', function() { michael@0: ok(gotAppFrameClose, "Should have gotten app frame close by now."); michael@0: ok(!gotAppFrameAlert, "Just one alert from the app frame."); michael@0: gotAppFrameAlert = true; michael@0: if (gotBrowserFrameAlert && gotAppFrameAlert) { michael@0: SimpleTest.finish(); michael@0: } michael@0: }); michael@0: michael@0: browserFrame.addEventListener('mozbrowserclose', function() { michael@0: ok(false, "Got close from browser frame."); michael@0: }); michael@0: michael@0: var gotBrowserFrameAlert = false; michael@0: browserFrame.addEventListener('mozbrowsershowmodalprompt', function() { michael@0: ok(!gotBrowserFrameAlert, "Just one browser frame alert."); michael@0: gotBrowserFrameAlert = true; michael@0: if (gotBrowserFrameAlert && gotAppFrameAlert) { michael@0: SimpleTest.finish(); michael@0: } michael@0: }); michael@0: michael@0: document.body.appendChild(appFrame); michael@0: document.body.appendChild(browserFrame); michael@0: michael@0: appFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html'; michael@0: browserFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html'; michael@0: } michael@0: michael@0: // The test harness sets dom.allow_scripts_to_close_windows to true (as of michael@0: // writing, anyway). But that means that browser tabs can close themselves, michael@0: // which is what we want to test /can't/ happen! For the purposes of this michael@0: // test (and normal browser operation), this pref should be false. michael@0: addEventListener('testready', function() { michael@0: SpecialPowers.pushPrefEnv({'set': [['dom.allow_scripts_to_close_windows', false]]}, runTest); michael@0: });