Sat, 03 Jan 2015 20:18:00 +0100
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 function testInvalidAddressForSMS(aInvalidAddr) {
82 log("manager.send(...) should get 'InvalidAddressError' error " +
83 "when attempting to send SMS to: " + aInvalidAddr);
85 let request = manager.send(aInvalidAddr, "Test");
87 request.onerror = function(event) {
88 log("Received 'onerror' DOMRequest event.");
89 let error = event.target.error;
90 ok(error instanceof DOMError, "should be a valid DOMError object");
91 ok(error.name === "InvalidAddressError", "should be 'InvalidAddressError'");
92 tasks.next();
93 };
94 }
96 function testInvalidAddressForMMS(aInvalidAddrs) {
97 log("manager.sendMMS(...) should get 'InvalidAddressError' error " +
98 "when attempting to send MMS to: " + aInvalidAddrs);
100 let request = manager.sendMMS({
101 subject: "Test",
102 receivers: aInvalidAddrs,
103 attachments: [],
104 });
106 request.onerror = function(event) {
107 log("Received 'onerror' DOMRequest event.");
108 let error = event.target.error;
109 ok(error instanceof DOMError, "should be a valid DOMError object");
110 ok(error.name === "InvalidAddressError", "should be 'InvalidAddressError'");
111 tasks.next();
112 };
113 }
115 tasks.push(function() {
116 log("Verifying initial state.");
118 manager = window.navigator.mozMobileMessage;
119 ok(manager instanceof MozMobileMessageManager,
120 "manager is instance of " + manager.constructor);
122 tasks.next();
123 });
125 // Test sending SMS to invalid addresses.
126 tasks.push(testInvalidAddressForSMS.bind(this, "&%&"));
127 tasks.push(testInvalidAddressForSMS.bind(this, ""));
129 // Test sending MMS to invalid addresses.
130 tasks.push(testInvalidAddressForMMS.bind(this, ["&%&"]));
131 tasks.push(testInvalidAddressForMMS.bind(this, [""]));
132 tasks.push(testInvalidAddressForMMS.bind(this, ["123", "&%&", "456"]));
134 tasks.push(deleteAllMessages);
136 // WARNING: All tasks should be pushed before this!!!
137 tasks.push(function cleanUp() {
138 SpecialPowers.removePermission("sms", document);
139 SpecialPowers.clearUserPref("dom.sms.enabled");
140 finish();
141 });
143 tasks.run();