dom/mobilemessage/tests/marionette/test_invalid_address.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 60000;
michael@0 5
michael@0 6 const MMS_MAX_LENGTH_SUBJECT = 40;
michael@0 7
michael@0 8 SpecialPowers.addPermission("sms", true, document);
michael@0 9 SpecialPowers.setBoolPref("dom.sms.enabled", true);
michael@0 10
michael@0 11 let tasks = {
michael@0 12 // List of test fuctions. Each of them should call |tasks.next()| when
michael@0 13 // completed or |tasks.finish()| to jump to the last one.
michael@0 14 _tasks: [],
michael@0 15 _nextTaskIndex: 0,
michael@0 16
michael@0 17 push: function(func) {
michael@0 18 this._tasks.push(func);
michael@0 19 },
michael@0 20
michael@0 21 next: function() {
michael@0 22 let index = this._nextTaskIndex++;
michael@0 23 let task = this._tasks[index];
michael@0 24 try {
michael@0 25 task();
michael@0 26 } catch (ex) {
michael@0 27 ok(false, "test task[" + index + "] throws: " + ex);
michael@0 28 // Run last task as clean up if possible.
michael@0 29 if (index != this._tasks.length - 1) {
michael@0 30 this.finish();
michael@0 31 }
michael@0 32 }
michael@0 33 },
michael@0 34
michael@0 35 finish: function() {
michael@0 36 this._tasks[this._tasks.length - 1]();
michael@0 37 },
michael@0 38
michael@0 39 run: function() {
michael@0 40 this.next();
michael@0 41 }
michael@0 42 };
michael@0 43
michael@0 44 let manager;
michael@0 45
michael@0 46 function getAllMessages(callback, filter, reverse) {
michael@0 47 if (!filter) {
michael@0 48 filter = new MozSmsFilter;
michael@0 49 }
michael@0 50 let messages = [];
michael@0 51 let request = manager.getMessages(filter, reverse || false);
michael@0 52 request.onsuccess = function(event) {
michael@0 53 if (request.result) {
michael@0 54 messages.push(request.result);
michael@0 55 request.continue();
michael@0 56 return;
michael@0 57 }
michael@0 58
michael@0 59 window.setTimeout(callback.bind(null, messages), 0);
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 function deleteAllMessages() {
michael@0 64 getAllMessages(function deleteAll(messages) {
michael@0 65 let message = messages.shift();
michael@0 66 if (!message) {
michael@0 67 ok(true, "all messages deleted");
michael@0 68 tasks.next();
michael@0 69 return;
michael@0 70 }
michael@0 71
michael@0 72 let request = manager.delete(message.id);
michael@0 73 request.onsuccess = deleteAll.bind(null, messages);
michael@0 74 request.onerror = function(event) {
michael@0 75 ok(false, "failed to delete all messages");
michael@0 76 tasks.finish();
michael@0 77 }
michael@0 78 });
michael@0 79 }
michael@0 80
michael@0 81 function testInvalidAddressForSMS(aInvalidAddr) {
michael@0 82 log("manager.send(...) should get 'InvalidAddressError' error " +
michael@0 83 "when attempting to send SMS to: " + aInvalidAddr);
michael@0 84
michael@0 85 let request = manager.send(aInvalidAddr, "Test");
michael@0 86
michael@0 87 request.onerror = function(event) {
michael@0 88 log("Received 'onerror' DOMRequest event.");
michael@0 89 let error = event.target.error;
michael@0 90 ok(error instanceof DOMError, "should be a valid DOMError object");
michael@0 91 ok(error.name === "InvalidAddressError", "should be 'InvalidAddressError'");
michael@0 92 tasks.next();
michael@0 93 };
michael@0 94 }
michael@0 95
michael@0 96 function testInvalidAddressForMMS(aInvalidAddrs) {
michael@0 97 log("manager.sendMMS(...) should get 'InvalidAddressError' error " +
michael@0 98 "when attempting to send MMS to: " + aInvalidAddrs);
michael@0 99
michael@0 100 let request = manager.sendMMS({
michael@0 101 subject: "Test",
michael@0 102 receivers: aInvalidAddrs,
michael@0 103 attachments: [],
michael@0 104 });
michael@0 105
michael@0 106 request.onerror = function(event) {
michael@0 107 log("Received 'onerror' DOMRequest event.");
michael@0 108 let error = event.target.error;
michael@0 109 ok(error instanceof DOMError, "should be a valid DOMError object");
michael@0 110 ok(error.name === "InvalidAddressError", "should be 'InvalidAddressError'");
michael@0 111 tasks.next();
michael@0 112 };
michael@0 113 }
michael@0 114
michael@0 115 tasks.push(function() {
michael@0 116 log("Verifying initial state.");
michael@0 117
michael@0 118 manager = window.navigator.mozMobileMessage;
michael@0 119 ok(manager instanceof MozMobileMessageManager,
michael@0 120 "manager is instance of " + manager.constructor);
michael@0 121
michael@0 122 tasks.next();
michael@0 123 });
michael@0 124
michael@0 125 // Test sending SMS to invalid addresses.
michael@0 126 tasks.push(testInvalidAddressForSMS.bind(this, "&%&"));
michael@0 127 tasks.push(testInvalidAddressForSMS.bind(this, ""));
michael@0 128
michael@0 129 // Test sending MMS to invalid addresses.
michael@0 130 tasks.push(testInvalidAddressForMMS.bind(this, ["&%&"]));
michael@0 131 tasks.push(testInvalidAddressForMMS.bind(this, [""]));
michael@0 132 tasks.push(testInvalidAddressForMMS.bind(this, ["123", "&%&", "456"]));
michael@0 133
michael@0 134 tasks.push(deleteAllMessages);
michael@0 135
michael@0 136 // WARNING: All tasks should be pushed before this!!!
michael@0 137 tasks.push(function cleanUp() {
michael@0 138 SpecialPowers.removePermission("sms", document);
michael@0 139 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 140 finish();
michael@0 141 });
michael@0 142
michael@0 143 tasks.run();

mercurial