storage/test/unit/test_chunk_growth.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // This file tests SQLITE_FCNTL_CHUNK_SIZE behaves as expected
michael@0 6
michael@0 7 function run_sql(d, sql) {
michael@0 8 var stmt = d.createStatement(sql)
michael@0 9 stmt.execute()
michael@0 10 stmt.finalize();
michael@0 11 }
michael@0 12
michael@0 13 function new_file(name)
michael@0 14 {
michael@0 15 var file = dirSvc.get("ProfD", Ci.nsIFile);
michael@0 16 file.append(name);
michael@0 17 return file;
michael@0 18 }
michael@0 19
michael@0 20 function get_size(name) {
michael@0 21 return new_file(name).fileSize
michael@0 22 }
michael@0 23
michael@0 24 function run_test()
michael@0 25 {
michael@0 26 const filename = "chunked.sqlite";
michael@0 27 const CHUNK_SIZE = 512 * 1024;
michael@0 28 var d = getDatabase(new_file(filename));
michael@0 29 try {
michael@0 30 d.setGrowthIncrement(CHUNK_SIZE, "");
michael@0 31 } catch (e if e.result == Cr.NS_ERROR_FILE_TOO_BIG) {
michael@0 32 print("Too little free space to set CHUNK_SIZE!");
michael@0 33 return;
michael@0 34 }
michael@0 35 run_sql(d, "CREATE TABLE bloat(data varchar)");
michael@0 36
michael@0 37 var orig_size = get_size(filename);
michael@0 38 /* Dump in at least 32K worth of data.
michael@0 39 * While writing ensure that the file size growth in chunksize set above.
michael@0 40 */
michael@0 41 const str1024 = new Array(1024).join("T");
michael@0 42 for(var i = 0; i < 32; i++) {
michael@0 43 run_sql(d, "INSERT INTO bloat VALUES('" + str1024 + "')");
michael@0 44 var size = get_size(filename)
michael@0 45 // Must not grow in small increments.
michael@0 46 do_check_true(size == orig_size || size >= CHUNK_SIZE);
michael@0 47 }
michael@0 48 /* In addition to growing in chunk-size increments, the db
michael@0 49 * should shrink in chunk-size increments too.
michael@0 50 */
michael@0 51 run_sql(d, "DELETE FROM bloat")
michael@0 52 run_sql(d, "VACUUM")
michael@0 53 do_check_true(get_size(filename) >= CHUNK_SIZE)
michael@0 54 }
michael@0 55

mercurial