Bug 1267889 - Always steal the error result in PushMessage::Json. r=dragana

MozReview-Commit-ID: FOpIoIYBCFW

--HG--
extra : rebase_source : b58a1e9a9199ec781afb7a1dde77b250711d8510
extra : amend_source : b2cb82443ee0022f036d318d33e16f3de0ecf406
This commit is contained in:
Kit Cambridge 2016-04-26 18:26:30 -07:00
parent b317ad3cae
commit 7e0401c6d3
3 changed files with 42 additions and 4 deletions

View File

@ -428,10 +428,7 @@ PushMessage::Json(JSContext* aCx,
}
ErrorResult error;
BodyUtil::ConsumeJson(aCx, aResult, mDecodedText, error);
if (error.Failed()) {
return error.StealNSResult();
}
return NS_OK;
return error.StealNSResult();
}
NS_IMETHODIMP

View File

@ -0,0 +1,40 @@
'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 data = new TextEncoder('utf-8').encode(textData);
let notifyPromise =
promiseObserverNotification(PushServiceComponent.pushTopic);
pushNotifier.notifyPushWithData('chrome://notify-test', systemPrincipal,
'' /* messageId */, data.length, data);
let message = (yield notifyPromise).subject.QueryInterface(Ci.nsIPushMessage);
deepEqual(message.json(), {
hello: 'world',
}, 'Should extract JSON values');
deepEqual(message.binary(), Array.from(data),
'Should extract raw binary data');
equal(message.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 message = (yield notifyPromise).subject.QueryInterface(Ci.nsIPushMessage);
throws(_ => message.json(),
'Should throw an error when parsing an empty string as JSON');
strictEqual(message.text(), '', 'Should return an empty string');
deepEqual(message.binary(), [], 'Should return an empty array');
});

View File

@ -16,6 +16,7 @@ support-files = PushServiceHandler.js PushServiceHandler.manifest
[test_notification_error.js]
[test_notification_incomplete.js]
[test_notification_version_string.js]
[test_observer_data.js]
[test_permissions.js]
run-sequentially = This will delete all existing push subscriptions.