summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/database-quota.html
blob: 038e8d8e5cb162839a85384f56808a651852f963 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>

description("Tests IndexedDB's quota enforcing mechanism.");
if (window.layoutTestController) 
    layoutTestController.waitUntilDone();

function test()
{
    request = evalAndLog("webkitIndexedDB.open('database-quota')");
    request.onsuccess = openSuccess;
    request.onerror = unexpectedErrorCallback;
}

function openSuccess()
{
    window.db = evalAndLog("db = event.target.result");

    request = evalAndLog("db.setVersion('new version')");
    request.onsuccess = setVersionSuccess;
    request.onerror = unexpectedErrorCallback;
}

function setVersionSuccess()
{
    debug("setVersionSuccess():");
    window.trans = evalAndLog("trans = event.target.result");
    shouldBeTrue("trans !== null");
    trans.onabort = unexpectedAbortCallback;

    deleteAllObjectStores(db);

    shouldBeEqualToString("db.version", "new version");
    shouldBeEqualToString("db.name", "database-quota");
    shouldBe("db.objectStoreNames", "[]");
    shouldBe("db.objectStoreNames.length", "0");
    shouldBe("db.objectStoreNames.contains('')", "false");

    objectStore = evalAndLog('db.createObjectStore("test123")');
    checkObjectStore();
    commitAndContinue();
}

function checkObjectStore()
{
    shouldBe("db.objectStoreNames", "['test123']");
    shouldBe("db.objectStoreNames.length", "1");
    shouldBe("db.objectStoreNames.contains('')", "false");
    shouldBe("db.objectStoreNames.contains('test456')", "false");
    shouldBe("db.objectStoreNames.contains('test123')", "true");
}

function commitAndContinue()
{
    window.setTimeout(checkQuotaEnforcing, 0);
}

function checkQuotaEnforcing()
{
    var trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
    trans.onabort = testComplete;
    trans.oncomplete = unexpectedCompleteCallback;
    debug("Creating 'data' which contains 64K of data");
    window.data = "X";
    for (var i = 0; i < 16; i++)
        data += data;
    shouldBe("data.length", "65536");
    window.dataAdded = 0;
    window.store = evalAndLog("store = trans.objectStore('test123')");
    addData();
}

function addData()
{
    if (dataAdded < 5 * 1024 * 1024) {
        if (dataAdded > 0)
            store = event.target.source;
    } else {
        testFailed("added more than quota");
        done();
        return;
    }
    dataAdded += 65536;
    request = store.add({x: data}, dataAdded);
    request.onsuccess = addData;
    request.onerror = logError;
}

function logError()
{
    debug("Error function called: (" + event.code + ") " + event.message);
    evalAndLog("event.preventDefault()");
}

function testComplete()
{
    testPassed("Adding data failed due to quota error. Data added was about " + Math.round(dataAdded / 1024 / 1024) + " MB");
    done();
}

test();

var successfullyParsed = true;

</script>
</body>
</html>