summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/executesql-accepts-only-one-statement.html
blob: a3860c89925f2fcdb10636fe7c623ac83b13602a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<script>

var TOTAL_STATEMENTS = 8;
var statements = 0;
var db = null;

function log(message)
{
    document.body.innerText += message + "\n";
}

function terminateTest()
{
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function executeStatement(expectedToPass, statement)
{
    db.transaction(function(tx) {
        tx.executeSql(statement, [],
            function(tx, data) {
                if (!expectedToPass) {
                    log("Statement " + statement + " was expected to fail, but passed.");
                    terminateTest();
                }
                if (++statements == TOTAL_STATEMENTS) {
                    log("Test passed.");
                    terminateTest();
                }
            }, function(tx, error) {
                if (expectedToPass) {
                    log("Statement " + statement + " was expected to pass, but failed.");
                    terminateTest();
                }
                if (++statements == TOTAL_STATEMENTS) {
                    log("Test passed.");
                    terminateTest();
                }
            });
    });
}

function runTest()
{
    if (window.layoutTestController) {
        layoutTestController.clearAllDatabases();
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }

    db = openDatabase("ExecuteSQLAcceptsOnlyOneStatementTest", "1.0", "", 1);
    db.transaction(function(tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
    }, function(error) {
        log("Test failed: " + error.message);
        terminateTest();
    }, function() {
        executeStatement(true, "INSERT INTO Test VALUES (1)");
        executeStatement(true, "INSERT INTO Test VALUES (2);");
        executeStatement(true, "   INSERT INTO Test VALUES (3)    ");
        executeStatement(true, "   INSERT INTO Test VALUES (4);   ");
        executeStatement(true, "INSERT INTO Test VALUES (5)   ;");
        executeStatement(false, "INSERT INTO Test VALUES (6); garbage");
        executeStatement(false, "INSERT INTO Test VALUES (7); INSERT INTO Test VALUES (8)");
        executeStatement(false, "  INSERT INTO Test VALUES (9);   INSERT INTO Test VALUES (10);   ");
    });
}

</script>
</head>
<body onload="runTest();">
This test tests that executeSql() fails when called with a string that has more than one valid statement in it.<br>
</body>
</body>
</html>