summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbkeyrange_incorrect.htm
blob: 0449ca8073231489345e9d6b32a8ac047278ce95 (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
<!DOCTYPE html>
<!-- Submitted from TestTWF Paris -->
<html>
    <head>
        <meta charset=utf-8>
        <title id='desc'>IDBKeyRange Tests - Incorrect</title>
        <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#range-concept">
        <link rel=assert title="If the lower key is greater than the upper key, then a DOMException of type DataError must be thrown.">
        <link rel=author href="mailto:chrcharles67@gmail.com" title="Christophe CHARLES">

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

        <script type="text/javascript">

            // TypeError: bound requires more than 0 arguments
            test( function() {
                assert_throws(new TypeError(), function() {
                    IDBKeyRange.bound();
                });
            }, "IDBKeyRange.bound() - bound requires more than 0 arguments.");

            // Null parameters
            test( function() {
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(null, null);
                });
            }, "IDBKeyRange.bound(null, null) - null parameters are incorrect.");

            // // Null parameter
            test( function() {
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(1, null);
                });
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(null, 1);
                });
            }, "IDBKeyRange.bound(1, null / null, 1) - null parameter is incorrect.");

            // bound incorrect
            test( function() {
                var lowerBad = Math.floor(Math.random()*31) + 5;
                var upper = lowerBad - 1;
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(lowerBad, upper);
                });
                assert_throws("DataError", function() {
                    IDBKeyRange.bound('b', 'a');
                });
            }, "IDBKeyRange.bound(lower, upper / lower > upper) -  'lower' is greater than 'upper'."
            );

            test( function() {
                assert_throws("DataError", function() {
                    IDBKeyRange.bound('a', 1);
                });
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(new Date(), 1);
                });
                assert_throws("DataError", function() {
                    IDBKeyRange.bound([1, 2], 1);
                });
            }, "IDBKeyRange.bound(DOMString/Date/Array, 1) - A DOMString, Date and Array are greater than a float.");


            // ReferenceError: the variable is not defined
            test( function() {
                var goodVariable = 1;
                assert_throws(new ReferenceError(), function() {
                    IDBKeyRange.bound(noExistingVariable, 1);
                });
                assert_throws(new ReferenceError(), function() {
                    IDBKeyRange.bound(goodVariable, noExistingVariable);
                });
            }, "IDBKeyRange.bound(noExistingVariable, 1 / goodVariable, noExistingVariable) - noExistingVariable is not defined.");

            // Valid type key error
            test( function() {
                assert_throws("DataError", function() {
                    IDBKeyRange.bound(true, 1);
                });
            }, "IDBKeyRange.bound(true, 1) - boolean is not a valid key type.");


        </script>
    </head>

    <body>
        <div id="log"></div>
    </body>
</html>