<!DOCTYPE html>
<html>
<head>
<script src="/resources/js-test-pre.js"></script>
<script src="/resources/notifications-test-pre.js"></script>
</head>
<body>
<script>

description("This test checks that Permissions::query() works for dedicated workers")

jsTestIsAsync = true;

var expectedData = null;
var receivedPostMessageResponse = true;

var worker = new Worker('permissions-query-dedicated-workers.js');
worker.onmessage = function(message) {
    window.message = message;
    shouldBeEqualToString("message.data", expectedData);
    receivedPostMessageResponse = true;
}

async function defaultTest()
{
    receivedPostMessageResponse = false;
    expectedData = "prompt";
    worker.postMessage(1);
    await shouldBecomeEqual("receivedPostMessageResponse", "true");
}

async function grantTest() 
{   
    receivedPostMessageResponse = false;
    expectedData = "granted";
    testRunner.setGeolocationPermission(true);
    worker.postMessage(2);
    await shouldBecomeEqual("receivedPostMessageResponse", "true");
}

async function denyTest() 
{
    receivedPostMessageResponse = false;
    expectedData = "prompt";
    testRunner.setGeolocationPermission(false);
    worker.postMessage(3);
    await shouldBecomeEqual("receivedPostMessageResponse", "true");
}

(async function () {
    await defaultTest();
    await grantTest();
    await denyTest();
    finishJSTest();
})();

</script>
<script src="/resources/js-test-post.js"></script>
</body>
</html>
