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.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 60000;
     6 const MMS_MAX_LENGTH_SUBJECT = 40;
     8 SpecialPowers.addPermission("sms", true, document);
     9 SpecialPowers.setBoolPref("dom.sms.enabled", true);
    11 let tasks = {
    12   // List of test fuctions. Each of them should call |tasks.next()| when
    13   // completed or |tasks.finish()| to jump to the last one.
    14   _tasks: [],
    15   _nextTaskIndex: 0,
    17   push: function(func) {
    18     this._tasks.push(func);
    19   },
    21   next: function() {
    22     let index = this._nextTaskIndex++;
    23     let task = this._tasks[index];
    24     try {
    25       task();
    26     } catch (ex) {
    27       ok(false, "test task[" + index + "] throws: " + ex);
    28       // Run last task as clean up if possible.
    29       if (index != this._tasks.length - 1) {
    30         this.finish();
    31       }
    32     }
    33   },
    35   finish: function() {
    36     this._tasks[this._tasks.length - 1]();
    37   },
    39   run: function() {
    40     this.next();
    41   }
    42 };
    44 let manager;
    46 function getAllMessages(callback, filter, reverse) {
    47   if (!filter) {
    48     filter = new MozSmsFilter;
    49   }
    50   let messages = [];
    51   let request = manager.getMessages(filter, reverse || false);
    52   request.onsuccess = function(event) {
    53     if (request.result) {
    54       messages.push(request.result);
    55       request.continue();
    56       return;
    57     }
    59     window.setTimeout(callback.bind(null, messages), 0);
    60   }
    61 }
    63 function deleteAllMessages() {
    64   getAllMessages(function deleteAll(messages) {
    65     let message = messages.shift();
    66     if (!message) {
    67       ok(true, "all messages deleted");
    68       tasks.next();
    69       return;
    70     }
    72     let request = manager.delete(message.id);
    73     request.onsuccess = deleteAll.bind(null, messages);
    74     request.onerror = function(event) {
    75       ok(false, "failed to delete all messages");
    76       tasks.finish();
    77     }
    78   });
    79 }
    81 tasks.push(function() {
    82   log("Verifying initial state.");
    84   manager = window.navigator.mozMobileMessage;
    85   ok(manager instanceof MozMobileMessageManager,
    86      "manager is instance of " + manager.constructor);
    88   tasks.next();
    89 });
    91 tasks.push(function() {
    92   log("MmsMessage.attachments should be an empty array.");
    94   manager.onfailed = function(event) {
    95     manager.onfailed = null;
    97     let message = event.message;
    98     ok(Array.isArray(message.attachments) && message.attachments.length === 0,
    99        "message.attachments should be an empty array.");
   101     tasks.next();
   102   };
   104   // Have a long long subject causes the send fails, so we don't need
   105   // networking here.
   106   manager.sendMMS({
   107     subject: new Array(MMS_MAX_LENGTH_SUBJECT + 2).join("a"),
   108     receivers: ["1", "2"],
   109     attachments: [],
   110   });
   111 });
   113 tasks.push(deleteAllMessages);
   115 // WARNING: All tasks should be pushed before this!!!
   116 tasks.push(function cleanUp() {
   117   SpecialPowers.removePermission("sms", document);
   118   SpecialPowers.clearUserPref("dom.sms.enabled");
   119   finish();
   120 });
   122 tasks.run();

mercurial