Skip to content

Commit

Permalink
Bug 1230549 - Make Storage pass basic eslint. r=yoric
Browse files Browse the repository at this point in the history
--HG--
rename : browser/.eslintrc => storage/.eslintrc
extra : commitid : 5RiWGmPFkg2
extra : rebase_source : 54b8a2e9680c37d88c0a501d85422163f4e04fea
  • Loading branch information
mak77 committed Dec 4, 2015
1 parent b729a30 commit 4190a83
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 128 deletions.
5 changes: 5 additions & 0 deletions storage/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"../toolkit/.eslintrc"
]
}
15 changes: 6 additions & 9 deletions storage/test/unit/test_chunk_growth.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
45 changes: 15 additions & 30 deletions storage/test/unit/test_connection_executeAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, " +
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -210,48 +207,36 @@ 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 {
conn.asyncClose();
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()
{
Expand Down
12 changes: 2 additions & 10 deletions storage/test/unit/test_connection_executeSimpleSQLAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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();
}
Loading

0 comments on commit 4190a83

Please sign in to comment.