Bug 1144399 - Replace LoginTest usage with LoginTestUtils. r=paolo

This commit is contained in:
Nazim Can Altinova 2015-04-19 11:01:00 +01:00
Родитель beff3d3dfe
Коммит 1867fc27ec
11 изменённых файлов: 133 добавлений и 130 удалений

Просмотреть файл

@ -31,12 +31,11 @@ const LoginInfo =
Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
"nsILoginInfo", "init");
// Import LoginTestUtils.jsm as LoginTest.
XPCOMUtils.defineLazyModuleGetter(this, "LoginTest",
"resource://testing-common/LoginTestUtils.jsm",
"LoginTestUtils");
LoginTest.Assert = Assert;
const TestData = LoginTest.testData;
// Import LoginTestUtils.jsm as LoginTestUtils.
XPCOMUtils.defineLazyModuleGetter(this, "LoginTestUtils",
"resource://testing-common/LoginTestUtils.jsm");
LoginTestUtils.Assert = Assert;
const TestData = LoginTestUtils.testData;
/**
* All the tests are implemented with add_task, this starts them automatically.
@ -172,8 +171,8 @@ add_task(function test_common_initialize()
yield Services.logins.initializationPromise;
// Ensure that every test file starts with an empty database.
LoginTest.clearData();
LoginTestUtils.clearData();
// Clean up after every test.
do_register_cleanup(() => LoginTest.clearData());
do_register_cleanup(() => LoginTestUtils.clearData());
});

Просмотреть файл

@ -26,23 +26,24 @@ add_task(function test_setLoginSavingEnabled_getAllDisabledHosts()
Services.logins.setLoginSavingEnabled(hostname2, false);
Services.logins.setLoginSavingEnabled(hostname3, false);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname2, hostname3]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname2, hostname3]);
// Adding the same host twice should not result in an error.
Services.logins.setLoginSavingEnabled(hostname2, false);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname2, hostname3]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname2, hostname3]);
// Removing a disabled host should work.
Services.logins.setLoginSavingEnabled(hostname2, true);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname3]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1, hostname3]);
// Removing the last disabled host should work.
Services.logins.setLoginSavingEnabled(hostname1, true);
Services.logins.setLoginSavingEnabled(hostname3, true);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(), []);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[]);
});
/**
@ -83,7 +84,8 @@ add_task(function test_setLoginSavingEnabled_invalid_characters()
/Invalid hostname/);
// Verify that no data was stored by the previous call.
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(), []);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[]);
});
/**
@ -112,8 +114,8 @@ add_task(function test_rememberSignons()
do_check_false(Services.logins.getLoginSavingEnabled(hostname2));
// The list of disabled hosts should be unaltered.
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname1]);
// Changing values with the preference set should work.
Services.logins.setLoginSavingEnabled(hostname1, true);
@ -124,8 +126,8 @@ add_task(function test_rememberSignons()
do_check_false(Services.logins.getLoginSavingEnabled(hostname2));
// The list of disabled hosts should have been changed.
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname2]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname2]);
// Enable storage of saved passwords again.
Services.prefs.setBoolPref("signon.rememberSignons", true);
@ -136,7 +138,8 @@ add_task(function test_rememberSignons()
// Clean up.
Services.logins.setLoginSavingEnabled(hostname2, true);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(), []);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[]);
});
/**
@ -147,8 +150,8 @@ add_task(function test_storage_setLoginSavingEnabled_nonascii()
let hostname = "http://" + String.fromCharCode(355) + ".example.com";
Services.logins.setLoginSavingEnabled(hostname, false);
yield LoginTest.reloadData();
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname]);
LoginTest.clearData();
yield LoginTestUtils.reloadData();
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname]);
LoginTestUtils.clearData();
});

Просмотреть файл

@ -104,5 +104,5 @@ add_task(function test_searchLogins_wildcard()
let loginInfo = TestData.formLogin({ hostname: "http://any.example.com",
formSubmitURL: "" });
LoginTest.assertLoginListsEqual(logins, [loginInfo]);
LoginTestUtils.assertLoginListsEqual(logins, [loginInfo]);
});

Просмотреть файл

@ -28,7 +28,7 @@ function checkLoginInvalid(aLoginInfo, aExpectedError)
{
// Try to add the new login, and verify that no data is stored.
Assert.throws(() => Services.logins.addLogin(aLoginInfo), aExpectedError);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
// Add a login for the modification tests.
let testLogin = TestData.formLogin({ hostname: "http://modify.example.com" });
@ -48,7 +48,7 @@ function checkLoginInvalid(aLoginInfo, aExpectedError)
})), aExpectedError);
// Verify that no data was stored by the previous calls.
LoginTest.checkLogins([testLogin]);
LoginTestUtils.checkLogins([testLogin]);
Services.logins.removeLogin(testLogin);
}
@ -64,7 +64,7 @@ add_task(function test_addLogin_removeLogin()
for (let loginInfo of TestData.loginList()) {
Services.logins.addLogin(loginInfo);
}
LoginTest.checkLogins(TestData.loginList());
LoginTestUtils.checkLogins(TestData.loginList());
// Trying to add each login again should result in an error.
for (let loginInfo of TestData.loginList()) {
@ -76,7 +76,7 @@ add_task(function test_addLogin_removeLogin()
Services.logins.removeLogin(loginInfo);
}
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
});
/**
@ -179,7 +179,7 @@ add_task(function test_removeAllLogins()
Services.logins.addLogin(loginInfo);
}
Services.logins.removeAllLogins();
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
// The function should also work when there are no logins to delete.
Services.logins.removeAllLogins();
@ -208,25 +208,25 @@ add_task(function test_modifyLogin_nsILoginInfo()
Services.logins.modifyLogin(loginInfo, updatedLoginInfo);
// The data should now match the second login.
LoginTest.checkLogins([updatedLoginInfo]);
LoginTestUtils.checkLogins([updatedLoginInfo]);
Assert.throws(() => Services.logins.modifyLogin(loginInfo, updatedLoginInfo),
/No matching logins/);
// The login can be changed to have a different type and hostname.
Services.logins.modifyLogin(updatedLoginInfo, differentLoginInfo);
LoginTest.checkLogins([differentLoginInfo]);
LoginTestUtils.checkLogins([differentLoginInfo]);
// It is now possible to add a login with the old type and hostname.
Services.logins.addLogin(loginInfo);
LoginTest.checkLogins([loginInfo, differentLoginInfo]);
LoginTestUtils.checkLogins([loginInfo, differentLoginInfo]);
// Modifying a login to match an existing one should not be possible.
Assert.throws(
() => Services.logins.modifyLogin(loginInfo, differentLoginInfo),
/already exists/);
LoginTest.checkLogins([loginInfo, differentLoginInfo]);
LoginTestUtils.checkLogins([loginInfo, differentLoginInfo]);
LoginTest.clearData();
LoginTestUtils.clearData();
});
/**
@ -267,7 +267,7 @@ add_task(function test_modifyLogin_nsIProperyBag()
}));
// The data should now match the second login.
LoginTest.checkLogins([updatedLoginInfo]);
LoginTestUtils.checkLogins([updatedLoginInfo]);
Assert.throws(() => Services.logins.modifyLogin(loginInfo, newPropertyBag()),
/No matching logins/);
@ -281,17 +281,17 @@ add_task(function test_modifyLogin_nsIProperyBag()
// The login can be changed to have a different type and hostname.
Services.logins.modifyLogin(updatedLoginInfo, differentLoginProperties);
LoginTest.checkLogins([differentLoginInfo]);
LoginTestUtils.checkLogins([differentLoginInfo]);
// It is now possible to add a login with the old type and hostname.
Services.logins.addLogin(loginInfo);
LoginTest.checkLogins([loginInfo, differentLoginInfo]);
LoginTestUtils.checkLogins([loginInfo, differentLoginInfo]);
// Modifying a login to match an existing one should not be possible.
Assert.throws(
() => Services.logins.modifyLogin(loginInfo, differentLoginProperties),
/already exists/);
LoginTest.checkLogins([loginInfo, differentLoginInfo]);
LoginTestUtils.checkLogins([loginInfo, differentLoginInfo]);
LoginTest.clearData();
LoginTestUtils.clearData();
});

Просмотреть файл

@ -56,7 +56,7 @@ add_task(function test_logins_decrypt_failure()
for (let loginInfo of logins) {
Services.logins.addLogin(loginInfo);
}
LoginTest.checkLogins(logins);
LoginTestUtils.checkLogins(logins);
do_check_eq(Services.logins.countLogins("", "", ""), logins.length * 2);
// Finding logins doesn't return the non-decryptable duplicates.

Просмотреть файл

@ -109,7 +109,7 @@ add_task(function test_addLogin_metainfo()
gLoginMetaInfo1 = retrieveLoginMatching(gLoginInfo1);
do_check_true(gLooksLikeUUIDRegex.test(gLoginMetaInfo1.guid));
let creationTime = gLoginMetaInfo1.timeCreated;
LoginTest.assertTimeIsAboutNow(creationTime);
LoginTestUtils.assertTimeIsAboutNow(creationTime);
do_check_eq(gLoginMetaInfo1.timeLastUsed, creationTime);
do_check_eq(gLoginMetaInfo1.timePasswordChanged, creationTime);
do_check_eq(gLoginMetaInfo1.timesUsed, 1);
@ -128,7 +128,7 @@ add_task(function test_addLogin_metainfo()
// Add an authentication login to the database before continuing.
Services.logins.addLogin(gLoginInfo3);
gLoginMetaInfo3 = retrieveLoginMatching(gLoginInfo3);
LoginTest.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
});
/**
@ -144,7 +144,7 @@ add_task(function test_addLogin_metainfo_duplicate()
/specified GUID already exists/);
// Verify that no data was stored by the previous call.
LoginTest.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
});
/**
@ -201,7 +201,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo()
do_check_eq(gLoginMetaInfo2.password, gLoginInfo2.password);
do_check_eq(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
do_check_eq(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
LoginTest.assertTimeIsAboutNow(gLoginMetaInfo2.timePasswordChanged);
LoginTestUtils.assertTimeIsAboutNow(gLoginMetaInfo2.timePasswordChanged);
// Check that timePasswordChanged is not set to the current time when changing
// the password and specifying a new value for the property at the same time.
@ -237,7 +237,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo_duplicate()
Assert.throws(() => Services.logins.modifyLogin(gLoginInfo1, newPropertyBag({
guid: gLoginInfo2.guid,
})), /specified GUID already exists/);
LoginTest.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
});
/**
@ -277,8 +277,8 @@ add_task(function test_searchLogins_metainfo()
*/
add_task(function test_storage_metainfo()
{
yield LoginTest.reloadData();
LoginTest.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
yield LoginTestUtils.reloadData();
LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo1), gLoginMetaInfo1);
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo2), gLoginMetaInfo2);

