Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | // This file tests that dbs of various page sizes are using the right cache |
michael@0 | 5 | // size (bug 703113). |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * In order to change the cache size, we must open a DB, change the page |
michael@0 | 9 | * size, create a table, close the DB, then re-open the DB. We then check |
michael@0 | 10 | * the cache size after reopening. |
michael@0 | 11 | * |
michael@0 | 12 | * @param dbOpener |
michael@0 | 13 | * function that opens the DB specified in file |
michael@0 | 14 | * @param file |
michael@0 | 15 | * file holding the database |
michael@0 | 16 | * @param pageSize |
michael@0 | 17 | * the DB's page size |
michael@0 | 18 | * @param expectedCacheSize |
michael@0 | 19 | * the expected cache size for the given page size |
michael@0 | 20 | */ |
michael@0 | 21 | function check_size(dbOpener, file, pageSize, expectedCacheSize) |
michael@0 | 22 | { |
michael@0 | 23 | // Open the DB, immediately change its page size. |
michael@0 | 24 | let db = dbOpener(file); |
michael@0 | 25 | db.executeSimpleSQL("PRAGMA page_size = " + pageSize); |
michael@0 | 26 | |
michael@0 | 27 | // Check the page size change worked. |
michael@0 | 28 | let stmt = db.createStatement("PRAGMA page_size"); |
michael@0 | 29 | do_check_true(stmt.executeStep()); |
michael@0 | 30 | do_check_eq(stmt.row.page_size, pageSize); |
michael@0 | 31 | stmt.finalize(); |
michael@0 | 32 | |
michael@0 | 33 | // Create a simple table. |
michael@0 | 34 | db.executeSimpleSQL("CREATE TABLE test ( id INTEGER PRIMARY KEY )"); |
michael@0 | 35 | |
michael@0 | 36 | // Close and re-open the DB. |
michael@0 | 37 | db.close(); |
michael@0 | 38 | db = dbOpener(file); |
michael@0 | 39 | |
michael@0 | 40 | // Check cache size is as expected. |
michael@0 | 41 | let stmt = db.createStatement("PRAGMA cache_size"); |
michael@0 | 42 | do_check_true(stmt.executeStep()); |
michael@0 | 43 | do_check_eq(stmt.row.cache_size, expectedCacheSize); |
michael@0 | 44 | stmt.finalize(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function new_file(name) |
michael@0 | 48 | { |
michael@0 | 49 | let file = dirSvc.get("ProfD", Ci.nsIFile); |
michael@0 | 50 | file.append(name + ".sqlite"); |
michael@0 | 51 | do_check_false(file.exists()); |
michael@0 | 52 | return file; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function run_test() |
michael@0 | 56 | { |
michael@0 | 57 | const kExpectedCacheSize = -2048; // 2MiB |
michael@0 | 58 | |
michael@0 | 59 | let pageSizes = [ |
michael@0 | 60 | 1024, |
michael@0 | 61 | 4096, |
michael@0 | 62 | 32768, |
michael@0 | 63 | ]; |
michael@0 | 64 | |
michael@0 | 65 | for (let i = 0; i < pageSizes.length; i++) { |
michael@0 | 66 | let pageSize = pageSizes[i]; |
michael@0 | 67 | check_size(getDatabase, |
michael@0 | 68 | new_file("shared" + pageSize), pageSize, kExpectedCacheSize); |
michael@0 | 69 | check_size(getService().openUnsharedDatabase, |
michael@0 | 70 | new_file("unshared" + pageSize), pageSize, kExpectedCacheSize); |
michael@0 | 71 | } |
michael@0 | 72 | } |