dom/mobilemessage/tests/marionette/test_mmsmessage_attachments.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 tasks.push(function() {
michael@0 82 log("Verifying initial state.");
michael@0 83
michael@0 84 manager = window.navigator.mozMobileMessage;
michael@0 85 ok(manager instanceof MozMobileMessageManager,
michael@0 86 "manager is instance of " + manager.constructor);
michael@0 87
michael@0 88 tasks.next();
michael@0 89 });
michael@0 90
michael@0 91 tasks.push(function() {
michael@0 92 log("MmsMessage.attachments should be an empty array.");
michael@0 93
michael@0 94 manager.onfailed = function(event) {
michael@0 95 manager.onfailed = null;
michael@0 96
michael@0 97 let message = event.message;
michael@0 98 ok(Array.isArray(message.attachments) && message.attachments.length === 0,
michael@0 99 "message.attachments should be an empty array.");
michael@0 100
michael@0 101 tasks.next();
michael@0 102 };
michael@0 103
michael@0 104 // Have a long long subject causes the send fails, so we don't need
michael@0 105 // networking here.
michael@0 106 manager.sendMMS({
michael@0 107 subject: new Array(MMS_MAX_LENGTH_SUBJECT + 2).join("a"),
michael@0 108 receivers: ["1", "2"],
michael@0 109 attachments: [],
michael@0 110 });
michael@0 111 });
michael@0 112
michael@0 113 tasks.push(deleteAllMessages);
michael@0 114
michael@0 115 // WARNING: All tasks should be pushed before this!!!
michael@0 116 tasks.push(function cleanUp() {
michael@0 117 SpecialPowers.removePermission("sms", document);
michael@0 118 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 119 finish();
michael@0 120 });
michael@0 121
michael@0 122 tasks.run();

mercurial