dom/mobilemessage/tests/marionette/test_getmessages.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 SpecialPowers.addPermission("sms", true, document);
michael@0 7 SpecialPowers.setBoolPref("dom.sms.enabled", true);
michael@0 8
michael@0 9 let manager = window.navigator.mozMobileMessage;
michael@0 10 let numberMsgs = 10;
michael@0 11 let smsList = new Array();
michael@0 12
michael@0 13 function verifyInitialState() {
michael@0 14 log("Verifying initial state.");
michael@0 15 ok(manager instanceof MozMobileMessageManager,
michael@0 16 "manager is instance of " + manager.constructor);
michael@0 17 // Ensure test is starting clean with no existing sms messages
michael@0 18 deleteAllMsgs(simulateIncomingSms);
michael@0 19 }
michael@0 20
michael@0 21 function isIn(aVal, aArray, aMsg) {
michael@0 22 ok(aArray.indexOf(aVal) >= 0, aMsg);
michael@0 23 }
michael@0 24
michael@0 25 function deleteAllMsgs(nextFunction) {
michael@0 26 let msgList = new Array();
michael@0 27 let smsFilter = new MozSmsFilter;
michael@0 28
michael@0 29 let cursor = manager.getMessages(smsFilter, false);
michael@0 30 ok(cursor instanceof DOMCursor,
michael@0 31 "cursor is instanceof " + cursor.constructor);
michael@0 32
michael@0 33 cursor.onsuccess = function(event) {
michael@0 34 // Check if message was found
michael@0 35 if (cursor.result) {
michael@0 36 msgList.push(cursor.result.id);
michael@0 37 // Now get next message in the list
michael@0 38 cursor.continue();
michael@0 39 } else {
michael@0 40 // No (more) messages found
michael@0 41 if (msgList.length) {
michael@0 42 log("Found " + msgList.length + " SMS messages to delete.");
michael@0 43 deleteMsgs(msgList, nextFunction);
michael@0 44 } else {
michael@0 45 log("No SMS messages found.");
michael@0 46 nextFunction();
michael@0 47 }
michael@0 48 }
michael@0 49 };
michael@0 50
michael@0 51 cursor.onerror = function(event) {
michael@0 52 log("Received 'onerror' event.");
michael@0 53 ok(event.target.error, "domerror obj");
michael@0 54 log("manager.getMessages error: " + event.target.error.name);
michael@0 55 ok(false,"Could not get SMS messages");
michael@0 56 cleanUp();
michael@0 57 };
michael@0 58 }
michael@0 59
michael@0 60 function deleteMsgs(msgList, nextFunction) {
michael@0 61 let smsId = msgList.shift();
michael@0 62
michael@0 63 log("Deleting SMS (id: " + smsId + ").");
michael@0 64 let request = manager.delete(smsId);
michael@0 65 ok(request instanceof DOMRequest,
michael@0 66 "request is instanceof " + request.constructor);
michael@0 67
michael@0 68 request.onsuccess = function(event) {
michael@0 69 log("Received 'onsuccess' smsrequest event.");
michael@0 70 if (event.target.result) {
michael@0 71 // Message deleted, continue until none are left
michael@0 72 if (msgList.length) {
michael@0 73 deleteMsgs(msgList, nextFunction);
michael@0 74 } else {
michael@0 75 log("Finished deleting SMS messages.");
michael@0 76 nextFunction();
michael@0 77 }
michael@0 78 } else {
michael@0 79 log("SMS delete failed.");
michael@0 80 ok(false,"manager.delete request returned false");
michael@0 81 cleanUp();
michael@0 82 }
michael@0 83 };
michael@0 84
michael@0 85 request.onerror = function(event) {
michael@0 86 log("Received 'onerror' smsrequest event.");
michael@0 87 ok(event.target.error, "domerror obj");
michael@0 88 ok(false, "manager.delete request returned unexpected error: "
michael@0 89 + event.target.error.name );
michael@0 90 cleanUp();
michael@0 91 };
michael@0 92 }
michael@0 93
michael@0 94 function simulateIncomingSms() {
michael@0 95 let text = "Incoming SMS number " + (smsList.length + 1);
michael@0 96 let remoteNumber = "5552229797";
michael@0 97
michael@0 98 log("Simulating incoming SMS number " + (smsList.length + 1) + " of "
michael@0 99 + numberMsgs + ".");
michael@0 100
michael@0 101 // Simulate incoming sms sent from remoteNumber to our emulator
michael@0 102 rcvdEmulatorCallback = false;
michael@0 103 runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
michael@0 104 is(result[0], "OK", "emulator callback");
michael@0 105 rcvdEmulatorCallback = true;
michael@0 106 });
michael@0 107 }
michael@0 108
michael@0 109 // Callback for incoming sms
michael@0 110 manager.onreceived = function onreceived(event) {
michael@0 111 log("Received 'onreceived' sms event.");
michael@0 112 let incomingSms = event.message;
michael@0 113 log("Received SMS (id: " + incomingSms.id + ").");
michael@0 114
michael@0 115 // Add newly received message to array of received msgs
michael@0 116 smsList.push(incomingSms);
michael@0 117
michael@0 118 // Wait for emulator to catch up before continuing
michael@0 119 waitFor(nextRep,function() {
michael@0 120 return(rcvdEmulatorCallback);
michael@0 121 });
michael@0 122 };
michael@0 123
michael@0 124 function nextRep() {
michael@0 125 if (smsList.length < numberMsgs) {
michael@0 126 simulateIncomingSms();
michael@0 127 } else {
michael@0 128 log("Received " + numberMsgs + " sms messages in total.");
michael@0 129 getMsgs(false);
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 function getMsgs(reverse) {
michael@0 134 let smsFilter = new MozSmsFilter;
michael@0 135 let foundSmsCount = 0;
michael@0 136 let foundSmsList = new Array();
michael@0 137
michael@0 138 if (!reverse) {
michael@0 139 log("Getting the sms messages.");
michael@0 140 } else {
michael@0 141 log("Getting the sms messages in reverse order.");
michael@0 142 }
michael@0 143
michael@0 144 // Note: This test is intended for getMessages, so just a basic test with
michael@0 145 // no filter (default); separate tests will be written for sms filtering
michael@0 146 let cursor = manager.getMessages(smsFilter, reverse);
michael@0 147 ok(cursor instanceof DOMCursor,
michael@0 148 "cursor is instanceof " + cursor.constructor);
michael@0 149
michael@0 150 cursor.onsuccess = function(event) {
michael@0 151 log("Received 'onsuccess' event.");
michael@0 152
michael@0 153 if (cursor.result) {
michael@0 154 // Another message found
michael@0 155 log("Got SMS (id: " + cursor.result.id + ").");
michael@0 156 foundSmsCount++;
michael@0 157 // Store found message
michael@0 158 foundSmsList.push(cursor.result);
michael@0 159 // Now get next message in the list
michael@0 160 cursor.continue();
michael@0 161 } else {
michael@0 162 // No more messages; ensure correct number found
michael@0 163 if (foundSmsCount == numberMsgs) {
michael@0 164 log("SMS getMessages returned " + foundSmsCount +
michael@0 165 " messages as expected.");
michael@0 166 } else {
michael@0 167 log("SMS getMessages returned " + foundSmsCount +
michael@0 168 " messages, but expected " + numberMsgs + ".");
michael@0 169 ok(false, "Incorrect number of messages returned by manager.getMessages");
michael@0 170 }
michael@0 171 verifyFoundMsgs(foundSmsList, reverse);
michael@0 172 }
michael@0 173 };
michael@0 174
michael@0 175 cursor.onerror = function(event) {
michael@0 176 log("Received 'onerror' event.");
michael@0 177 ok(event.target.error, "domerror obj");
michael@0 178 log("manager.getMessages error: " + event.target.error.name);
michael@0 179 ok(false,"Could not get SMS messages");
michael@0 180 cleanUp();
michael@0 181 };
michael@0 182 }
michael@0 183
michael@0 184 function verifyFoundMsgs(foundSmsList, reverse) {
michael@0 185 if (reverse) {
michael@0 186 smsList.reverse();
michael@0 187 }
michael@0 188 for (var x = 0; x < numberMsgs; x++) {
michael@0 189 is(foundSmsList[x].id, smsList[x].id, "id");
michael@0 190 is(foundSmsList[x].threadId, smsList[x].threadId, "thread id");
michael@0 191 is(foundSmsList[x].body, smsList[x].body, "body");
michael@0 192 is(foundSmsList[x].delivery, smsList[x].delivery, "delivery");
michael@0 193 is(foundSmsList[x].read, smsList[x].read, "read");
michael@0 194
michael@0 195 // Bug 805799: receiver null when onreceived event is fired, until do a
michael@0 196 // getMessage. Default emulator (receiver) phone number is 15555215554
michael@0 197 if (!smsList[x].receiver) {
michael@0 198 isIn(foundSmsList[x].receiver, ["15555215554", "+15555215554"], "receiver");
michael@0 199 } else {
michael@0 200 isIn(foundSmsList[x].receiver, [smsList[x].receiver, "+15555215554"], "receiver");
michael@0 201 }
michael@0 202
michael@0 203 isIn(foundSmsList[x].sender, [smsList[x].sender, "+15552229797"], "sender");
michael@0 204 is(foundSmsList[x].timestamp, smsList[x].timestamp, "timestamp");
michael@0 205 is(foundSmsList[x].sentTimestamp, smsList[x].sentTimestamp, "sentTimestamp");
michael@0 206 }
michael@0 207
michael@0 208 log("Content in all of the returned SMS messages is correct.");
michael@0 209
michael@0 210 if (!reverse) {
michael@0 211 // Now get messages in reverse
michael@0 212 getMsgs(true);
michael@0 213 } else {
michael@0 214 // Finished, delete all messages
michael@0 215 deleteAllMsgs(cleanUp);
michael@0 216 };
michael@0 217 }
michael@0 218
michael@0 219 function cleanUp() {
michael@0 220 manager.onreceived = null;
michael@0 221 SpecialPowers.removePermission("sms", document);
michael@0 222 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 223 finish();
michael@0 224 }
michael@0 225
michael@0 226 // Start the test
michael@0 227 verifyInitialState();

mercurial