• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<script>
4var database1 = null;
5var database2 = null;
6var database3 = null;
7
8function log(message)
9{
10    document.getElementById("console").innerHTML += message + "<br>";
11}
12
13function finishTest()
14{
15    log("Test Complete");
16    if (window.layoutTestController)
17        layoutTestController.notifyDone();
18}
19
20function statementErrorFunction(tx, error)
21{
22    log("Unexpected exception - " + error.message);
23    finishTest();
24}
25
26function transactionErrorFunction(db, error)
27{
28    // We only expect an error message for database2
29    if (db == database2) {
30        log("Expected quota exception - " + error.message);
31        checkCompletion(db);
32    } else {
33        log("Unexpected exception - " + error.message);
34        finishTest();
35    }
36}
37
38function checkCompletion(db)
39{
40    log("Done adding data");
41
42    if (database3) {
43        finishTest();
44    } else if (database2) {
45        database3 = openDatabase("QuotaManagementDatabase3", "1.0", "Test for quota management <rdar://5628468>", 1);
46        testDatabase(database3);
47    } else {
48        database2 = openDatabase("QuotaManagementDatabase2", "1.0", "Test for quota management <rdar://5628468>", 1);
49        testDatabase(database2);
50    }
51}
52
53function addData(db)
54{
55    db.transaction(function(tx) {
56        log("Inserting some data");
57        tx.executeSql("INSERT INTO DataTest (randomData) VALUES (ZEROBLOB(17408))", [],
58                      function(tx, result) { }, statementErrorFunction);
59        if (db == database2) {
60            // Try to run this statement on 'database2' only.
61            // It should not be run, because the previous statement should've
62            // resulted in a failure that made sqlite roll back the entire transaction.
63            tx.executeSql("INSERT INTO DataTest (randomData) VALUES (ZEROBLOB(10))", [],
64                          function(tx, result) {
65                              log("This statement should not have been run.");
66                              finishTest();
67                          }, statementErrorFunction);
68        }
69    }, function(error) {
70        transactionErrorFunction(db, error);
71    }, function() {
72        checkCompletion(db);
73    });
74}
75
76function testDatabase(db)
77{
78    db.transaction(function(tx) {
79        log("Adding a table");
80        tx.executeSql("CREATE TABLE DataTest (randomData)", [],
81                      function(tx, result) { }, statementErrorFunction);
82    }, function(error) {
83        transactionErrorFunction(db, error);
84    }, function() {
85        addData(db);
86    });
87}
88
89function runTest()
90{
91    if (window.layoutTestController) {
92        layoutTestController.clearAllDatabases();
93        layoutTestController.dumpDatabaseCallbacks();
94        layoutTestController.setDatabaseQuota(40960);
95        layoutTestController.dumpAsText();
96        layoutTestController.waitUntilDone();
97    }
98
99    database1 = openDatabase("QuotaManagementDatabase1", "1.0", "Test for quota management <rdar://5628468>", 1);
100    testDatabase(database1);
101}
102
103</script>
104</head>
105
106<body onload="runTest()">
107This test checks to make sure that quotas are enforced per-origin instead of per-database, as they were prior to http://trac.webkit.org/projects/webkit/changeset/29983.<br>
108The test clears all databases, sets the quota for the origin to 40k, then tries to insert 17k of data into two databases. If things go as planned, the second insert should fail, the UI Delegate should be informed of the exceeded quota and should increase the quota for this origin. Inserting 17k of data the third time should succeed again.
109<pre id="console">
110</pre>
111</body>
112
113</html>
114