Просмотреть файл

@ -52,7 +52,7 @@ function checkSearchLogins(aQuery, aExpectedCount)
let outCount = {};
let logins = Services.logins.searchLogins(outCount, newPropertyBag(aQuery));
do_check_eq(outCount.value, expectedLogins.length);
LoginTest.assertLoginListsEqual(logins, expectedLogins);
LoginTestUtils.assertLoginListsEqual(logins, expectedLogins);
}
/**
@ -87,7 +87,7 @@ function checkAllSearches(aQuery, aExpectedCount)
let logins = Services.logins.findLogins(outCount, hostname, formSubmitURL,
httpRealm);
do_check_eq(outCount.value, expectedLogins.length);
LoginTest.assertLoginListsEqual(logins, expectedLogins);
LoginTestUtils.assertLoginListsEqual(logins, expectedLogins);
// Test countLogins.
let count = Services.logins.countLogins(hostname, formSubmitURL, httpRealm)

Просмотреть файл

@ -206,7 +206,7 @@ add_task(function test_import_downgraded()
// Verify that the missing metadata was generated correctly.
let loginItem = store.data.logins[0];
let creationTime = loginItem.timeCreated;
LoginTest.assertTimeIsAboutNow(creationTime);
LoginTestUtils.assertTimeIsAboutNow(creationTime);
do_check_eq(loginItem.timeLastUsed, creationTime);
do_check_eq(loginItem.timePasswordChanged, creationTime);
do_check_eq(loginItem.timesUsed, 1);

Просмотреть файл

@ -76,7 +76,7 @@ testdesc = "addLogin";
expectedNotification = "addLogin";
expectedData = testuser1;
Services.logins.addLogin(testuser1);
LoginTest.checkLogins([testuser1]);
LoginTestUtils.checkLogins([testuser1]);
do_check_eq(expectedNotification, null); // check that observer got a notification
/* ========== 3 ========== */
@ -87,7 +87,7 @@ expectedNotification = "modifyLogin";
expectedData=[testuser1, testuser2];
Services.logins.modifyLogin(testuser1, testuser2);
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([testuser2]);
LoginTestUtils.checkLogins([testuser2]);
/* ========== 4 ========== */
testnum++;
@ -97,7 +97,7 @@ expectedNotification = "removeLogin";
expectedData = testuser2;
Services.logins.removeLogin(testuser2);
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
/* ========== 5 ========== */
testnum++;
@ -107,7 +107,7 @@ expectedNotification = "removeAllLogins";
expectedData = null;
Services.logins.removeAllLogins();
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
/* ========== 6 ========== */
testnum++;
@ -117,7 +117,7 @@ expectedNotification = "removeAllLogins";
expectedData = null;
Services.logins.removeAllLogins();
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
/* ========== 7 ========== */
testnum++;
@ -127,8 +127,8 @@ expectedNotification = "hostSavingDisabled";
expectedData = "http://site.com";
Services.logins.setLoginSavingEnabled("http://site.com", false);
do_check_eq(expectedNotification, null);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
["http://site.com"]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
["http://site.com"]);
/* ========== 8 ========== */
testnum++;
@ -138,8 +138,8 @@ expectedNotification = "hostSavingDisabled";
expectedData = "http://site.com";
Services.logins.setLoginSavingEnabled("http://site.com", false);
do_check_eq(expectedNotification, null);
LoginTest.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
["http://site.com"]);
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
["http://site.com"]);
/* ========== 9 ========== */
testnum++;
@ -149,7 +149,7 @@ expectedNotification = "hostSavingEnabled";
expectedData = "http://site.com";
Services.logins.setLoginSavingEnabled("http://site.com", true);
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
/* ========== 10 ========== */
testnum++;
@ -159,11 +159,11 @@ expectedNotification = "hostSavingEnabled";
expectedData = "http://site.com";
Services.logins.setLoginSavingEnabled("http://site.com", true);
do_check_eq(expectedNotification, null);
LoginTest.checkLogins([]);
LoginTestUtils.checkLogins([]);
Services.obs.removeObserver(TestObserver, "passwordmgr-storage-changed");
LoginTest.clearData();
LoginTestUtils.clearData();
} catch (e) {
throw new Error("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);

Просмотреть файл

@ -16,9 +16,9 @@
function reloadAndCheckLogins(aExpectedLogins)
{
yield LoginTest.reloadData();
LoginTest.checkLogins(aExpectedLogins);
LoginTest.clearData();
yield LoginTestUtils.reloadData();
LoginTestUtils.checkLogins(aExpectedLogins);
LoginTestUtils.clearData();
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -11,13 +11,13 @@ const ENCTYPE_SDR = 1;
// kept in sync with the version there (or else the tests fail).
const CURRENT_SCHEMA = 5;
LoginTest.copyFile = function (aLeafName)
function copyFile(aLeafName)
{
yield OS.File.copy(OS.Path.join(do_get_file("data").path, aLeafName),
OS.Path.join(OS.Constants.Path.profileDir, aLeafName));
};
LoginTest.openDB = function (aLeafName)
function openDB(aLeafName)
{
var dbFile = new FileUtils.File(OS.Constants.Path.profileDir);
dbFile.append(aLeafName);
@ -25,7 +25,7 @@ LoginTest.openDB = function (aLeafName)
return Services.storage.openDatabase(dbFile);
};
LoginTest.deleteFile = function (pathname, filename)
function deleteFile(pathname, filename)
{
var file = new FileUtils.File(pathname);
file.append(filename);
@ -39,7 +39,7 @@ LoginTest.deleteFile = function (pathname, filename)
} catch (e) {}
};
LoginTest.reloadStorage = function (aInputPathName, aInputFileName)
function reloadStorage(aInputPathName, aInputFileName)
{
var inputFile = null;
if (aInputFileName) {
@ -58,10 +58,11 @@ LoginTest.reloadStorage = function (aInputPathName, aInputFileName)
return storage;
};
LoginTest.checkStorageData = function (storage, ref_disabledHosts, ref_logins)
function checkStorageData(storage, ref_disabledHosts, ref_logins)
{
LoginTest.assertLoginListsEqual(storage.getAllLogins(), ref_logins);
LoginTest.assertDisabledHostsEqual(storage.getAllDisabledHosts(), ref_disabledHosts);
LoginTestUtils.assertLoginListsEqual(storage.getAllLogins(), ref_logins);
LoginTestUtils.assertDisabledHostsEqual(storage.getAllDisabledHosts(),
ref_disabledHosts);
};
add_task(function test_execute()
@ -121,21 +122,21 @@ testuser5.init("http://test.gov", "http://test.gov", null,
testnum++;
testdesc = "Test downgrade from v999 storage"
yield LoginTest.copyFile("signons-v999.sqlite");
yield copyFile("signons-v999.sqlite");
// Verify the schema version in the test file.
dbConnection = LoginTest.openDB("signons-v999.sqlite");
dbConnection = openDB("signons-v999.sqlite");
do_check_eq(999, dbConnection.schemaVersion);
dbConnection.close();
storage = LoginTest.reloadStorage(OUTDIR, "signons-v999.sqlite");
LoginTest.checkStorageData(storage, ["https://disabled.net"], [testuser1]);
storage = reloadStorage(OUTDIR, "signons-v999.sqlite");
checkStorageData(storage, ["https://disabled.net"], [testuser1]);
// Check to make sure we downgraded the schema version.
dbConnection = LoginTest.openDB("signons-v999.sqlite");
dbConnection = openDB("signons-v999.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
dbConnection.close();
LoginTest.deleteFile(OUTDIR, "signons-v999.sqlite");
deleteFile(OUTDIR, "signons-v999.sqlite");
/* ========== 2 ========== */
testnum++;
@ -146,10 +147,10 @@ var origFile = OS.Path.join(OUTDIR, "signons-v999-2.sqlite");
var failFile = OS.Path.join(OUTDIR, "signons-v999-2.sqlite.corrupt");
// Make sure we always start clean in a clean state.
yield LoginTest.copyFile("signons-v999-2.sqlite");
yield copyFile("signons-v999-2.sqlite");
yield OS.File.remove(failFile);
Assert.throws(() => LoginTest.reloadStorage(OUTDIR, "signons-v999-2.sqlite"),
Assert.throws(() => reloadStorage(OUTDIR, "signons-v999-2.sqlite"),
/Initialization failed/);
// Check to ensure the DB file was renamed to .corrupt.
@ -162,17 +163,17 @@ yield OS.File.remove(failFile);
testnum++;
testdesc = "Test upgrade from v1->v2 storage"
yield LoginTest.copyFile("signons-v1.sqlite");
yield copyFile("signons-v1.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v1.sqlite");
dbConnection = openDB("signons-v1.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
dbConnection.close();
storage = LoginTest.reloadStorage(OUTDIR, "signons-v1.sqlite");
LoginTest.checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2]);
storage = reloadStorage(OUTDIR, "signons-v1.sqlite");
checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2]);
// Check to see that we added a GUIDs to the logins.
dbConnection = LoginTest.openDB("signons-v1.sqlite");
dbConnection = openDB("signons-v1.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
var guid = getGUIDforID(dbConnection, 1);
do_check_true(isGUID.test(guid));
@ -180,7 +181,7 @@ guid = getGUIDforID(dbConnection, 2);
do_check_true(isGUID.test(guid));
dbConnection.close();
LoginTest.deleteFile(OUTDIR, "signons-v1.sqlite");
deleteFile(OUTDIR, "signons-v1.sqlite");
/* ========== 4 ========== */
testnum++;
@ -189,23 +190,23 @@ testdesc = "Test upgrade v2->v1 storage";
// are upgrading it again. Any logins added by the v1 code must be properly
// upgraded.
yield LoginTest.copyFile("signons-v1v2.sqlite");
yield copyFile("signons-v1v2.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v1v2.sqlite");
dbConnection = openDB("signons-v1v2.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
dbConnection.close();
storage = LoginTest.reloadStorage(OUTDIR, "signons-v1v2.sqlite");
LoginTest.checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2, testuser3]);
storage = reloadStorage(OUTDIR, "signons-v1v2.sqlite");
checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2, testuser3]);
// While we're here, try modifying a login, to ensure that doing so doesn't
// change the existing GUID.
storage.modifyLogin(testuser1, testuser1B);
LoginTest.checkStorageData(storage, ["https://disabled.net"], [testuser1B, testuser2, testuser3]);
checkStorageData(storage, ["https://disabled.net"], [testuser1B, testuser2, testuser3]);
// Check the GUIDs. Logins 1 and 2 should retain their original GUID, login 3
// should have one created (because it didn't have one previously).
dbConnection = LoginTest.openDB("signons-v1v2.sqlite");
dbConnection = openDB("signons-v1v2.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
guid = getGUIDforID(dbConnection, 1);
do_check_eq("{655c7358-f1d6-6446-adab-53f98ac5d80f}", guid);
@ -215,18 +216,18 @@ guid = getGUIDforID(dbConnection, 3);
do_check_true(isGUID.test(guid));
dbConnection.close();
LoginTest.deleteFile(OUTDIR, "signons-v1v2.sqlite");
deleteFile(OUTDIR, "signons-v1v2.sqlite");
/* ========== 5 ========== */
testnum++;
testdesc = "Test upgrade from v2->v3 storage"
yield LoginTest.copyFile("signons-v2.sqlite");
yield copyFile("signons-v2.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v2.sqlite");
dbConnection = openDB("signons-v2.sqlite");
do_check_eq(2, dbConnection.schemaVersion);
storage = LoginTest.reloadStorage(OUTDIR, "signons-v2.sqlite");
storage = reloadStorage(OUTDIR, "signons-v2.sqlite");
// Check to see that we added the correct encType to the logins.
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
@ -237,10 +238,10 @@ dbConnection.close();
// There are 4 logins, but 3 will be invalid because we can no longer decrypt
// base64-encoded items. (testuser1/4/5)
LoginTest.checkStorageData(storage, ["https://disabled.net"],
checkStorageData(storage, ["https://disabled.net"],
[testuser2]);
LoginTest.deleteFile(OUTDIR, "signons-v2.sqlite");
deleteFile(OUTDIR, "signons-v2.sqlite");
/* ========== 6 ========== */
testnum++;
@ -249,16 +250,16 @@ testdesc = "Test upgrade v3->v2 storage";
// are upgrading it again. Any logins added by the v2 code must be properly
// upgraded.
yield LoginTest.copyFile("signons-v2v3.sqlite");
yield copyFile("signons-v2v3.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v2v3.sqlite");
dbConnection = openDB("signons-v2v3.sqlite");
do_check_eq(2, dbConnection.schemaVersion);
encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64, null];
for (let i = 0; i < encTypes.length; i++)
do_check_eq(encTypes[i], getEncTypeForID(dbConnection, i + 1));
// Reload storage, check that the new login now has encType=1, others untouched
storage = LoginTest.reloadStorage(OUTDIR, "signons-v2v3.sqlite");
storage = reloadStorage(OUTDIR, "signons-v2v3.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64, ENCTYPE_SDR];
@ -268,53 +269,53 @@ for (let i = 0; i < encTypes.length; i++)
// Sanity check that the data gets migrated
// There are 5 logins, but 3 will be invalid because we can no longer decrypt
// base64-encoded items. (testuser1/4/5). We no longer reencrypt with SDR.
LoginTest.checkStorageData(storage, ["https://disabled.net"], [testuser2, testuser3]);
checkStorageData(storage, ["https://disabled.net"], [testuser2, testuser3]);
encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64, ENCTYPE_SDR];
for (let i = 0; i < encTypes.length; i++)
do_check_eq(encTypes[i], getEncTypeForID(dbConnection, i + 1));
dbConnection.close();
LoginTest.deleteFile(OUTDIR, "signons-v2v3.sqlite");
deleteFile(OUTDIR, "signons-v2v3.sqlite");
/* ========== 7 ========== */
testnum++;
testdesc = "Test upgrade from v3->v4 storage"
yield LoginTest.copyFile("signons-v3.sqlite");
yield copyFile("signons-v3.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v3.sqlite");
dbConnection = openDB("signons-v3.sqlite");
do_check_eq(3, dbConnection.schemaVersion);
storage = LoginTest.reloadStorage(OUTDIR, "signons-v3.sqlite");
storage = reloadStorage(OUTDIR, "signons-v3.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
// Check that timestamps and counts were initialized correctly
LoginTest.checkStorageData(storage, [], [testuser1, testuser2]);
checkStorageData(storage, [], [testuser1, testuser2]);
var logins = storage.getAllLogins();
for (var i = 0; i < 2; i++) {
do_check_true(logins[i] instanceof Ci.nsILoginMetaInfo);
do_check_eq(1, logins[i].timesUsed);
LoginTest.assertTimeIsAboutNow(logins[i].timeCreated);
LoginTest.assertTimeIsAboutNow(logins[i].timeLastUsed);
LoginTest.assertTimeIsAboutNow(logins[i].timePasswordChanged);
LoginTestUtils.assertTimeIsAboutNow(logins[i].timeCreated);
LoginTestUtils.assertTimeIsAboutNow(logins[i].timeLastUsed);
LoginTestUtils.assertTimeIsAboutNow(logins[i].timePasswordChanged);
}
/* ========== 8 ========== */
testnum++;
testdesc = "Test upgrade from v3->v4->v3 storage"
yield LoginTest.copyFile("signons-v3v4.sqlite");
yield copyFile("signons-v3v4.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v3v4.sqlite");
dbConnection = openDB("signons-v3v4.sqlite");
do_check_eq(3, dbConnection.schemaVersion);
storage = LoginTest.reloadStorage(OUTDIR, "signons-v3v4.sqlite");
storage = reloadStorage(OUTDIR, "signons-v3v4.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
// testuser1 already has timestamps, testuser2 does not.
LoginTest.checkStorageData(storage, [], [testuser1, testuser2]);
checkStorageData(storage, [], [testuser1, testuser2]);
var logins = storage.getAllLogins();
@ -336,22 +337,22 @@ do_check_eq(1262049951275, t1.timeLastUsed);
do_check_eq(1262049951275, t1.timePasswordChanged);
do_check_eq(1, t2.timesUsed);
LoginTest.assertTimeIsAboutNow(t2.timeCreated);
LoginTest.assertTimeIsAboutNow(t2.timeLastUsed);
LoginTest.assertTimeIsAboutNow(t2.timePasswordChanged);
LoginTestUtils.assertTimeIsAboutNow(t2.timeCreated);
LoginTestUtils.assertTimeIsAboutNow(t2.timeLastUsed);
LoginTestUtils.assertTimeIsAboutNow(t2.timePasswordChanged);
/* ========== 9 ========== */
testnum++;
testdesc = "Test upgrade from v4 storage"
yield LoginTest.copyFile("signons-v4.sqlite");
yield copyFile("signons-v4.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v4.sqlite");
dbConnection = openDB("signons-v4.sqlite");
do_check_eq(4, dbConnection.schemaVersion);
do_check_false(dbConnection.tableExists("moz_deleted_logins"));
storage = LoginTest.reloadStorage(OUTDIR, "signons-v4.sqlite");
storage = reloadStorage(OUTDIR, "signons-v4.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
do_check_true(dbConnection.tableExists("moz_deleted_logins"));
@ -360,13 +361,13 @@ do_check_true(dbConnection.tableExists("moz_deleted_logins"));
testnum++;
testdesc = "Test upgrade from v4->v5->v4 storage"
yield LoginTest.copyFile("signons-v4v5.sqlite");
yield copyFile("signons-v4v5.sqlite");
// Sanity check the test file.
dbConnection = LoginTest.openDB("signons-v4v5.sqlite");
dbConnection = openDB("signons-v4v5.sqlite");
do_check_eq(4, dbConnection.schemaVersion);
do_check_true(dbConnection.tableExists("moz_deleted_logins"));
storage = LoginTest.reloadStorage(OUTDIR, "signons-v4v5.sqlite");
storage = reloadStorage(OUTDIR, "signons-v4v5.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
do_check_true(dbConnection.tableExists("moz_deleted_logins"));
@ -397,7 +398,7 @@ yield OS.File.copy(do_get_file("data/corruptDB.sqlite").path, filepath);
// will init mozStorage module with corrupt database, init should fail
Assert.throws(
() => LoginTest.reloadStorage(OS.Constants.Path.profileDir, filename),
() => reloadStorage(OS.Constants.Path.profileDir, filename),
/Initialization failed/);
// check that the backup file exists
@ -407,11 +408,11 @@ do_check_true(yield OS.File.exists(filepath + ".corrupt"));
do_check_false(yield OS.File.exists(filepath));
// initialize the storage module again
storage = LoginTest.reloadStorage(OS.Constants.Path.profileDir, filename);
storage = reloadStorage(OS.Constants.Path.profileDir, filename);
// use the storage module again, should work now
storage.addLogin(testuser1);
LoginTest.checkStorageData(storage, [], [testuser1]);
checkStorageData(storage, [], [testuser1]);
// check the file exists
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
@ -419,8 +420,8 @@ file.initWithPath(OS.Constants.Path.profileDir);
file.append(filename);
do_check_true(file.exists());
LoginTest.deleteFile(OS.Constants.Path.profileDir, filename + ".corrupt");
LoginTest.deleteFile(OS.Constants.Path.profileDir, filename);
deleteFile(OS.Constants.Path.profileDir, filename + ".corrupt");
deleteFile(OS.Constants.Path.profileDir, filename);
} catch (e) {
throw new Error("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);