Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | MARIONETTE_HEAD_JS = 'mmdb_head.js'; |
michael@0 | 6 | |
michael@0 | 7 | const DBNAME = "test_mmdb_full_storage:" + newUUID(); |
michael@0 | 8 | |
michael@0 | 9 | let gIsDiskFull = true; |
michael@0 | 10 | |
michael@0 | 11 | function newSavableMessage() { |
michael@0 | 12 | return { |
michael@0 | 13 | type: "sms", |
michael@0 | 14 | sender: "+0987654321", |
michael@0 | 15 | receiver: "+1234567890", |
michael@0 | 16 | body: "quick fox jump over the lazy dog", |
michael@0 | 17 | deliveryStatusRequested: false, |
michael@0 | 18 | messageClass: "normal", |
michael@0 | 19 | timestamp: Date.now(), |
michael@0 | 20 | iccId: "1029384756" |
michael@0 | 21 | }; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function isFileNoDeviceSpaceError(aErrorResult) { |
michael@0 | 25 | is(aErrorResult, Cr.NS_ERROR_FILE_NO_DEVICE_SPACE, "Database error code"); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function isCallbackStorageFullError(aErrorCode) { |
michael@0 | 29 | is(aErrorCode, Ci.nsIMobileMessageCallback.STORAGE_FULL_ERROR, |
michael@0 | 30 | "nsIMobileMessageCallback error code"); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function testSaveSendingMessage(aMmdb) { |
michael@0 | 34 | log("testSaveSendingMessage()"); |
michael@0 | 35 | |
michael@0 | 36 | gIsDiskFull = true; |
michael@0 | 37 | return saveSendingMessage(aMmdb, newSavableMessage()) |
michael@0 | 38 | // Resolved/rejected results are both [<Cr.NS_ERROR_FOO>, <DOM message>], |
michael@0 | 39 | // and we need only the error code in both cases. |
michael@0 | 40 | .then((aValue) => aValue[0], |
michael@0 | 41 | (aValue) => aValue[0]) |
michael@0 | 42 | .then(isFileNoDeviceSpaceError); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function testSaveReceivedMessage(aMmdb) { |
michael@0 | 46 | log("testSaveReceivedMessage()"); |
michael@0 | 47 | |
michael@0 | 48 | gIsDiskFull = true; |
michael@0 | 49 | return saveReceivedMessage(aMmdb, newSavableMessage()) |
michael@0 | 50 | // Resolved/rejected results are both [<Cr.NS_ERROR_FOO>, <DOM message>], |
michael@0 | 51 | // and we need only the error code in both cases. |
michael@0 | 52 | .then((aValue) => aValue[0], |
michael@0 | 53 | (aValue) => aValue[0]) |
michael@0 | 54 | .then(isFileNoDeviceSpaceError); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function testGetMessageRecordById(aMmdb) { |
michael@0 | 58 | log("testGetMessageRecordById()"); |
michael@0 | 59 | |
michael@0 | 60 | gIsDiskFull = false; |
michael@0 | 61 | return saveReceivedMessage(aMmdb, newSavableMessage()) |
michael@0 | 62 | // Resolved result is [<Cr.NS_ERROR_FOO>, <DOM message>], |
michael@0 | 63 | .then(function(aValue) { |
michael@0 | 64 | let domMessage = aValue[1]; |
michael@0 | 65 | |
michael@0 | 66 | gIsDiskFull = true; |
michael@0 | 67 | return getMessageRecordById(aMmdb, domMessage.id); |
michael@0 | 68 | }); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function testMarkMessageRead(aMmdb) { |
michael@0 | 72 | log("testMarkMessageRead()"); |
michael@0 | 73 | |
michael@0 | 74 | gIsDiskFull = false; |
michael@0 | 75 | return saveReceivedMessage(aMmdb, newSavableMessage()) |
michael@0 | 76 | // Resolved/rejected results are both [<Cr.NS_ERROR_FOO>, <DOM message>]. |
michael@0 | 77 | .then(function(aValue) { |
michael@0 | 78 | let domMessage = aValue[1]; |
michael@0 | 79 | |
michael@0 | 80 | gIsDiskFull = true; |
michael@0 | 81 | return markMessageRead(aMmdb, domMessage.id, true) |
michael@0 | 82 | .then(null, (aValue) => aValue) |
michael@0 | 83 | .then(isCallbackStorageFullError); |
michael@0 | 84 | }); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function testCreateMessageCursor(aMmdb) { |
michael@0 | 88 | log("testCreateMessageCursor()"); |
michael@0 | 89 | |
michael@0 | 90 | gIsDiskFull = true; |
michael@0 | 91 | return createMessageCursor(aMmdb, {}, false); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function testCreateThreadCursor(aMmdb) { |
michael@0 | 95 | log("testCreateThreadCursor()"); |
michael@0 | 96 | |
michael@0 | 97 | gIsDiskFull = true; |
michael@0 | 98 | return createThreadCursor(aMmdb); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | startTestBase(function testCaseMain() { |
michael@0 | 102 | |
michael@0 | 103 | let mmdb = newMobileMessageDB(); |
michael@0 | 104 | return initMobileMessageDB(mmdb, DBNAME, 0) |
michael@0 | 105 | .then(function() { |
michael@0 | 106 | mmdb.isDiskFull = function() { |
michael@0 | 107 | return gIsDiskFull; |
michael@0 | 108 | }; |
michael@0 | 109 | }) |
michael@0 | 110 | |
michael@0 | 111 | .then(() => testSaveSendingMessage(mmdb)) |
michael@0 | 112 | .then(() => testSaveReceivedMessage(mmdb)) |
michael@0 | 113 | .then(() => testGetMessageRecordById(mmdb)) |
michael@0 | 114 | .then(() => testMarkMessageRead(mmdb)) |
michael@0 | 115 | .then(() => testCreateMessageCursor(mmdb)) |
michael@0 | 116 | .then(() => testCreateThreadCursor(mmdb)) |
michael@0 | 117 | |
michael@0 | 118 | .then(() => closeMobileMessageDB(mmdb)); |
michael@0 | 119 | }); |