dom/mobilemessage/tests/marionette/test_getsegmentinfofortext.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 // Copied from dom/system/gonk/ril_consts.js.
     7 const PDU_MAX_USER_DATA_7BIT = 160;
     9 SpecialPowers.setBoolPref("dom.sms.enabled", true);
    10 SpecialPowers.addPermission("sms", true, document);
    12 let manager = window.navigator.mozMobileMessage;
    13 ok(manager instanceof MozMobileMessageManager,
    14    "manager is instance of " + manager.constructor);
    16 let tasks = {
    17   // List of test fuctions. Each of them should call |tasks.next()| when
    18   // completed or |tasks.finish()| to jump to the last one.
    19   _tasks: [],
    20   _nextTaskIndex: 0,
    22   push: function(func) {
    23     this._tasks.push(func);
    24   },
    26   next: function() {
    27     let index = this._nextTaskIndex++;
    28     let task = this._tasks[index];
    29     try {
    30       task();
    31     } catch (ex) {
    32       ok(false, "test task[" + index + "] throws: " + ex);
    33       // Run last task as clean up if possible.
    34       if (index != this._tasks.length - 1) {
    35         this.finish();
    36       }
    37     }
    38   },
    40   finish: function() {
    41     this._tasks[this._tasks.length - 1]();
    42   },
    44   run: function() {
    45     this.next();
    46   }
    47 };
    49 function addTest(text, segments, charsPerSegment, charsAvailableInLastSegment) {
    50   tasks.push(function() {
    51     log("Testing '" + text + "' ...");
    52     let domRequest = manager.getSegmentInfoForText(text);
    53     ok(domRequest, "DOMRequest object returned.");
    55     domRequest.onsuccess = function(e) {
    56       log("Received 'onsuccess' DOMRequest event.");
    58       let result = e.target.result;
    59       if (!result) {
    60         ok(false, "getSegmentInfoForText() result is not valid.");
    61         tasks.finish();
    62         return;
    63       }
    65       is(result.segments, segments, "info.segments");
    66       is(result.charsPerSegment, charsPerSegment, "info.charsPerSegment");
    67       is(result.charsAvailableInLastSegment, charsAvailableInLastSegment,
    68          "info.charsAvailableInLastSegment");
    70       tasks.next();
    71     };
    73     domRequest.onerror = function(e) {
    74       ok(false, "Failed to call getSegmentInfoForText().");
    75       tasks.finish();
    76     };
    77   });
    78 }
    80 function addTestThrows(text) {
    81   tasks.push(function() {
    82     log("Testing '" + text + "' ...");
    83     try {
    84       let domRequest = manager.getSegmentInfoForText(text);
    86       ok(false, "Not thrown.");
    87       tasks.finish();
    88     } catch (e) {
    89       tasks.next();
    90     }
    91   });
    92 }
    94 addTestThrows(null);
    96 // Testing "undefined".
    97 addTest(undefined, 1, PDU_MAX_USER_DATA_7BIT,
    98         PDU_MAX_USER_DATA_7BIT - "undefined".length);
   100 // Testing numeric values.
   101 addTest(0,   1, PDU_MAX_USER_DATA_7BIT, PDU_MAX_USER_DATA_7BIT - "0".length);
   102 addTest(1.0, 1, PDU_MAX_USER_DATA_7BIT, PDU_MAX_USER_DATA_7BIT - "1".length);
   104 // Testing empty object.  The empty object extends to "[object Object]" and both
   105 // '[' and ']' are in default single shift table, so each of them takes two
   106 // septets.
   107 addTest({}, 1, PDU_MAX_USER_DATA_7BIT,
   108         PDU_MAX_USER_DATA_7BIT - (("" + {}).length + 2));
   110 // Testing Date object.
   111 let date = new Date();
   112 addTest(date, 1, PDU_MAX_USER_DATA_7BIT,
   113         PDU_MAX_USER_DATA_7BIT - ("" + date).length);
   115 addTest("", 1, PDU_MAX_USER_DATA_7BIT,
   116         PDU_MAX_USER_DATA_7BIT - "".length);
   118 // WARNING: All tasks should be pushed before this!!!
   119 tasks.push(function cleanUp() {
   120   SpecialPowers.removePermission("sms", document);
   121   SpecialPowers.clearUserPref("dom.sms.enabled");
   122   finish();
   123 });
   125 tasks.run();

mercurial