Bug 1230549 - Make Storage pass basic eslint. r=yoric

--HG--
rename : browser/.eslintrc => storage/.eslintrc
extra : commitid : 5RiWGmPFkg2
extra : rebase_source : 54b8a2e9680c37d88c0a501d85422163f4e04fea
This commit is contained in:
Marco Bonardo 2015-12-04 15:52:43 +01:00
Родитель b729a30707
Коммит 4190a83115
5 изменённых файлов: 74 добавлений и 128 удалений

5
storage/.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,5 @@
{
"extends": [
"../toolkit/.eslintrc"
]
}

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

@ -1,7 +1,3 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This file tests SQLITE_FCNTL_CHUNK_SIZE behaves as expected
function run_sql(d, sql) {
@ -10,8 +6,7 @@ function run_sql(d, sql) {
stmt.finalize();
}
function new_file(name)
{
function new_file(name) {
var file = dirSvc.get("ProfD", Ci.nsIFile);
file.append(name);
return file;
@ -21,14 +16,16 @@ function get_size(name) {
return new_file(name).fileSize
}
function run_test()
{
function run_test() {
const filename = "chunked.sqlite";
const CHUNK_SIZE = 512 * 1024;
var d = getDatabase(new_file(filename));
try {
d.setGrowthIncrement(CHUNK_SIZE, "");
} catch (e if e.result == Cr.NS_ERROR_FILE_TOO_BIG) {
} catch (e) {
if (e.result != Cr.NS_ERROR_FILE_TOO_BIG) {
throw e;
}
print("Too little free space to set CHUNK_SIZE!");
return;
}

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

@ -12,8 +12,7 @@ const TEXT = "this is test text";
const REAL = 3.23;
const BLOB = [1, 2];
function test_create_and_add()
{
add_test(function test_create_and_add() {
getOpenedDatabase().executeSimpleSQL(
"CREATE TABLE test (" +
"id INTEGER, " +
@ -96,10 +95,9 @@ function test_create_and_add()
});
stmts[0].finalize();
stmts[1].finalize();
}
});
function test_multiple_bindings_on_statements()
{
add_test(function test_multiple_bindings_on_statements() {
// This tests to make sure that we pass all the statements multiply bound
// parameters when we call executeAsync.
const AMOUNT_TO_ADD = 5;
@ -176,10 +174,9 @@ function test_multiple_bindings_on_statements()
}
});
stmts.forEach(stmt => stmt.finalize());
}
});
function test_asyncClose_does_not_complete_before_statements()
{
add_test(function test_asyncClose_does_not_complete_before_statements() {
let stmt = createStatement("SELECT * FROM sqlite_master");
let executed = false;
stmt.executeAsync({
@ -210,19 +207,17 @@ function test_asyncClose_does_not_complete_before_statements()
gDBConn = null;
run_next_test();
});
}
});
function test_asyncClose_does_not_throw_no_callback()
{
add_test(function test_asyncClose_does_not_throw_no_callback() {
getOpenedDatabase().asyncClose();
// Reset gDBConn so that later tests will get a new connection object.
gDBConn = null;
run_next_test();
}
});
function test_double_asyncClose_throws()
{
add_test(function test_double_asyncClose_throws() {
let conn = getOpenedDatabase();
conn.asyncClose();
try {
@ -230,28 +225,18 @@ function test_double_asyncClose_throws()
do_throw("should have thrown");
// There is a small race condition here, which can cause either of
// Cr.NS_ERROR_NOT_INITIALIZED or Cr.NS_ERROR_UNEXPECTED to be thrown.
} catch (e if "result" in e && e.result == Cr.NS_ERROR_NOT_INITIALIZED) {
do_print("NS_ERROR_NOT_INITIALIZED");
} catch (e if "result" in e && e.result == Cr.NS_ERROR_UNEXPECTED) {
do_print("NS_ERROR_UNEXPECTED");
} catch (e) {
if ("result" in e && e.result == Cr.NS_ERROR_NOT_INITIALIZED) {
do_print("NS_ERROR_NOT_INITIALIZED");
} else if ("result" in e && e.result == Cr.NS_ERROR_UNEXPECTED) {
do_print("NS_ERROR_UNEXPECTED");
}
}
// Reset gDBConn so that later tests will get a new connection object.
gDBConn = null;
run_next_test();
}
////////////////////////////////////////////////////////////////////////////////
//// Test Runner
[
test_create_and_add,
test_multiple_bindings_on_statements,
test_asyncClose_does_not_complete_before_statements,
test_asyncClose_does_not_throw_no_callback,
test_double_asyncClose_throws,
].forEach(add_test);
});
function run_test()
{

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

@ -55,7 +55,7 @@ function executeSimpleSQLAsync(db, query, onResult) {
return deferred.promise;
}
add_task(function test_create_and_add() {
add_task(function* test_create_and_add() {
let adb = yield openAsyncDatabase(getTestDB());
let completion = yield executeSimpleSQLAsync(adb,
@ -97,7 +97,7 @@ add_task(function test_create_and_add() {
});
add_task(function test_asyncClose_does_not_complete_before_statement() {
add_task(function* test_asyncClose_does_not_complete_before_statement() {
let adb = yield openAsyncDatabase(getTestDB());
let executed = false;
@ -121,11 +121,3 @@ add_task(function test_asyncClose_does_not_complete_before_statement() {
yield asyncClose(adb);
});
////////////////////////////////////////////////////////////////////////////////
//// Test Runner
function run_test()
{
run_next_test();
}

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

@ -69,8 +69,7 @@ function executeAsync(statement, onResult) {
return deferred.promise;
}
add_task(function test_connectionReady_open()
{
add_task(function* test_connectionReady_open() {
// there doesn't seem to be a way for the connection to not be ready (unless
// we close it with mozIStorageConnection::Close(), but we don't for this).
// It can only fail if GetPath fails on the database file, or if we run out
@ -80,8 +79,7 @@ add_task(function test_connectionReady_open()
do_check_true(msc.connectionReady);
});
add_task(function test_connectionReady_closed()
{
add_task(function* test_connectionReady_closed() {
// This also tests mozIStorageConnection::Close()
var msc = getOpenedDatabase();
@ -90,26 +88,22 @@ add_task(function test_connectionReady_closed()
gDBConn = null; // this is so later tests don't start to fail.
});
add_task(function test_databaseFile()
{
add_task(function* test_databaseFile() {
var msc = getOpenedDatabase();
do_check_true(getTestDB().equals(msc.databaseFile));
});
add_task(function test_tableExists_not_created()
{
add_task(function* test_tableExists_not_created() {
var msc = getOpenedDatabase();
do_check_false(msc.tableExists("foo"));
});
add_task(function test_indexExists_not_created()
{
add_task(function* test_indexExists_not_created() {
var msc = getOpenedDatabase();
do_check_false(msc.indexExists("foo"));
});
add_task(function test_temp_tableExists_and_indexExists()
{
add_task(function* test_temp_tableExists_and_indexExists() {
var msc = getOpenedDatabase();
msc.executeSimpleSQL("CREATE TEMP TABLE test_temp(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");
do_check_true(msc.tableExists("test_temp"));
@ -121,22 +115,19 @@ add_task(function test_temp_tableExists_and_indexExists()
msc.executeSimpleSQL("DROP TABLE test_temp");
});
add_task(function test_createTable_not_created()
{
add_task(function* test_createTable_not_created() {
var msc = getOpenedDatabase();
msc.createTable("test", "id INTEGER PRIMARY KEY, name TEXT");
do_check_true(msc.tableExists("test"));
});
add_task(function test_indexExists_created()
{
add_task(function* test_indexExists_created() {
var msc = getOpenedDatabase();
msc.executeSimpleSQL("CREATE INDEX name_ind ON test (name)");
do_check_true(msc.indexExists("name_ind"));
});
add_task(function test_createTable_already_created()
{
add_task(function* test_createTable_already_created() {
var msc = getOpenedDatabase();
do_check_true(msc.tableExists("test"));
try {
@ -147,8 +138,7 @@ add_task(function test_createTable_already_created()
}
});
add_task(function test_attach_createTable_tableExists_indexExists()
{
add_task(function* test_attach_createTable_tableExists_indexExists() {
var msc = getOpenedDatabase();
var file = do_get_file("storage_attach.sqlite", true);
var msc2 = getDatabase(file);
@ -160,7 +150,10 @@ add_task(function test_attach_createTable_tableExists_indexExists()
try {
msc.createTable("sample.test", "id INTEGER PRIMARY KEY, name TEXT");
do_throw("We shouldn't get here!");
} catch (e if e.result == Components.results.NS_ERROR_FAILURE) {
} catch (e) {
if (e.result != Components.results.NS_ERROR_FAILURE) {
throw e;
}
// we expect to fail because this table should exist already.
}
@ -173,21 +166,18 @@ add_task(function test_attach_createTable_tableExists_indexExists()
try { file.remove(false); } catch(e) { }
});
add_task(function test_lastInsertRowID()
{
add_task(function* test_lastInsertRowID() {
var msc = getOpenedDatabase();
msc.executeSimpleSQL("INSERT INTO test (name) VALUES ('foo')");
do_check_eq(1, msc.lastInsertRowID);
});
add_task(function test_transactionInProgress_no()
{
add_task(function* test_transactionInProgress_no() {
var msc = getOpenedDatabase();
do_check_false(msc.transactionInProgress);
});
add_task(function test_transactionInProgress_yes()
{
add_task(function* test_transactionInProgress_yes() {
var msc = getOpenedDatabase();
msc.beginTransaction();
do_check_true(msc.transactionInProgress);
@ -200,8 +190,7 @@ add_task(function test_transactionInProgress_yes()
do_check_false(msc.transactionInProgress);
});
add_task(function test_commitTransaction_no_transaction()
{
add_task(function* test_commitTransaction_no_transaction() {
var msc = getOpenedDatabase();
do_check_false(msc.transactionInProgress);
try {
@ -212,8 +201,7 @@ add_task(function test_commitTransaction_no_transaction()
}
});
add_task(function test_rollbackTransaction_no_transaction()
{
add_task(function* test_rollbackTransaction_no_transaction() {
var msc = getOpenedDatabase();
do_check_false(msc.transactionInProgress);
try {
@ -224,36 +212,32 @@ add_task(function test_rollbackTransaction_no_transaction()
}
});
add_task(function test_get_schemaVersion_not_set()
{
add_task(function* test_get_schemaVersion_not_set() {
do_check_eq(0, getOpenedDatabase().schemaVersion);
});
add_task(function test_set_schemaVersion()
{
add_task(function* test_set_schemaVersion() {
var msc = getOpenedDatabase();
const version = 1;
msc.schemaVersion = version;
do_check_eq(version, msc.schemaVersion);
});
add_task(function test_set_schemaVersion_same()
{
add_task(function* test_set_schemaVersion_same() {
var msc = getOpenedDatabase();
const version = 1;
msc.schemaVersion = version; // should still work ok
do_check_eq(version, msc.schemaVersion);
});
add_task(function test_set_schemaVersion_negative()
{
add_task(function* test_set_schemaVersion_negative() {
var msc = getOpenedDatabase();
const version = -1;
msc.schemaVersion = version;
do_check_eq(version, msc.schemaVersion);
});
add_task(function test_createTable(){
add_task(function* test_createTable(){
var temp = getTestDB().parent;
temp.append("test_db_table");
try {
@ -272,8 +256,7 @@ add_task(function test_createTable(){
}
});
add_task(function test_defaultSynchronousAtNormal()
{
add_task(function* test_defaultSynchronousAtNormal() {
var msc = getOpenedDatabase();
var stmt = createStatement("PRAGMA synchronous;");
try {
@ -287,8 +270,7 @@ add_task(function test_defaultSynchronousAtNormal()
});
// must be ran before executeAsync tests
add_task(function test_close_does_not_spin_event_loop()
{
add_task(function* test_close_does_not_spin_event_loop() {
// We want to make sure that the event loop on the calling thread does not
// spin when close is called.
let event = {
@ -315,8 +297,7 @@ add_task(function test_close_does_not_spin_event_loop()
gDBConn = null;
});
add_task(function test_asyncClose_succeeds_with_finalized_async_statement()
{
add_task(function* test_asyncClose_succeeds_with_finalized_async_statement() {
// XXX this test isn't perfect since we can't totally control when events will
// run. If this paticular function fails randomly, it means we have a
// real bug.
@ -333,7 +314,7 @@ add_task(function test_asyncClose_succeeds_with_finalized_async_statement()
gDBConn = null;
});
add_task(function test_close_then_release_statement() {
add_task(function* test_close_then_release_statement() {
// Testing the behavior in presence of a bad client that finalizes
// statements after the database has been closed (typically by
// letting the gc finalize the statement).
@ -346,7 +327,7 @@ add_task(function test_close_then_release_statement() {
gDBConn = null;
});
add_task(function test_asyncClose_then_release_statement() {
add_task(function* test_asyncClose_then_release_statement() {
// Testing the behavior in presence of a bad client that finalizes
// statements after the database has been async closed (typically by
// letting the gc finalize the statement).
@ -359,8 +340,7 @@ add_task(function test_asyncClose_then_release_statement() {
gDBConn = null;
});
add_task(function test_close_fails_with_async_statement_ran()
{
add_task(function* test_close_fails_with_async_statement_ran() {
let deferred = Promise.defer();
let stmt = createStatement("SELECT * FROM test");
stmt.executeAsync();
@ -385,8 +365,7 @@ add_task(function test_close_fails_with_async_statement_ran()
yield deferred.promise;
});
add_task(function test_clone_optional_param()
{
add_task(function* test_clone_optional_param() {
let db1 = getService().openUnsharedDatabase(getTestDB());
let db2 = db1.clone();
do_check_true(db2.connectionReady);
@ -409,7 +388,7 @@ add_task(function test_clone_optional_param()
db2.close();
});
function standardAsyncTest(promisedDB, name, shouldInit = false) {
function* standardAsyncTest(promisedDB, name, shouldInit = false) {
do_print("Performing standard async test " + name);
let adb = yield promisedDB;
@ -451,7 +430,7 @@ function standardAsyncTest(promisedDB, name, shouldInit = false) {
do_print("Standard async test " + name + " complete");
}
add_task(function test_open_async() {
add_task(function* test_open_async() {
yield standardAsyncTest(openAsyncDatabase(getTestDB(), null), "default");
yield standardAsyncTest(openAsyncDatabase(getTestDB()), "no optional arg");
yield standardAsyncTest(openAsyncDatabase(getTestDB(),
@ -492,7 +471,7 @@ add_task(function test_open_async() {
});
add_task(function test_async_open_with_shared_cache() {
add_task(function* test_async_open_with_shared_cache() {
do_print("Testing that opening with a shared cache doesn't break stuff");
let adb = yield openAsyncDatabase(getTestDB(), {shared: true});
@ -520,8 +499,7 @@ add_task(function test_async_open_with_shared_cache() {
yield asyncClose(adb);
});
add_task(function test_clone_trivial_async()
{
add_task(function* test_clone_trivial_async() {
let db1 = getService().openDatabase(getTestDB());
do_print("Opened adb1");
do_check_true(db1 instanceof Ci.mozIStorageAsyncConnection);
@ -533,8 +511,7 @@ add_task(function test_clone_trivial_async()
yield asyncClose(adb2);
});
add_task(function test_clone_no_optional_param_async()
{
add_task(function* test_clone_no_optional_param_async() {
"use strict";
do_print("Testing async cloning");
let adb1 = yield openAsyncDatabase(getTestDB(), null);
@ -580,8 +557,7 @@ add_task(function test_clone_no_optional_param_async()
do_print("Second db closed");
});
add_task(function test_clone_readonly()
{
add_task(function* test_clone_readonly() {
let db1 = getService().openUnsharedDatabase(getTestDB());
let db2 = db1.clone(true);
do_check_true(db2.connectionReady);
@ -601,8 +577,7 @@ add_task(function test_clone_readonly()
db2.close();
});
add_task(function test_clone_shared_readonly()
{
add_task(function* test_clone_shared_readonly() {
let db1 = getService().openDatabase(getTestDB());
let db2 = db1.clone(true);
do_check_true(db2.connectionReady);
@ -626,8 +601,7 @@ add_task(function test_clone_shared_readonly()
db2.close();
});
add_task(function test_close_clone_fails()
{
add_task(function* test_close_clone_fails() {
let calls = [
"openDatabase",
"openUnsharedDatabase",
@ -639,15 +613,13 @@ add_task(function test_close_clone_fails()
});
});
add_task(function test_memory_clone_fails()
{
add_task(function* test_memory_clone_fails() {
let db = getService().openSpecialDatabase("memory");
db.close();
expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone());
});
add_task(function test_clone_copies_functions()
{
add_task(function* test_clone_copies_functions() {
const FUNC_NAME = "test_func";
let calls = [
"openDatabase",
@ -680,8 +652,7 @@ add_task(function test_clone_copies_functions()
});
});
add_task(function test_clone_copies_overridden_functions()
{
add_task(function* test_clone_copies_overridden_functions() {
const FUNC_NAME = "lower";
function test_func() {
this.called = false;
@ -726,8 +697,7 @@ add_task(function test_clone_copies_overridden_functions()
});
});
add_task(function test_clone_copies_pragmas()
{
add_task(function* test_clone_copies_pragmas() {
const PRAGMAS = [
{ name: "cache_size", value: 500, copied: true },
{ name: "temp_store", value: 2, copied: true },
@ -769,8 +739,7 @@ add_task(function test_clone_copies_pragmas()
db2.close();
});
add_task(function test_readonly_clone_copies_pragmas()
{
add_task(function* test_readonly_clone_copies_pragmas() {
const PRAGMAS = [
{ name: "cache_size", value: 500, copied: true },
{ name: "temp_store", value: 2, copied: true },
@ -812,8 +781,7 @@ add_task(function test_readonly_clone_copies_pragmas()
db2.close();
});
add_task(function test_getInterface()
{
add_task(function* test_getInterface() {
let db = getOpenedDatabase();
let target = db.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEventTarget);
@ -826,7 +794,6 @@ add_task(function test_getInterface()
});
function run_test()
{
function run_test() {
run_next_test();
}