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.

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

mercurial