Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /*-*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | *vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * This file tests to make sure that SQLite was compiled with |
michael@0 | 9 | * SQLITE_SECURE_DELETE=1. |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 13 | //// Helper Methods |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Reads the contents of a file and returns it as a string. |
michael@0 | 17 | * |
michael@0 | 18 | * @param aFile |
michael@0 | 19 | * The file to return from. |
michael@0 | 20 | * @return the contents of the file in the form of a string. |
michael@0 | 21 | */ |
michael@0 | 22 | function getFileContents(aFile) |
michael@0 | 23 | { |
michael@0 | 24 | let fstream = Cc["@mozilla.org/network/file-input-stream;1"]. |
michael@0 | 25 | createInstance(Ci.nsIFileInputStream); |
michael@0 | 26 | fstream.init(aFile, -1, 0, 0); |
michael@0 | 27 | |
michael@0 | 28 | let bstream = Cc["@mozilla.org/binaryinputstream;1"]. |
michael@0 | 29 | createInstance(Ci.nsIBinaryInputStream); |
michael@0 | 30 | bstream.setInputStream(fstream); |
michael@0 | 31 | return bstream.readBytes(bstream.available()); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 35 | //// Tests |
michael@0 | 36 | |
michael@0 | 37 | function test_delete_removes_data() |
michael@0 | 38 | { |
michael@0 | 39 | const TEST_STRING = "SomeRandomStringToFind"; |
michael@0 | 40 | |
michael@0 | 41 | let file = getTestDB(); |
michael@0 | 42 | let db = getService().openDatabase(file); |
michael@0 | 43 | |
michael@0 | 44 | // Create the table and insert the data. |
michael@0 | 45 | db.createTable("test", "data TEXT"); |
michael@0 | 46 | let stmt = db.createStatement("INSERT INTO test VALUES(:data)"); |
michael@0 | 47 | stmt.params.data = TEST_STRING; |
michael@0 | 48 | try { |
michael@0 | 49 | stmt.execute(); |
michael@0 | 50 | } |
michael@0 | 51 | finally { |
michael@0 | 52 | stmt.finalize(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // Make sure this test is actually testing what it thinks by making sure the |
michael@0 | 56 | // string shows up in the database. Because the previous statement was |
michael@0 | 57 | // automatically wrapped in a transaction, the contents are already on disk. |
michael@0 | 58 | let contents = getFileContents(file); |
michael@0 | 59 | do_check_neq(-1, contents.indexOf(TEST_STRING)); |
michael@0 | 60 | |
michael@0 | 61 | // Delete the data, and then close the database. |
michael@0 | 62 | stmt = db.createStatement("DELETE FROM test WHERE data = :data"); |
michael@0 | 63 | stmt.params.data = TEST_STRING; |
michael@0 | 64 | try { |
michael@0 | 65 | stmt.execute(); |
michael@0 | 66 | } |
michael@0 | 67 | finally { |
michael@0 | 68 | stmt.finalize(); |
michael@0 | 69 | } |
michael@0 | 70 | db.close(); |
michael@0 | 71 | |
michael@0 | 72 | // Check the file to see if the string can be found. |
michael@0 | 73 | contents = getFileContents(file); |
michael@0 | 74 | do_check_eq(-1, contents.indexOf(TEST_STRING)); |
michael@0 | 75 | |
michael@0 | 76 | run_next_test(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 80 | //// Test Runner |
michael@0 | 81 | |
michael@0 | 82 | [ |
michael@0 | 83 | test_delete_removes_data, |
michael@0 | 84 | ].forEach(add_test); |
michael@0 | 85 | |
michael@0 | 86 | function run_test() |
michael@0 | 87 | { |
michael@0 | 88 | cleanup(); |
michael@0 | 89 | run_next_test(); |
michael@0 | 90 | } |