Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1038811 - Push Notifications - Tests. r=nsm
- Loading branch information
Showing
13 changed files
with
515 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> | ||
<script> | ||
|
||
|
||
function waitOnPushMessage(pushSubscription) | ||
{ | ||
var p = new Promise(function(res, rej) { | ||
navigator.serviceWorker.onmessage = function(e) { | ||
if (e.data.type == "finished") { | ||
parent.ok(e.data.okay == "yes", "Got a push message."); | ||
res(pushSubscription); | ||
} | ||
}; | ||
}); | ||
return p; | ||
} | ||
|
||
|
||
</script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[DEFAULT] | ||
support-files = | ||
worker.js | ||
push-server.sjs | ||
frame.html | ||
|
||
[test_has_permissions.html] | ||
skip-if = os == "android" || toolkit == "gonk" | ||
[test_permissions.html] | ||
skip-if = os == "android" || toolkit == "gonk" | ||
[test_register.html] | ||
skip-if = os == "android" || toolkit == "gonk" | ||
[test_multiple_register.html] | ||
skip-if = os == "android" || toolkit == "gonk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function debug(str) { | ||
// dump("@@@ push-server " + str + "\n"); | ||
} | ||
|
||
function handleRequest(request, response) | ||
{ | ||
debug("handling request!"); | ||
|
||
const Cc = Components.classes; | ||
const Ci = Components.interfaces; | ||
|
||
let params = request.getHeader("X-Push-Server"); | ||
debug("params = " + params); | ||
|
||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); | ||
xhr.open("PUT", params); | ||
xhr.send(); | ||
xhr.onload = function(e) { | ||
debug("xhr : " + this.status); | ||
} | ||
xhr.onerror = function(e) { | ||
debug("xhr error: " + e); | ||
} | ||
|
||
response.setStatusLine(request.httpVersion, "200", "OK"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<!-- | ||
Bug 1038811: Push tests. | ||
Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/licenses/publicdomain/ | ||
--> | ||
<head> | ||
<title>Test for Bug 1038811</title> | ||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> | ||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> | ||
</head> | ||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1038811">Mozilla Bug 1038811</a> | ||
<p id="display"></p> | ||
<div id="content" style="display: none"> | ||
|
||
</div> | ||
<pre id="test"> | ||
</pre> | ||
|
||
<script class="testbody" type="text/javascript"> | ||
|
||
function debug(str) { | ||
// console.log(str + "\n"); | ||
} | ||
|
||
function start() { | ||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."}) | ||
.then((swr) => registration = swr); | ||
} | ||
|
||
function unregister() { | ||
return registration.unregister().then(function(result) { | ||
ok(result, "Unregister should return true."); | ||
}); | ||
} | ||
|
||
function hasPermission(swr) { | ||
var p = new Promise(function(res, rej) { | ||
swr.pushManager.hasPermission().then( | ||
function(status) { | ||
debug("status: " + status); | ||
ok(true, "hasPermission() returned a status"); | ||
res(swr); | ||
}, function(error) { | ||
ok(false, "hasPermission failed."); | ||
res(swr); | ||
} | ||
); | ||
}); | ||
return p; | ||
} | ||
|
||
function runTest() { | ||
start() | ||
.then(hasPermission) | ||
.then(unregister) | ||
.catch(function(e) { | ||
ok(false, "Some test failed with error " + e); | ||
}).then(SimpleTest.finish); | ||
} | ||
|
||
SpecialPowers.addPermission('push', false, document); | ||
SpecialPowers.pushPrefEnv({"set": [ | ||
["dom.serviceWorkers.exemptFromPerDomainMax", true], | ||
["dom.serviceWorkers.enabled", true], | ||
["dom.serviceWorkers.testing.enabled", true] | ||
]}, runTest); | ||
SimpleTest.waitForExplicitFinish(); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<!-- | ||
Bug 1038811: Push tests. | ||
Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/licenses/publicdomain/ | ||
--> | ||
<head> | ||
<title>Test for Bug 1038811</title> | ||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> | ||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> | ||
</head> | ||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1038811">Mozilla Bug 1038811</a> | ||
<p id="display"></p> | ||
<div id="content" style="display: none"> | ||
|
||
</div> | ||
<pre id="test"> | ||
</pre> | ||
|
||
<script class="testbody" type="text/javascript"> | ||
|
||
function debug(str) { | ||
// console.log(str + "\n"); | ||
} | ||
|
||
function start() { | ||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."}) | ||
.then((swr) => registration = swr); | ||
} | ||
|
||
function unregister() { | ||
return registration.unregister().then(function(result) { | ||
ok(result, "Unregister should return true."); | ||
}); | ||
} | ||
|
||
function setupPushNotification(swr) { | ||
var p = new Promise(function(res, rej) { | ||
swr.pushManager.subscribe().then( | ||
function(pushSubscription) { | ||
ok(true, "successful registered for push notification"); | ||
res({swr: swr, pushSubscription: pushSubscription}); | ||
}, function(error) { | ||
ok(false, "could not register for push notification"); | ||
res(null); | ||
} | ||
); | ||
}); | ||
return p; | ||
} | ||
|
||
function setupSecondEndpoint(result) { | ||
var p = new Promise(function(res, rej) { | ||
result.swr.pushManager.subscribe().then( | ||
function(pushSubscription) { | ||
ok(result.pushSubscription.endpoint == pushSubscription.endpoint, "setupSecondEndpoint - Got the same endpoint back."); | ||
res(result); | ||
}, function(error) { | ||
ok(false, "could not register for push notification"); | ||
res(null); | ||
} | ||
); | ||
}); | ||
return p; | ||
} | ||
|
||
function getEndpointExpectNull(swr) { | ||
var p = new Promise(function(res, rej) { | ||
swr.pushManager.getSubscription().then( | ||
function(pushSubscription) { | ||
ok(pushSubscription == null, "getEndpoint should return null when app not subscribed."); | ||
res(swr); | ||
}, function(error) { | ||
ok(false, "could not register for push notification"); | ||
res(null); | ||
} | ||
); | ||
}); | ||
return p; | ||
} | ||
|
||
function getEndpoint(result) { | ||
var p = new Promise(function(res, rej) { | ||
result.swr.pushManager.getSubscription().then( | ||
function(pushSubscription) { | ||
ok(result.pushSubscription.endpoint == pushSubscription.endpoint, "getEndpoint - Got the same endpoint back."); | ||
|
||
res(pushSubscription); | ||
}, function(error) { | ||
ok(false, "could not register for push notification"); | ||
res(null); | ||
} | ||
); | ||
}); | ||
return p; | ||
} | ||
|
||
function unregisterPushNotification(pushSubscription) { | ||
return pushSubscription.unsubscribe(); | ||
} | ||
|
||
function runTest() { | ||
start() | ||
.then(getEndpointExpectNull) | ||
.then(setupPushNotification) | ||
.then(setupSecondEndpoint) | ||
.then(getEndpoint) | ||
.then(unregisterPushNotification) | ||
.then(unregister) | ||
.catch(function(e) { | ||
ok(false, "Some test failed with error " + e); | ||
}).then(SimpleTest.finish); | ||
} | ||
|
||
SpecialPowers.pushPrefEnv({"set": [ | ||
["dom.serviceWorkers.exemptFromPerDomainMax", true], | ||
["dom.serviceWorkers.enabled", true], | ||
["dom.serviceWorkers.testing.enabled", true] | ||
]}, runTest); | ||
SpecialPowers.addPermission('push', true, document); | ||
SimpleTest.waitForExplicitFinish(); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.