mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 980354 - 1/2: add mmdb_head.js and run mmdb test cases in chrome context. r=hsinyi
This commit is contained in:
parent
3bcd1c9eb8
commit
220885d16f
@ -344,65 +344,6 @@ function sendRawSmsToEmulator(aPdu) {
|
|||||||
return runEmulatorCmdSafe(command);
|
return runEmulatorCmdSafe(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Name space for MobileMessageDB.jsm. Only initialized after first call to
|
|
||||||
* newMobileMessageDB.
|
|
||||||
*/
|
|
||||||
let MMDB;
|
|
||||||
|
|
||||||
// Create a new MobileMessageDB instance.
|
|
||||||
function newMobileMessageDB() {
|
|
||||||
if (!MMDB) {
|
|
||||||
MMDB = Cu.import("resource://gre/modules/MobileMessageDB.jsm", {});
|
|
||||||
is(typeof MMDB.MobileMessageDB, "function", "MMDB.MobileMessageDB");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mmdb = new MMDB.MobileMessageDB();
|
|
||||||
ok(mmdb, "MobileMessageDB instance");
|
|
||||||
return mmdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a MobileMessageDB. Resolve if initialized with success, reject
|
|
||||||
* otherwise.
|
|
||||||
*
|
|
||||||
* Fulfill params: a MobileMessageDB instance.
|
|
||||||
* Reject params: a MobileMessageDB instance.
|
|
||||||
*
|
|
||||||
* @param aMmdb
|
|
||||||
* A MobileMessageDB instance.
|
|
||||||
* @param aDbName
|
|
||||||
* A string name for that database.
|
|
||||||
* @param aDbVersion
|
|
||||||
* The version that MobileMessageDB should upgrade to. 0 for the lastest
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* @return A deferred promise.
|
|
||||||
*/
|
|
||||||
function initMobileMessageDB(aMmdb, aDbName, aDbVersion) {
|
|
||||||
let deferred = Promise.defer();
|
|
||||||
|
|
||||||
aMmdb.init(aDbName, aDbVersion, function(aError) {
|
|
||||||
if (aError) {
|
|
||||||
deferred.reject(aMmdb);
|
|
||||||
} else {
|
|
||||||
deferred.resolve(aMmdb);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close a MobileMessageDB.
|
|
||||||
*
|
|
||||||
* @return The passed MobileMessageDB instance.
|
|
||||||
*/
|
|
||||||
function closeMobileMessageDB(aMmdb) {
|
|
||||||
aMmdb.close();
|
|
||||||
return aMmdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new array of id attribute of input messages.
|
* Create a new array of id attribute of input messages.
|
||||||
*
|
*
|
||||||
@ -418,24 +359,6 @@ function messagesToIds(aMessages) {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A reference to a nsIUUIDGenerator service.
|
|
||||||
let uuidGenerator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a new UUID.
|
|
||||||
*
|
|
||||||
* @return A UUID string.
|
|
||||||
*/
|
|
||||||
function newUUID() {
|
|
||||||
if (!uuidGenerator) {
|
|
||||||
uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
|
|
||||||
.getService(Ci.nsIUUIDGenerator);
|
|
||||||
ok(uuidGenerator, "uuidGenerator");
|
|
||||||
}
|
|
||||||
|
|
||||||
return uuidGenerator.generateUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush permission settings and call |finish()|.
|
* Flush permission settings and call |finish()|.
|
||||||
*/
|
*/
|
||||||
|
117
dom/mobilemessage/tests/marionette/mmdb_head.js
Normal file
117
dom/mobilemessage/tests/marionette/mmdb_head.js
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
MARIONETTE_CONTEXT = "chrome";
|
||||||
|
|
||||||
|
let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name space for MobileMessageDB.jsm. Only initialized after first call to
|
||||||
|
* newMobileMessageDB.
|
||||||
|
*/
|
||||||
|
let MMDB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new MobileMessageDB instance.
|
||||||
|
*
|
||||||
|
* @return A MobileMessageDB instance.
|
||||||
|
*/
|
||||||
|
function newMobileMessageDB() {
|
||||||
|
if (!MMDB) {
|
||||||
|
MMDB = Cu.import("resource://gre/modules/MobileMessageDB.jsm", {});
|
||||||
|
is(typeof MMDB.MobileMessageDB, "function", "MMDB.MobileMessageDB");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mmdb = new MMDB.MobileMessageDB();
|
||||||
|
ok(mmdb, "MobileMessageDB instance");
|
||||||
|
return mmdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a MobileMessageDB. Resolve if initialized with success, reject
|
||||||
|
* otherwise.
|
||||||
|
*
|
||||||
|
* Fulfill params: a MobileMessageDB instance.
|
||||||
|
* Reject params: a MobileMessageDB instance.
|
||||||
|
*
|
||||||
|
* @param aMmdb
|
||||||
|
* A MobileMessageDB instance.
|
||||||
|
* @param aDbName
|
||||||
|
* A string name for that database.
|
||||||
|
* @param aDbVersion
|
||||||
|
* The version that MobileMessageDB should upgrade to. 0 for the lastest
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* @return A deferred promise.
|
||||||
|
*/
|
||||||
|
function initMobileMessageDB(aMmdb, aDbName, aDbVersion) {
|
||||||
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
|
aMmdb.init(aDbName, aDbVersion, function(aError) {
|
||||||
|
if (aError) {
|
||||||
|
deferred.reject(aMmdb);
|
||||||
|
} else {
|
||||||
|
deferred.resolve(aMmdb);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a MobileMessageDB.
|
||||||
|
*
|
||||||
|
* @param aMmdb
|
||||||
|
* A MobileMessageDB instance.
|
||||||
|
*
|
||||||
|
* @return The passed MobileMessageDB instance.
|
||||||
|
*/
|
||||||
|
function closeMobileMessageDB(aMmdb) {
|
||||||
|
aMmdb.close();
|
||||||
|
return aMmdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A reference to a nsIUUIDGenerator service.
|
||||||
|
let _uuidGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new UUID.
|
||||||
|
*
|
||||||
|
* @return A UUID string.
|
||||||
|
*/
|
||||||
|
function newUUID() {
|
||||||
|
if (!_uuidGenerator) {
|
||||||
|
_uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
|
||||||
|
.getService(Ci.nsIUUIDGenerator);
|
||||||
|
ok(_uuidGenerator, "uuidGenerator");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _uuidGenerator.generateUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush permission settings and call |finish()|.
|
||||||
|
*/
|
||||||
|
function cleanUp() {
|
||||||
|
// Use ok here so that we have at least one test run.
|
||||||
|
ok(true, "permissions flushed");
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic test routine helper for mobile message tests.
|
||||||
|
*
|
||||||
|
* This helper does nothing but clean-ups.
|
||||||
|
*
|
||||||
|
* @param aTestCaseMain
|
||||||
|
* A function that takes no parameter.
|
||||||
|
*/
|
||||||
|
function startTestBase(aTestCaseMain) {
|
||||||
|
Promise.resolve()
|
||||||
|
.then(aTestCaseMain)
|
||||||
|
.then(null, function() {
|
||||||
|
ok(false, 'promise rejects during test.');
|
||||||
|
})
|
||||||
|
.then(cleanUp);
|
||||||
|
}
|
@ -2,11 +2,9 @@
|
|||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
MARIONETTE_TIMEOUT = 60000;
|
MARIONETTE_TIMEOUT = 60000;
|
||||||
MARIONETTE_HEAD_JS = 'head.js';
|
MARIONETTE_HEAD_JS = 'mmdb_head.js';
|
||||||
|
|
||||||
// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
|
const DBNAME = "test_mmdb_foreachmatchedmmsdeliveryinfo:" + newUUID();
|
||||||
// empty object in return.
|
|
||||||
let mmdb;
|
|
||||||
|
|
||||||
const PHONE_0 = "+15555215500";
|
const PHONE_0 = "+15555215500";
|
||||||
const PHONE_1 = "+15555215501";
|
const PHONE_1 = "+15555215501";
|
||||||
@ -51,10 +49,6 @@ function doTest(aMmdb, aNeedle, aVerifyFunc, aCount) {
|
|||||||
function testNotFound(aMmdb) {
|
function testNotFound(aMmdb) {
|
||||||
log("Testing unavailable");
|
log("Testing unavailable");
|
||||||
|
|
||||||
// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
|
|
||||||
// empty object in return.
|
|
||||||
aMmdb = mmdb;
|
|
||||||
|
|
||||||
doTest(aMmdb, PHONE_0, function(aElement) {
|
doTest(aMmdb, PHONE_0, function(aElement) {
|
||||||
ok(false, "Should never have a match");
|
ok(false, "Should never have a match");
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -65,10 +59,6 @@ function testNotFound(aMmdb) {
|
|||||||
function testDirectMatch(aMmdb) {
|
function testDirectMatch(aMmdb) {
|
||||||
log("Testing direct matching");
|
log("Testing direct matching");
|
||||||
|
|
||||||
// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
|
|
||||||
// empty object in return.
|
|
||||||
aMmdb = mmdb;
|
|
||||||
|
|
||||||
for (let needle of [PHONE_1, EMAIL_1]) {
|
for (let needle of [PHONE_1, EMAIL_1]) {
|
||||||
let count = deliveryInfo.reduce(function(aCount, aElement) {
|
let count = deliveryInfo.reduce(function(aCount, aElement) {
|
||||||
return aElement.receiver == needle ? aCount + 1 : aCount;
|
return aElement.receiver == needle ? aCount + 1 : aCount;
|
||||||
@ -87,9 +77,6 @@ function testPhoneMatch(aMmdb) {
|
|||||||
let verifyFunc = function(aValid, aElement) {
|
let verifyFunc = function(aValid, aElement) {
|
||||||
ok(aValid.indexOf(aElement.receiver) >= 0, "element.receiver");
|
ok(aValid.indexOf(aElement.receiver) >= 0, "element.receiver");
|
||||||
};
|
};
|
||||||
// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
|
|
||||||
// empty object in return.
|
|
||||||
aMmdb = mmdb;
|
|
||||||
|
|
||||||
let matchingGroups = [
|
let matchingGroups = [
|
||||||
[PHONE_2, PHONE_2_NET],
|
[PHONE_2, PHONE_2_NET],
|
||||||
@ -105,10 +92,10 @@ function testPhoneMatch(aMmdb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startTestBase(function testCaseMain() {
|
startTestBase(function testCaseMain() {
|
||||||
mmdb = newMobileMessageDB();
|
let mmdb = newMobileMessageDB();
|
||||||
return initMobileMessageDB(mmdb, "test_mmdb_foreachmatchedmmsdeliveryinfo", 0)
|
return initMobileMessageDB(mmdb, DBNAME, 0)
|
||||||
.then(testNotFound)
|
.then(testNotFound)
|
||||||
.then(testDirectMatch)
|
.then(testDirectMatch)
|
||||||
.then(testPhoneMatch)
|
.then(testPhoneMatch)
|
||||||
.then(closeMobileMessageDB.bind(null, mmdb));
|
.then(closeMobileMessageDB);
|
||||||
});
|
});
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
MARIONETTE_TIMEOUT = 60000;
|
MARIONETTE_TIMEOUT = 60000;
|
||||||
MARIONETTE_HEAD_JS = 'head.js';
|
MARIONETTE_HEAD_JS = 'mmdb_head.js';
|
||||||
|
|
||||||
let gMmdb;
|
const DBNAME = "test_mmdb_full_storage:" + newUUID();
|
||||||
|
|
||||||
let gIsDiskFull = true;
|
let gIsDiskFull = true;
|
||||||
|
|
||||||
@ -18,16 +18,16 @@ let gMessageToSave = {
|
|||||||
iccId: "1029384756"
|
iccId: "1029384756"
|
||||||
};
|
};
|
||||||
|
|
||||||
function testSaveSendingMessage() {
|
function testSaveSendingMessage(aMmdb) {
|
||||||
log("testSaveSendingMessage()");
|
log("testSaveSendingMessage()");
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
gMmdb.saveSendingMessage(gMessageToSave,
|
aMmdb.saveSendingMessage(gMessageToSave,
|
||||||
{ notify : function(aRv, aDomMessage) {
|
{ notify : function(aRv, aDomMessage) {
|
||||||
if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
|
if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
|
||||||
ok(true, "Forbidden due to storage full.");
|
ok(true, "Forbidden due to storage full.");
|
||||||
deferred.resolve(Promise.resolve());
|
deferred.resolve(aMmdb);
|
||||||
} else {
|
} else {
|
||||||
ok(false, "Unexpected result: " + aRv);
|
ok(false, "Unexpected result: " + aRv);
|
||||||
deferred.reject(aRv);
|
deferred.reject(aRv);
|
||||||
@ -37,16 +37,16 @@ function testSaveSendingMessage() {
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSaveReceivingMessage() {
|
function testSaveReceivingMessage(aMmdb) {
|
||||||
log("testSaveReceivingMessage()");
|
log("testSaveReceivingMessage()");
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
gMmdb.saveReceivedMessage(gMessageToSave,
|
aMmdb.saveReceivedMessage(gMessageToSave,
|
||||||
{ notify : function(aRv, aDomMessage) {
|
{ notify : function(aRv, aDomMessage) {
|
||||||
if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
|
if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
|
||||||
ok(true, "Forbidden due to storage full.");
|
ok(true, "Forbidden due to storage full.");
|
||||||
deferred.resolve(Promise.resolve());
|
deferred.resolve(aMmdb);
|
||||||
} else {
|
} else {
|
||||||
ok(false, "Unexpected result: " + aRv);
|
ok(false, "Unexpected result: " + aRv);
|
||||||
deferred.reject(aRv);
|
deferred.reject(aRv);
|
||||||
@ -56,16 +56,16 @@ function testSaveReceivingMessage() {
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetMessage() {
|
function testGetMessage(aMmdb) {
|
||||||
log("testGetMessage()");
|
log("testGetMessage()");
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
gMmdb.getMessage(1,
|
aMmdb.getMessage(1,
|
||||||
{ notifyGetMessageFailed : function(aRv) {
|
{ notifyGetMessageFailed : function(aRv) {
|
||||||
if (aRv === Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR) {
|
if (aRv === Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR) {
|
||||||
ok(true, "Getting message successfully!");
|
ok(true, "Getting message successfully!");
|
||||||
deferred.resolve(Promise.resolve());
|
deferred.resolve(aMmdb);
|
||||||
} else {
|
} else {
|
||||||
ok(false, "Unexpected result: " + aRv);
|
ok(false, "Unexpected result: " + aRv);
|
||||||
deferred.reject(aRv);
|
deferred.reject(aRv);
|
||||||
@ -77,13 +77,13 @@ function testGetMessage() {
|
|||||||
|
|
||||||
startTestBase(function testCaseMain() {
|
startTestBase(function testCaseMain() {
|
||||||
|
|
||||||
gMmdb = newMobileMessageDB();
|
let mmdb = newMobileMessageDB();
|
||||||
gMmdb.isDiskFull = function() {
|
mmdb.isDiskFull = function() {
|
||||||
return gIsDiskFull;
|
return gIsDiskFull;
|
||||||
};
|
};
|
||||||
return initMobileMessageDB(gMmdb, "test_gMmdb_full_storage", 0)
|
return initMobileMessageDB(mmdb, DBNAME, 0)
|
||||||
.then(testSaveSendingMessage)
|
.then(testSaveSendingMessage)
|
||||||
.then(testSaveReceivingMessage)
|
.then(testSaveReceivingMessage)
|
||||||
.then(testGetMessage)
|
.then(testGetMessage)
|
||||||
.then(closeMobileMessageDB.bind(null, gMmdb));
|
.then(closeMobileMessageDB);
|
||||||
});
|
});
|
||||||
|
@ -2,35 +2,36 @@
|
|||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
MARIONETTE_TIMEOUT = 60000;
|
MARIONETTE_TIMEOUT = 60000;
|
||||||
MARIONETTE_HEAD_JS = 'head.js';
|
MARIONETTE_HEAD_JS = 'mmdb_head.js';
|
||||||
|
|
||||||
|
const DBNAME = "test_mmdb_new:" + newUUID();
|
||||||
|
let dbVersion = 0;
|
||||||
|
|
||||||
|
function check(aMmdb) {
|
||||||
|
is(aMmdb.dbName, DBNAME, "dbName");
|
||||||
|
if (!dbVersion) {
|
||||||
|
ok(aMmdb.dbVersion, "dbVersion");
|
||||||
|
dbVersion = aMmdb.dbVersion;
|
||||||
|
} else {
|
||||||
|
is(aMmdb.dbVersion, dbVersion, "dbVersion");
|
||||||
|
}
|
||||||
|
|
||||||
|
return aMmdb;
|
||||||
|
}
|
||||||
|
|
||||||
startTestBase(function testCaseMain() {
|
startTestBase(function testCaseMain() {
|
||||||
log("Test init MobileMessageDB");
|
log("Test init MobileMessageDB");
|
||||||
|
|
||||||
// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
|
|
||||||
// empty object in return.
|
|
||||||
let mmdb = newMobileMessageDB();
|
let mmdb = newMobileMessageDB();
|
||||||
let dbName = "test_mmdb_new";
|
return initMobileMessageDB(mmdb, DBNAME, dbVersion)
|
||||||
let dbVersion = 0;
|
|
||||||
let check = function() {
|
|
||||||
is(mmdb.dbName, dbName, "dbName");
|
|
||||||
if (!dbVersion) {
|
|
||||||
ok(mmdb.dbVersion, "dbVersion");
|
|
||||||
dbVersion = mmdb.dbVersion;
|
|
||||||
} else {
|
|
||||||
is(mmdb.dbVersion, dbVersion, "dbVersion");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return initMobileMessageDB(mmdb, dbName, dbVersion)
|
|
||||||
.then(check)
|
.then(check)
|
||||||
.then(closeMobileMessageDB.bind(null, mmdb))
|
.then(closeMobileMessageDB)
|
||||||
.then(check)
|
.then(check)
|
||||||
.then(function() {
|
.then(function(aMmdb) {
|
||||||
log("Test re-init and close.");
|
log("Test re-init and close.");
|
||||||
return initMobileMessageDB(mmdb, dbName, dbVersion);
|
return initMobileMessageDB(aMmdb, DBNAME, dbVersion);
|
||||||
})
|
})
|
||||||
.then(check)
|
.then(check)
|
||||||
.then(closeMobileMessageDB.bind(null, mmdb))
|
.then(closeMobileMessageDB)
|
||||||
.then(check);
|
.then(check);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user