summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/string-list-ordering.htm
blob: ddbbc3036fb0ade4ec2b9da1a219f1c5c689446e (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
<!--
Test converted from WebKit:
http://trac.webkit.org/browser/trunk/LayoutTests/storage/indexeddb/resources/list-ordering.js
-->

<!DOCTYPE html>
<!-- Submitted from TestTWF Paris -->
<meta charset=utf-8>
<title>Test string list ordering in IndexedDB</title>
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBDatabase-objectStoreNames">
<link rel=assert title="The list must be sorted in ascending order using the algorithm defined by step 4 of section 11.8.5, The Abstract Relational Comparison Algorithm of the ECMAScript Language Specification [ECMA-262].">
<link rel=author href="mailto:romain.huet@gmail.com" title="Romain Huet">

<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=resources/support.js></script>

<script>

    var expectedOrder = [
        "",
        "\x00", // 'NULL' (U+0000)
        "0",
        "1",
        "A",
        "B",
        "a",
        "b",
        "\x7F", // 'DELETE' (U+007F)
        "\xC0", // 'LATIN CAPITAL LETTER A WITH GRAVE' (U+00C0)
        "\xC1", // 'LATIN CAPITAL LETTER A WITH ACUTE' (U+00C1)
        "\xE0", // 'LATIN SMALL LETTER A WITH GRAVE' (U+00E0)
        "\xE1", // 'LATIN SMALL LETTER A WITH ACUTE' (U+00E1)
        "\xFF", // 'LATIN SMALL LETTER Y WITH DIAERESIS' (U+00FF)
        "\u0100", // 'LATIN CAPITAL LETTER A WITH MACRON' (U+0100)
        "\u1000", // 'MYANMAR LETTER KA' (U+1000)
        "\uD834\uDD1E", // 'MUSICAL SYMBOL G-CLEF' (U+1D11E), UTF-16 surrogate pairs
        "\uFFFD" // 'REPLACEMENT CHARACTER' (U+FFFD)
    ];

    var i, tmp, permutedOrder = expectedOrder.slice();
    permutedOrder.reverse();
    for (i = 0; i < permutedOrder.length - 2; i += 2) {
        tmp = permutedOrder[i];
        permutedOrder[i] = permutedOrder[i + 1];
        permutedOrder[i + 1] = tmp;
    }

    var objStore, db;
    var t = async_test();

    // Check that the expected order is the canonical JS sort order.
    var sortedOrder = expectedOrder.slice();
    sortedOrder.sort();
    assert_array_equals(sortedOrder, expectedOrder);

    var request = createdb(t);

    request.onupgradeneeded = function(e) {
        db = e.target.result;

        // Object stores.
        for (var i = 0; i < permutedOrder.length; i++) {
            objStore = db.createObjectStore(permutedOrder[i]);
        }
        assert_array_equals(db.objectStoreNames, expectedOrder);

        // Indexes.
        for (var i = 0; i < permutedOrder.length; i++) {
            objStore.createIndex(permutedOrder[i], "keyPath");
        }
        assert_array_equals(objStore.indexNames, expectedOrder);
    };

    request.onsuccess = function(e) {
        // Object stores.
        assert_array_equals(db.objectStoreNames, expectedOrder);
        // Indexes.
        assert_array_equals(objStore.indexNames, expectedOrder);
        t.done();
    };

</script>

<div id=log></div>