diff --git a/webapprt/test/chrome/Makefile.in b/webapprt/test/chrome/Makefile.in index 818e5792fa40..f12d205effed 100644 --- a/webapprt/test/chrome/Makefile.in +++ b/webapprt/test/chrome/Makefile.in @@ -28,6 +28,14 @@ MOCHITEST_WEBAPPRT_CHROME_FILES = \ noperm.webapp \ noperm.webapp^headers^ \ noperm.html \ + browser_geolocation-prompt-perm.js \ + browser_geolocation-prompt-noperm.js \ + geolocation-prompt-perm.webapp \ + geolocation-prompt-perm.webapp^headers^ \ + geolocation-prompt-noperm.webapp \ + geolocation-prompt-noperm.webapp^headers^ \ + geolocation-prompt-perm.html \ + geolocation-prompt-noperm.html \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/webapprt/test/chrome/browser_geolocation-prompt-noperm.js b/webapprt/test/chrome/browser_geolocation-prompt-noperm.js new file mode 100644 index 000000000000..e10e6f1c644d --- /dev/null +++ b/webapprt/test/chrome/browser_geolocation-prompt-noperm.js @@ -0,0 +1,47 @@ +Cu.import("resource://gre/modules/Services.jsm"); + +function test() { + waitForExplicitFinish(); + + let openedWindows = 0; + + let winObserver = function(win, topic) { + if (topic == "domwindowopened") { + win.addEventListener("load", function onLoadWindow() { + win.removeEventListener("load", onLoadWindow, false); + openedWindows++; + if (openedWindows == 2) { + ok(false, "Prompt shown."); + win.close(); + } + }, false); + } + } + + Services.ww.registerNotification(winObserver); + + let mutObserver = null; + + loadWebapp("geolocation-prompt-noperm.webapp", undefined, function onLoad() { + let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal; + let permValue = Services.perms.testExactPermissionFromPrincipal(principal, "geolocation"); + is(permValue, Ci.nsIPermissionManager.UNKNOWN_ACTION, "Geolocation permission: unknown."); + + let msg = gAppBrowser.contentDocument.getElementById("msg"); + mutObserver = new MutationObserver(function(mutations) { + if (msg.textContent == "Failure.") { + ok(true, "Permission not granted."); + } else { + ok(false, "Permission not granted."); + } + + finish(); + }); + mutObserver.observe(msg, { childList: true }); + }); + + registerCleanupFunction(function() { + Services.ww.unregisterNotification(winObserver); + mutObserver.disconnect(); + }); +} diff --git a/webapprt/test/chrome/browser_geolocation-prompt-perm.js b/webapprt/test/chrome/browser_geolocation-prompt-perm.js new file mode 100644 index 000000000000..61bf976933b1 --- /dev/null +++ b/webapprt/test/chrome/browser_geolocation-prompt-perm.js @@ -0,0 +1,51 @@ +Cu.import("resource://gre/modules/Services.jsm"); + +function test() { + waitForExplicitFinish(); + + let openedWindows = 0; + + let winObserver = function(win, topic) { + if (topic == "domwindowopened") { + win.addEventListener("load", function onLoadWindow() { + win.removeEventListener("load", onLoadWindow, false); + openedWindows++; + if (openedWindows == 2) { + ok(true, "Prompt shown."); + win.close(); + } + }, false); + } + } + + Services.ww.registerNotification(winObserver); + + let mutObserver = null; + + loadWebapp("geolocation-prompt-perm.webapp", undefined, function onLoad() { + let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal; + let permValue = Services.perms.testExactPermissionFromPrincipal(principal, "geolocation"); + is(permValue, Ci.nsIPermissionManager.PROMPT_ACTION, "Geolocation permission: prompt."); + + let msg = gAppBrowser.contentDocument.getElementById("msg"); + mutObserver = new MutationObserver(function(mutations) { + if (msg.textContent == "Failure.") { + ok(true, "Permission not granted."); + } else { + ok(false, "Permission not granted."); + } + + if (openedWindows != 2) { + ok(false, "Prompt not shown."); + } + + finish(); + }); + mutObserver.observe(msg, { childList: true }); + }); + + registerCleanupFunction(function() { + Services.ww.unregisterNotification(winObserver); + mutObserver.disconnect(); + }); +} diff --git a/webapprt/test/chrome/geolocation-prompt-noperm.html b/webapprt/test/chrome/geolocation-prompt-noperm.html new file mode 100644 index 000000000000..c4a1b6fd1259 --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-noperm.html @@ -0,0 +1,18 @@ + + + + + + + +

Webapp waiting for geolocation...

+ + diff --git a/webapprt/test/chrome/geolocation-prompt-noperm.webapp b/webapprt/test/chrome/geolocation-prompt-noperm.webapp new file mode 100644 index 000000000000..bc33bca15fa2 --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-noperm.webapp @@ -0,0 +1,5 @@ +{ + "name": "Geolocation Permission Test Webapp", + "description": "A webapp for testing geolocation prompt.", + "launch_path": "/webapprtChrome/webapprt/test/chrome/geolocation-prompt-noperm.html" +} diff --git a/webapprt/test/chrome/geolocation-prompt-noperm.webapp^headers^ b/webapprt/test/chrome/geolocation-prompt-noperm.webapp^headers^ new file mode 100644 index 000000000000..a2367b11c78b --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-noperm.webapp^headers^ @@ -0,0 +1 @@ +Content-Type: application/x-web-app-manifest+json diff --git a/webapprt/test/chrome/geolocation-prompt-perm.html b/webapprt/test/chrome/geolocation-prompt-perm.html new file mode 100644 index 000000000000..c4a1b6fd1259 --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-perm.html @@ -0,0 +1,18 @@ + + + + + + + +

Webapp waiting for geolocation...

+ + diff --git a/webapprt/test/chrome/geolocation-prompt-perm.webapp b/webapprt/test/chrome/geolocation-prompt-perm.webapp new file mode 100644 index 000000000000..7b69d616d907 --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-perm.webapp @@ -0,0 +1,8 @@ +{ + "name": "Geolocation Permission Test Webapp", + "description": "A webapp for testing geolocation prompt.", + "launch_path": "/webapprtChrome/webapprt/test/chrome/geolocation-prompt-perm.html", + "permissions": { + "geolocation": { "description": "Desc" } + } +} diff --git a/webapprt/test/chrome/geolocation-prompt-perm.webapp^headers^ b/webapprt/test/chrome/geolocation-prompt-perm.webapp^headers^ new file mode 100644 index 000000000000..a2367b11c78b --- /dev/null +++ b/webapprt/test/chrome/geolocation-prompt-perm.webapp^headers^ @@ -0,0 +1 @@ +Content-Type: application/x-web-app-manifest+json