webapprt/test/chrome/browser_geolocation-prompt-perm.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 Cu.import("resource://gre/modules/Services.jsm");
michael@0 2
michael@0 3 function test() {
michael@0 4 waitForExplicitFinish();
michael@0 5
michael@0 6 let openedWindows = 0;
michael@0 7
michael@0 8 let winObserver = function(win, topic) {
michael@0 9 if (topic == "domwindowopened") {
michael@0 10 win.addEventListener("load", function onLoadWindow() {
michael@0 11 win.removeEventListener("load", onLoadWindow, false);
michael@0 12 openedWindows++;
michael@0 13 if (openedWindows == 2) {
michael@0 14 ok(true, "Prompt shown.");
michael@0 15 win.close();
michael@0 16 }
michael@0 17 }, false);
michael@0 18 }
michael@0 19 }
michael@0 20
michael@0 21 Services.ww.registerNotification(winObserver);
michael@0 22
michael@0 23 let mutObserver = null;
michael@0 24
michael@0 25 loadWebapp("geolocation-prompt-perm.webapp", undefined, function onLoad() {
michael@0 26 let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal;
michael@0 27 let permValue = Services.perms.testExactPermissionFromPrincipal(principal, "geolocation");
michael@0 28 is(permValue, Ci.nsIPermissionManager.PROMPT_ACTION, "Geolocation permission: prompt.");
michael@0 29
michael@0 30 let msg = gAppBrowser.contentDocument.getElementById("msg");
michael@0 31 mutObserver = new MutationObserver(function(mutations) {
michael@0 32 if (msg.textContent == "Failure.") {
michael@0 33 ok(true, "Permission not granted.");
michael@0 34 } else {
michael@0 35 ok(false, "Permission not granted.");
michael@0 36 }
michael@0 37
michael@0 38 if (openedWindows != 2) {
michael@0 39 ok(false, "Prompt not shown.");
michael@0 40 }
michael@0 41
michael@0 42 finish();
michael@0 43 });
michael@0 44 mutObserver.observe(msg, { childList: true });
michael@0 45 });
michael@0 46
michael@0 47 registerCleanupFunction(function() {
michael@0 48 Services.ww.unregisterNotification(winObserver);
michael@0 49 mutObserver.disconnect();
michael@0 50 });
michael@0 51 }

mercurial