• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var throwOnToStringObject = { };
2throwOnToStringObject.toString = function () { throw "Cannot call toString on this object." };
3
4var throwOnGetLengthObject = { };
5throwOnGetLengthObject.__defineGetter__("length", function () { throw "Cannot get length of this object."; });
6
7var throwOnGetZeroObject = { length: 1 };
8throwOnGetZeroObject.__defineGetter__("0", function () { throw "Cannot get 0 property of this object."; });
9
10var expectNoException = [
11    'null',
12    'undefined',
13    '0',
14    '""',
15    '"", null',
16    '"", undefined',
17    '"", []',
18    '"", [ "arg0" ]',
19    '"", { }',
20    '"", { length: 0 }',
21    '"", { length: 1, 0: "arg0" }',
22    '"", null, null',
23    '"", null, undefined',
24    '"", null, { }',
25    '"", null, null, null',
26    '"", null, null, undefined',
27    '"", null, null, { }',
28];
29
30var expectException = [
31    '',
32    'throwOnToStringObject',
33    '"", throwOnGetLengthObject',
34    '"", throwOnGetZeroObject',
35    '"", [ throwOnToStringObject ]',
36    '"", 0',
37    '"", ""',
38    '"", null, 0',
39    '"", null, ""',
40    '"", null, null, 0',
41    '"", null, null, ""',
42];
43
44function tryExecuteSql(transaction, parameterList)
45{
46    try {
47        eval('transaction.executeSql(' + parameterList + ')');
48        return null;
49    } catch (exception) {
50        return exception;
51    }
52}
53
54function runTransactionTest(transaction, parameterList, expectException)
55{
56    var exception = tryExecuteSql(transaction, parameterList);
57    if (expectException) {
58        if (exception)
59            log("PASS. executeSql(" + parameterList + ") threw an exception as expected.");
60        else
61            log("*FAIL*. executeSql(" + parameterList + ") did not throw an exception");
62    } else {
63        if (exception)
64            log("*FAIL*. executeSql(" + parameterList + ") threw an exception: " + exception);
65        else
66            log("PASS. executeSql(" + parameterList + ") did not throw an exception");
67    }
68}
69
70function runTransactionTests(transaction)
71{
72    for (i in expectNoException)
73        runTransactionTest(transaction, expectNoException[i], false);
74    for (i in expectException)
75        runTransactionTest(transaction, expectException[i], true);
76
77    if (window.layoutTestController)
78        layoutTestController.notifyDone();
79}
80
81function runTest()
82{
83
84    var db = openDatabaseWithSuffix("ExecuteSQLArgsTest", "1.0", "Test of handling of the arguments to SQLTransaction.executeSql", 1);
85    db.transaction(runTransactionTests);
86}
87