summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/resources/shared.js
blob: 65da3bf3d2473bee60a119554621ef1e58c23a39 (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
function done()
{
    isSuccessfullyParsed();
    if (window.layoutTestController)
        layoutTestController.notifyDone()
}

function verifyEventCommon(event)
{
    shouldBeTrue("'source' in event");
    shouldBeTrue("event.source != null");
    shouldBeTrue("'onsuccess' in event.target");
    shouldBeTrue("'onerror' in event.target");
    shouldBeTrue("'readyState' in event.target");
    shouldBe("event.target.readyState", "event.target.DONE");
    debug("");
}

function verifyErrorEvent(event)
{
    debug("Error event fired:");
    shouldBeFalse("'result' in event");
    shouldBeTrue("'code' in event");
    shouldBeTrue("'message' in event");
    verifyEventCommon(event);
}

function verifySuccessEvent(event)
{
    debug("Success event fired:");
    shouldBeTrue("'result' in event");
    shouldBeFalse("'code' in event");
    shouldBeFalse("'message' in event");
    verifyEventCommon(event);
}

function verifyAbortEvent(event)
{
    debug("Abort event fired:");
    shouldBeEqualToString("event.type", "abort");
}

function verifyResult(result)
{
    shouldBeTrue("'onsuccess' in result");
    shouldBeTrue("'onerror' in result");
    shouldBeTrue("'readyState' in result");
    debug("An event should fire shortly...");
    debug("");
}

function unexpectedSuccessCallback()
{
    testFailed("Success function called unexpectedly.");
    debug("");
    verifySuccessEvent(event);
    done();
}

function unexpectedErrorCallback()
{
    testFailed("Error function called unexpectedly: (" + event.code + ") " + event.message);
    debug("");
    verifyErrorEvent(event);
    done();
}

function deleteAllObjectStores(db)
{
    objectStores = db.objectStores;
    for (var i = 0; i < objectStores.length; ++i)
        db.removeObjectStore(objectStores[i]);
}