Bug 903055 - Test geolocation permission. r=myk

This commit is contained in:
Marco Castelluccio 2013-08-27 15:03:42 -04:00
Родитель b954caad6c
Коммит 9523b1f221
9 изменённых файлов: 157 добавлений и 0 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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();
});
}

Просмотреть файл

@ -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();
});
}

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
function failureCallback() {
document.getElementById("msg").textContent = "Failure.";
}
function successCallback() {
document.getElementById("msg").textContent = "Success.";
}
navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
</script>
<p id="msg">Webapp waiting for geolocation...</p>
</body>
</html>

Просмотреть файл

@ -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"
}

Просмотреть файл

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
function failureCallback() {
document.getElementById("msg").textContent = "Failure.";
}
function successCallback() {
document.getElementById("msg").textContent = "Success.";
}
navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
</script>
<p id="msg">Webapp waiting for geolocation...</p>
</body>
</html>

Просмотреть файл

@ -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" }
}
}

Просмотреть файл

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json