summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/manual-tests/indexeddb-persists.html
blob: d8061e1bcc74cff2f6a32e336dfa90a8f97249c6 (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
<html>
<body>
<p>This is a test that only applies to IndexedDB.  <span id=enabled>Our test for whether you have it enabled seems to have failed.</span></p>

<p>Please follow these steps in order:</p>

<p>First, click <a href="javascript: setData()">here</a> to open a database and set some data within it.</p>

<p>Next, close the browser and then re-open this page.</p>

<p>Lastly, click <a href="javascript: verifyData()">here</a> to verify the data was there</p>

<p>Status: <span id=status>...</span></p>

<script>

if (!('webkitIndexedDB' in window))
    document.getElementById("enabled").innerHTML = "<font color=red>Your build does NOT seem to have it enabled.  So all code on this page is disabled.</font>";
else
    document.getElementById("enabled").innerHTML = "<font color=green>Your build seems to have it enabled.</font>";

function status(str, color)
{
    if (color)
        str = "<font color='" + color + "'>" + str + "</font>";
    document.getElementById("status").innerHTML = str;
}

function setData()
{
    status("Something must have gone wrong (or we're still working)...", "red");

    webkitIndexedDB.open("someDB", "some description").onsuccess = function() {
        event.result.setVersion("some version").onsuccess = function() {
            var db = event.source;
            while (db.objectStoreNames.length)
                db.removeObjectStore(db.objectStoreNames[0]);
            db.createObjectStore("test").put("value", "key").onsuccess = function() {
                status("Value set", "green");
            }
        }
    }
}

function verifyData()
{
    status("Something must have gone wrong (or we're still working)...", "red");

    webkitIndexedDB.open("someDB", "some description").onsuccess = function() {
        try {
            var result = event.result.transaction([]).objectStore("test").get("key");
            result.onsuccess = function() {
                if (event.result == "value")
                    status("Value verified", "green");
                else
                    status("Value incorrect!", "red");
            }
            result.onerror = function() {
                status("An error occurred: " + event.code + " " + event.message, "red");
            }
        } catch (e) {
            status("An exception occurred: " + e, "red");
        }
    }
}

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