Home | History | Annotate | Download | only in storage
      1 <html>
      2 
      3 <head>
      4 <script>
      5 
      6 var throwOnToStringObject = { };
      7 throwOnToStringObject.toString = function () { throw "Cannot call toString on this object." };
      8 
      9 var throwOnGetLengthObject = { };
     10 throwOnGetLengthObject.__defineGetter__("length", function () { throw "Cannot get length of this object."; });
     11 
     12 var throwOnGetZeroObject = { length: 1 };
     13 throwOnGetZeroObject.__defineGetter__("0", function () { throw "Cannot get 0 property of this object."; });
     14 
     15 var expectNoException = [
     16     'null',
     17     'undefined',
     18     '0',
     19     '""',
     20     '"", null',
     21     '"", undefined',
     22     '"", []',
     23     '"", [ "arg0" ]',
     24     '"", { }',
     25     '"", { length: 0 }',
     26     '"", { length: 1, 0: "arg0" }',
     27     '"", null, null',
     28     '"", null, undefined',
     29     '"", null, { }',
     30     '"", null, null, null',
     31     '"", null, null, undefined',
     32     '"", null, null, { }',
     33 ];
     34 
     35 var expectException = [
     36     '',
     37     'throwOnToStringObject',
     38     '"", throwOnGetLengthObject',
     39     '"", throwOnGetZeroObject',
     40     '"", [ throwOnToStringObject ]',
     41     '"", 0',
     42     '"", ""',
     43     '"", null, 0',
     44     '"", null, ""',
     45     '"", null, null, 0',
     46     '"", null, null, ""',
     47 ];
     48 
     49 function writeMessageToLog(message)
     50 {
     51     document.getElementById("console").innerText += message + "\n";
     52 }
     53 
     54 function tryExecuteSql(transaction, parameterList)
     55 {
     56     try {
     57         eval('transaction.executeSql(' + parameterList + ')');
     58         return null;
     59     } catch (exception) {
     60         return exception;
     61     }
     62 }
     63 
     64 function runTransactionTest(transaction, parameterList, expectException)
     65 {
     66     var exception = tryExecuteSql(transaction, parameterList);
     67     if (expectException) {
     68         if (exception)
     69             writeMessageToLog("PASS. executeSql(" + parameterList + ") threw an exception as expected.");
     70         else
     71             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") did not throw an exception");
     72     } else {
     73         if (exception)
     74             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") threw an exception: " + exception);
     75         else
     76             writeMessageToLog("PASS. executeSql(" + parameterList + ") did not throw an exception");
     77     }
     78 }
     79 
     80 function runTransactionTests(transaction)
     81 {
     82     for (i in expectNoException)
     83         runTransactionTest(transaction, expectNoException[i], false);
     84     for (i in expectException)
     85         runTransactionTest(transaction, expectException[i], true);
     86 
     87     if (window.layoutTestController)
     88         layoutTestController.notifyDone();
     89 }
     90 
     91 function runTest()
     92 {
     93     if (window.layoutTestController) {
     94         layoutTestController.dumpAsText();
     95         layoutTestController.waitUntilDone();
     96     }
     97 
     98     var db = openDatabase("ExecuteSQLArgsTest", "1.0", "Test of handling of the arguments to SQLTransaction.executeSql", 1);
     99     db.transaction(runTransactionTests);
    100 }
    101 
    102 </script>
    103 </head>
    104 
    105 <body onload="runTest()">
    106 <pre id="console"></pre>
    107 </body>
    108 
    109 </html>
    110