storage/test/unit/test_js_helpers.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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: set sw=2 ts=2 sts=2 et : */
michael@0 3 /**
michael@0 4 * Any copyright is dedicated to the Public Domain.
michael@0 5 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 6 */
michael@0 7
michael@0 8 /**
michael@0 9 * This file tests that the JS language helpers in various ways.
michael@0 10 */
michael@0 11
michael@0 12 ////////////////////////////////////////////////////////////////////////////////
michael@0 13 //// Test Functions
michael@0 14
michael@0 15 function test_params_enumerate()
michael@0 16 {
michael@0 17 let stmt = createStatement(
michael@0 18 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
michael@0 19 );
michael@0 20
michael@0 21 // Make sure they are right.
michael@0 22 let expected = ["a", "b", "c"];
michael@0 23 let index = 0;
michael@0 24 for (let name in stmt.params)
michael@0 25 do_check_eq(name, expected[index++]);
michael@0 26 }
michael@0 27
michael@0 28 function test_params_prototype()
michael@0 29 {
michael@0 30 let stmt = createStatement(
michael@0 31 "SELECT * FROM sqlite_master"
michael@0 32 );
michael@0 33
michael@0 34 // Set a property on the prototype and make sure it exist (will not be a
michael@0 35 // bindable parameter, however).
michael@0 36 Object.getPrototypeOf(stmt.params).test = 2;
michael@0 37 do_check_eq(stmt.params.test, 2);
michael@0 38 stmt.finalize();
michael@0 39 }
michael@0 40
michael@0 41 function test_row_prototype()
michael@0 42 {
michael@0 43 let stmt = createStatement(
michael@0 44 "SELECT * FROM sqlite_master"
michael@0 45 );
michael@0 46
michael@0 47 do_check_true(stmt.executeStep());
michael@0 48
michael@0 49 // Set a property on the prototype and make sure it exists (will not be in the
michael@0 50 // results, however).
michael@0 51 Object.getPrototypeOf(stmt.row).test = 2;
michael@0 52 do_check_eq(stmt.row.test, 2);
michael@0 53
michael@0 54 // Clean up after ourselves.
michael@0 55 delete Object.getPrototypeOf(stmt.row).test;
michael@0 56 stmt.finalize();
michael@0 57 }
michael@0 58
michael@0 59 function test_params_gets_sync()
michael@0 60 {
michael@0 61 // Added for bug 562866.
michael@0 62 /*
michael@0 63 let stmt = createStatement(
michael@0 64 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
michael@0 65 );
michael@0 66
michael@0 67 // Make sure we do not assert in getting the value.
michael@0 68 let originalCount = Object.getOwnPropertyNames(stmt.params).length;
michael@0 69 let expected = ["a", "b", "c"];
michael@0 70 for each (let name in expected) {
michael@0 71 stmt.params[name];
michael@0 72 }
michael@0 73
michael@0 74 // Now make sure we didn't magically get any additional properties.
michael@0 75 let finalCount = Object.getOwnPropertyNames(stmt.params).length;
michael@0 76 do_check_eq(originalCount + expected.length, finalCount);
michael@0 77 */
michael@0 78 }
michael@0 79
michael@0 80 function test_params_gets_async()
michael@0 81 {
michael@0 82 // Added for bug 562866.
michael@0 83 /*
michael@0 84 let stmt = createAsyncStatement(
michael@0 85 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
michael@0 86 );
michael@0 87
michael@0 88 // Make sure we do not assert in getting the value.
michael@0 89 let originalCount = Object.getOwnPropertyNames(stmt.params).length;
michael@0 90 let expected = ["a", "b", "c"];
michael@0 91 for each (let name in expected) {
michael@0 92 stmt.params[name];
michael@0 93 }
michael@0 94
michael@0 95 // Now make sure we didn't magically get any additional properties.
michael@0 96 let finalCount = Object.getOwnPropertyNames(stmt.params).length;
michael@0 97 do_check_eq(originalCount + expected.length, finalCount);
michael@0 98 */
michael@0 99 }
michael@0 100
michael@0 101 ////////////////////////////////////////////////////////////////////////////////
michael@0 102 //// Test Runner
michael@0 103
michael@0 104 let tests = [
michael@0 105 test_params_enumerate,
michael@0 106 test_params_prototype,
michael@0 107 test_row_prototype,
michael@0 108 test_params_gets_sync,
michael@0 109 test_params_gets_async,
michael@0 110 ];
michael@0 111 function run_test()
michael@0 112 {
michael@0 113 cleanup();
michael@0 114
michael@0 115 // Create our database.
michael@0 116 getOpenedDatabase().executeSimpleSQL(
michael@0 117 "CREATE TABLE test (" +
michael@0 118 "id INTEGER PRIMARY KEY " +
michael@0 119 ")"
michael@0 120 );
michael@0 121
michael@0 122 // Run the tests.
michael@0 123 tests.forEach(function(test) test());
michael@0 124 }

mercurial