storage/test/unit/test_js_helpers.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/storage/test/unit/test_js_helpers.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=2 sts=2 et : */
     1.6 +/**
     1.7 + * Any copyright is dedicated to the Public Domain.
     1.8 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.9 + */
    1.10 +
    1.11 +/**
    1.12 + * This file tests that the JS language helpers in various ways.
    1.13 + */
    1.14 +
    1.15 +////////////////////////////////////////////////////////////////////////////////
    1.16 +//// Test Functions
    1.17 +
    1.18 +function test_params_enumerate()
    1.19 +{
    1.20 +  let stmt = createStatement(
    1.21 +    "SELECT * FROM test WHERE id IN (:a, :b, :c)"
    1.22 +  );
    1.23 +
    1.24 +  // Make sure they are right.
    1.25 +  let expected = ["a", "b", "c"];
    1.26 +  let index = 0;
    1.27 +  for (let name in stmt.params)
    1.28 +    do_check_eq(name, expected[index++]);
    1.29 +}
    1.30 +
    1.31 +function test_params_prototype()
    1.32 +{
    1.33 +  let stmt = createStatement(
    1.34 +    "SELECT * FROM sqlite_master"
    1.35 +  );
    1.36 +
    1.37 +  // Set a property on the prototype and make sure it exist (will not be a
    1.38 +  // bindable parameter, however).
    1.39 +  Object.getPrototypeOf(stmt.params).test = 2;
    1.40 +  do_check_eq(stmt.params.test, 2);
    1.41 +  stmt.finalize();
    1.42 +}
    1.43 +
    1.44 +function test_row_prototype()
    1.45 +{
    1.46 +  let stmt = createStatement(
    1.47 +    "SELECT * FROM sqlite_master"
    1.48 +  );
    1.49 +
    1.50 +  do_check_true(stmt.executeStep());
    1.51 +
    1.52 +  // Set a property on the prototype and make sure it exists (will not be in the
    1.53 +  // results, however).
    1.54 +  Object.getPrototypeOf(stmt.row).test = 2;
    1.55 +  do_check_eq(stmt.row.test, 2);
    1.56 +
    1.57 +  // Clean up after ourselves.
    1.58 +  delete Object.getPrototypeOf(stmt.row).test;
    1.59 +  stmt.finalize();
    1.60 +}
    1.61 +
    1.62 +function test_params_gets_sync()
    1.63 +{
    1.64 +  // Added for bug 562866.
    1.65 +  /*
    1.66 +  let stmt = createStatement(
    1.67 +    "SELECT * FROM test WHERE id IN (:a, :b, :c)"
    1.68 +  );
    1.69 +
    1.70 +  // Make sure we do not assert in getting the value.
    1.71 +  let originalCount = Object.getOwnPropertyNames(stmt.params).length;
    1.72 +  let expected = ["a", "b", "c"];
    1.73 +  for each (let name in expected) {
    1.74 +    stmt.params[name];
    1.75 +  }
    1.76 +
    1.77 +  // Now make sure we didn't magically get any additional properties.
    1.78 +  let finalCount = Object.getOwnPropertyNames(stmt.params).length;
    1.79 +  do_check_eq(originalCount + expected.length, finalCount);
    1.80 +  */
    1.81 +}
    1.82 +
    1.83 +function test_params_gets_async()
    1.84 +{
    1.85 +  // Added for bug 562866.
    1.86 +  /*
    1.87 +  let stmt = createAsyncStatement(
    1.88 +    "SELECT * FROM test WHERE id IN (:a, :b, :c)"
    1.89 +  );
    1.90 +
    1.91 +  // Make sure we do not assert in getting the value.
    1.92 +  let originalCount = Object.getOwnPropertyNames(stmt.params).length;
    1.93 +  let expected = ["a", "b", "c"];
    1.94 +  for each (let name in expected) {
    1.95 +    stmt.params[name];
    1.96 +  }
    1.97 +
    1.98 +  // Now make sure we didn't magically get any additional properties.
    1.99 +  let finalCount = Object.getOwnPropertyNames(stmt.params).length;
   1.100 +  do_check_eq(originalCount + expected.length, finalCount);
   1.101 +  */
   1.102 +}
   1.103 +
   1.104 +////////////////////////////////////////////////////////////////////////////////
   1.105 +//// Test Runner
   1.106 +
   1.107 +let tests = [
   1.108 +  test_params_enumerate,
   1.109 +  test_params_prototype,
   1.110 +  test_row_prototype,
   1.111 +  test_params_gets_sync,
   1.112 +  test_params_gets_async,
   1.113 +];
   1.114 +function run_test()
   1.115 +{
   1.116 +  cleanup();
   1.117 +
   1.118 +  // Create our database.
   1.119 +  getOpenedDatabase().executeSimpleSQL(
   1.120 +    "CREATE TABLE test (" +
   1.121 +      "id INTEGER PRIMARY KEY " +
   1.122 +    ")"
   1.123 +  );
   1.124 +
   1.125 +  // Run the tests.
   1.126 +  tests.forEach(function(test) test());
   1.127 +}

mercurial