1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/webapprt/test/chrome/browser_geolocation-prompt-perm.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +Cu.import("resource://gre/modules/Services.jsm"); 1.5 + 1.6 +function test() { 1.7 + waitForExplicitFinish(); 1.8 + 1.9 + let openedWindows = 0; 1.10 + 1.11 + let winObserver = function(win, topic) { 1.12 + if (topic == "domwindowopened") { 1.13 + win.addEventListener("load", function onLoadWindow() { 1.14 + win.removeEventListener("load", onLoadWindow, false); 1.15 + openedWindows++; 1.16 + if (openedWindows == 2) { 1.17 + ok(true, "Prompt shown."); 1.18 + win.close(); 1.19 + } 1.20 + }, false); 1.21 + } 1.22 + } 1.23 + 1.24 + Services.ww.registerNotification(winObserver); 1.25 + 1.26 + let mutObserver = null; 1.27 + 1.28 + loadWebapp("geolocation-prompt-perm.webapp", undefined, function onLoad() { 1.29 + let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal; 1.30 + let permValue = Services.perms.testExactPermissionFromPrincipal(principal, "geolocation"); 1.31 + is(permValue, Ci.nsIPermissionManager.PROMPT_ACTION, "Geolocation permission: prompt."); 1.32 + 1.33 + let msg = gAppBrowser.contentDocument.getElementById("msg"); 1.34 + mutObserver = new MutationObserver(function(mutations) { 1.35 + if (msg.textContent == "Failure.") { 1.36 + ok(true, "Permission not granted."); 1.37 + } else { 1.38 + ok(false, "Permission not granted."); 1.39 + } 1.40 + 1.41 + if (openedWindows != 2) { 1.42 + ok(false, "Prompt not shown."); 1.43 + } 1.44 + 1.45 + finish(); 1.46 + }); 1.47 + mutObserver.observe(msg, { childList: true }); 1.48 + }); 1.49 + 1.50 + registerCleanupFunction(function() { 1.51 + Services.ww.unregisterNotification(winObserver); 1.52 + mutObserver.disconnect(); 1.53 + }); 1.54 +}