summaryrefslogtreecommitdiffstats
path: root/dom/push/test/xpcshell/test_observer_data.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/push/test/xpcshell/test_observer_data.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/push/test/xpcshell/test_observer_data.js')
-rw-r--r--dom/push/test/xpcshell/test_observer_data.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/dom/push/test/xpcshell/test_observer_data.js b/dom/push/test/xpcshell/test_observer_data.js
new file mode 100644
index 000000000..2a610475a
--- /dev/null
+++ b/dom/push/test/xpcshell/test_observer_data.js
@@ -0,0 +1,42 @@
+'use strict';
+
+var pushNotifier = Cc['@mozilla.org/push/Notifier;1']
+ .getService(Ci.nsIPushNotifier);
+var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
+
+function run_test() {
+ run_next_test();
+}
+
+add_task(function* test_notifyWithData() {
+ let textData = '{"hello":"world"}';
+ let payload = new TextEncoder('utf-8').encode(textData);
+
+ let notifyPromise =
+ promiseObserverNotification(PushServiceComponent.pushTopic);
+ pushNotifier.notifyPushWithData('chrome://notify-test', systemPrincipal,
+ '' /* messageId */, payload.length, payload);
+
+ let data = (yield notifyPromise).subject.QueryInterface(
+ Ci.nsIPushMessage).data;
+ deepEqual(data.json(), {
+ hello: 'world',
+ }, 'Should extract JSON values');
+ deepEqual(data.binary(), Array.from(payload),
+ 'Should extract raw binary data');
+ equal(data.text(), textData, 'Should extract text data');
+});
+
+add_task(function* test_empty_notifyWithData() {
+ let notifyPromise =
+ promiseObserverNotification(PushServiceComponent.pushTopic);
+ pushNotifier.notifyPushWithData('chrome://notify-test', systemPrincipal,
+ '' /* messageId */, 0, null);
+
+ let data = (yield notifyPromise).subject.QueryInterface(
+ Ci.nsIPushMessage).data;
+ throws(_ => data.json(),
+ 'Should throw an error when parsing an empty string as JSON');
+ strictEqual(data.text(), '', 'Should return an empty string');
+ deepEqual(data.binary(), [], 'Should return an empty array');
+});