gecko/storage/test/unit/test_sqlite_secure_delete.js
Jim Blandy 4d6a633bba Bug 914753: Make Emacs file variable header lines correct, or at least consistent. DONTBUILD r=ehsan
The -*- file variable lines -*- establish per-file settings that Emacs will
pick up. This patch makes the following changes to those lines (and touches
nothing else):

 - Never set the buffer's mode.

   Years ago, Emacs did not have a good JavaScript mode, so it made sense
   to use Java or C++ mode in .js files. However, Emacs has had js-mode for
   years now; it's perfectly serviceable, and is available and enabled by
   default in all major Emacs packagings.

   Selecting a mode in the -*- file variable line -*- is almost always the
   wrong thing to do anyway. It overrides Emacs's default choice, which is
   (now) reasonable; and even worse, it overrides settings the user might
   have made in their '.emacs' file for that file extension. It's only
   useful when there's something specific about that particular file that
   makes a particular mode appropriate.

 - Correctly propagate settings that establish the correct indentation
   level for this file: c-basic-offset and js2-basic-offset should be
   js-indent-level. Whatever value they're given should be preserved;
   different parts of our tree use different indentation styles.

 - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil.
   Remove tab-width: settings, at least in files that don't contain tab
   characters.

 - Remove js2-mode settings that belong in the user's .emacs file, like
   js2-skip-preprocessor-directives.
2014-06-24 22:12:07 -07:00

91 lines
2.4 KiB
JavaScript

/*-*- indent-tabs-mode: nil; js-indent-level: 2 -*-
*vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This file tests to make sure that SQLite was compiled with
* SQLITE_SECURE_DELETE=1.
*/
////////////////////////////////////////////////////////////////////////////////
//// Helper Methods
/**
* Reads the contents of a file and returns it as a string.
*
* @param aFile
* The file to return from.
* @return the contents of the file in the form of a string.
*/
function getFileContents(aFile)
{
let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
fstream.init(aFile, -1, 0, 0);
let bstream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
bstream.setInputStream(fstream);
return bstream.readBytes(bstream.available());
}
////////////////////////////////////////////////////////////////////////////////
//// Tests
function test_delete_removes_data()
{
const TEST_STRING = "SomeRandomStringToFind";
let file = getTestDB();
let db = getService().openDatabase(file);
// Create the table and insert the data.
db.createTable("test", "data TEXT");
let stmt = db.createStatement("INSERT INTO test VALUES(:data)");
stmt.params.data = TEST_STRING;
try {
stmt.execute();
}
finally {
stmt.finalize();
}
// Make sure this test is actually testing what it thinks by making sure the
// string shows up in the database. Because the previous statement was
// automatically wrapped in a transaction, the contents are already on disk.
let contents = getFileContents(file);
do_check_neq(-1, contents.indexOf(TEST_STRING));
// Delete the data, and then close the database.
stmt = db.createStatement("DELETE FROM test WHERE data = :data");
stmt.params.data = TEST_STRING;
try {
stmt.execute();
}
finally {
stmt.finalize();
}
db.close();
// Check the file to see if the string can be found.
contents = getFileContents(file);
do_check_eq(-1, contents.indexOf(TEST_STRING));
run_next_test();
}
////////////////////////////////////////////////////////////////////////////////
//// Test Runner
[
test_delete_removes_data,
].forEach(add_test);
function run_test()
{
cleanup();
run_next_test();
}