OLD | NEW |
| (Empty) |
1 var throwOnToStringObject = { }; | |
2 throwOnToStringObject.toString = function () { throw "Cannot call toString on th
is object." }; | |
3 | |
4 var throwOnGetLengthObject = { }; | |
5 throwOnGetLengthObject.__defineGetter__("length", function () { throw "Cannot ge
t length of this object."; }); | |
6 | |
7 var throwOnGetZeroObject = { length: 1 }; | |
8 throwOnGetZeroObject.__defineGetter__("0", function () { throw "Cannot get 0 pro
perty of this object."; }); | |
9 | |
10 var expectNoException = [ | |
11 '""', | |
12 '"", null', | |
13 '"", undefined', | |
14 '"", []', | |
15 '"", [ "arg0" ]', | |
16 '"", { }', | |
17 '"", { length: 0 }', | |
18 '"", { length: 1, 0: "arg0" }', | |
19 ]; | |
20 | |
21 var expectException = [ | |
22 '', | |
23 'null', | |
24 'undefined', | |
25 '0', | |
26 'throwOnToStringObject', | |
27 '"", throwOnGetLengthObject', | |
28 '"", throwOnGetZeroObject', | |
29 '"", [ throwOnToStringObject ]', | |
30 '"", 0', | |
31 '"", ""', | |
32 ]; | |
33 | |
34 function tryExecuteSql(transaction, parameterList) | |
35 { | |
36 try { | |
37 eval('transaction.executeSql(' + parameterList + ')'); | |
38 return null; | |
39 } catch (exception) { | |
40 return exception; | |
41 } | |
42 } | |
43 | |
44 function runTransactionTest(transaction, parameterList, expectException) | |
45 { | |
46 var exception = tryExecuteSql(transaction, parameterList); | |
47 if (expectException) { | |
48 if (exception) | |
49 postMessage("PASS: executeSql(" + parameterList + ") threw an except
ion as expected."); | |
50 else | |
51 postMessage("FAIL: executeSql(" + parameterList + ") did not throw a
n exception."); | |
52 } else { | |
53 if (exception) | |
54 postMessage("FAIL: executeSql(" + parameterList + ") threw an except
ion: " + exception); | |
55 else | |
56 postMessage("PASS: executeSql(" + parameterList + ") did not throw a
n exception."); | |
57 } | |
58 } | |
59 | |
60 function runTransactionTests(transaction) | |
61 { | |
62 for (i in expectNoException) | |
63 runTransactionTest(transaction, expectNoException[i], false); | |
64 for (i in expectException) | |
65 runTransactionTest(transaction, expectException[i], true); | |
66 } | |
67 | |
68 var db = openDatabaseSync("ExecuteSQLArgsTest", "1.0", "Test of handling of the
arguments to SQLTransactionSync.executeSql", 1); | |
69 db.transaction(runTransactionTests); | |
70 postMessage("done"); | |
OLD | NEW |