Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the public domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Bug 789392 - Test that apps frames can trigger mozbrowserclose by calling |
michael@0 | 5 | // window.close(), but browser frames cannot. |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 9 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 10 | browserElementTestHelpers.addPermission(); |
michael@0 | 11 | SpecialPowers.addPermission("embed-apps", true, window.document); |
michael@0 | 12 | |
michael@0 | 13 | addEventListener('unload', function() { |
michael@0 | 14 | SpecialPowers.removePermission("embed-apps", window.document); |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | function runTest() { |
michael@0 | 18 | // Our app frame and browser frame load the same content. That content calls |
michael@0 | 19 | // window.close() and then alert(). We should get a mozbrowserclose event on |
michael@0 | 20 | // the app frame before the mozbrowsershowmodalprompt, but not on the browser |
michael@0 | 21 | // frame. |
michael@0 | 22 | |
michael@0 | 23 | var appFrame = document.createElement('iframe'); |
michael@0 | 24 | SpecialPowers.wrap(appFrame).mozbrowser = true; |
michael@0 | 25 | appFrame.setAttribute('mozapp', 'http://example.org/manifest.webapp'); |
michael@0 | 26 | |
michael@0 | 27 | var browserFrame = document.createElement('iframe'); |
michael@0 | 28 | SpecialPowers.wrap(browserFrame).mozbrowser = true; |
michael@0 | 29 | |
michael@0 | 30 | var gotAppFrameClose = false; |
michael@0 | 31 | appFrame.addEventListener('mozbrowserclose', function() { |
michael@0 | 32 | ok(true, "Got close from app frame."); |
michael@0 | 33 | gotAppFrameClose = true; |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | var gotAppFrameAlert = false; |
michael@0 | 37 | appFrame.addEventListener('mozbrowsershowmodalprompt', function() { |
michael@0 | 38 | ok(gotAppFrameClose, "Should have gotten app frame close by now."); |
michael@0 | 39 | ok(!gotAppFrameAlert, "Just one alert from the app frame."); |
michael@0 | 40 | gotAppFrameAlert = true; |
michael@0 | 41 | if (gotBrowserFrameAlert && gotAppFrameAlert) { |
michael@0 | 42 | SimpleTest.finish(); |
michael@0 | 43 | } |
michael@0 | 44 | }); |
michael@0 | 45 | |
michael@0 | 46 | browserFrame.addEventListener('mozbrowserclose', function() { |
michael@0 | 47 | ok(false, "Got close from browser frame."); |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | var gotBrowserFrameAlert = false; |
michael@0 | 51 | browserFrame.addEventListener('mozbrowsershowmodalprompt', function() { |
michael@0 | 52 | ok(!gotBrowserFrameAlert, "Just one browser frame alert."); |
michael@0 | 53 | gotBrowserFrameAlert = true; |
michael@0 | 54 | if (gotBrowserFrameAlert && gotAppFrameAlert) { |
michael@0 | 55 | SimpleTest.finish(); |
michael@0 | 56 | } |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | document.body.appendChild(appFrame); |
michael@0 | 60 | document.body.appendChild(browserFrame); |
michael@0 | 61 | |
michael@0 | 62 | appFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html'; |
michael@0 | 63 | browserFrame.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_CloseApp.html'; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // The test harness sets dom.allow_scripts_to_close_windows to true (as of |
michael@0 | 67 | // writing, anyway). But that means that browser tabs can close themselves, |
michael@0 | 68 | // which is what we want to test /can't/ happen! For the purposes of this |
michael@0 | 69 | // test (and normal browser operation), this pref should be false. |
michael@0 | 70 | addEventListener('testready', function() { |
michael@0 | 71 | SpecialPowers.pushPrefEnv({'set': [['dom.allow_scripts_to_close_windows', false]]}, runTest); |
michael@0 | 72 | }); |