Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / factory-cmp.js
blobb7cb0436f0965c8f8b8f35379e06b3714090e07f
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test IndexedDB key comparison using IDBFactory.cmp().");
8 function test()
10     shouldBeEqualToString("typeof indexedDB.cmp", "function");
12     testValidKeys();
13     testInvalidKeys();
14     testIdenticalKeys();
15     finishJSTest();
18 function testValidKeys()
20     debug("");
21     debug("compare valid keys");
23     var keys = [
24         "-Infinity",
25         "-Number.MAX_VALUE",
26         "-1",
27         "-Number.MIN_VALUE",
28         "0",
29         "Number.MIN_VALUE",
30         "1",
31         "Number.MAX_VALUE",
32         "Infinity",
34         "new Date(0)",
35         "new Date(1000)",
36         "new Date(1317399931023)",
38         "''",
39         "'\x00'",
40         "'a'",
41         "'aa'",
42         "'b'",
43         "'ba'",
45         "'\xA2'", // U+00A2 CENT SIGN
46         "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
47         "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
48         "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
50         "new Uint8Array()",
51         "new Uint8Array([0])",
52         "new Uint8Array([0, 0])",
53         "new Uint8Array([0, 1])",
54         "new Uint8Array([1])",
55         "new Uint8Array([1, 0])",
56         "new Uint8Array([1, 1])",
57         "new Uint8Array([255])",
59         "[]",
61         "[-Infinity]",
62         "[-Number.MAX_VALUE]",
63         "[-1]",
64         "[-Number.MIN_VALUE]",
65         "[0]",
66         "[Number.MIN_VALUE]",
67         "[1]",
68         "[Number.MAX_VALUE]",
69         "[Infinity]",
71         "[new Date(0)]",
72         "[new Date(1000)]",
73         "[new Date(1317399931023)]",
75         "['']",
76         "['\x00']",
77         "['a']",
78         "['aa']",
79         "['b']",
80         "['ba']",
82         "['\xA2']", // U+00A2 CENT SIGN
83         "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
84         "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
85         "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
87         "[new Uint8Array()]",
88         "[new Uint8Array([0])]",
89         "[new Uint8Array([0, 0])]",
90         "[new Uint8Array([0, 1])]",
91         "[new Uint8Array([1])]",
92         "[new Uint8Array([1, 0])]",
93         "[new Uint8Array([1, 1])]",
94         "[new Uint8Array([255])]",
96         "[[]]",
98         "[[], []]",
99         "[[], [], []]",
101         "[[[]]]",
102         "[[[[]]]]"
103     ];
105     var i, key1, key2;
106     for (i = 0; i < keys.length - 1; i += 1) {
107         key1 = keys[i];
108         key2 = keys[i + 1];
109         shouldBe("indexedDB.cmp(" + key1 + "," + key2 + ")", "-1");
110         shouldBe("indexedDB.cmp(" + key2 + "," + key1 + ")", "1");
111         shouldBe("indexedDB.cmp(" + key1 + "," + key1 + ")", "0");
112         shouldBe("indexedDB.cmp(" + key2 + "," + key2 + ")", "0");
113     }
116 function testInvalidKeys()
118     debug("");
119     debug("compare invalid keys");
121     var invalidKeys = [
122         "void 0", // undefined
123         "true",
124         "false",
125         "NaN",
126         "new Date(NaN)",
127         "null",
128         "{}",
129         "function () {}",
130         "/regex/",
131         "self",
132         "self.document",
133         "self.document.body"
134     ];
136     var i, key1, key2;
137     for (i = 0; i < invalidKeys.length - 1; i += 1) {
138         key1 = invalidKeys[i];
139         key2 = invalidKeys[i + 1];
140         evalAndExpectException("indexedDB.cmp(" + key1 + ", " + key2 + ")", "0", "'DataError'");
141         evalAndExpectException("indexedDB.cmp(" + key2 + ", " + key1 + ")", "0", "'DataError'");
142         evalAndExpectException("indexedDB.cmp(" + key1 + ", 'valid')", "0", "'DataError'");
143         evalAndExpectException("indexedDB.cmp('valid', " + key1 + ")", "0", "'DataError'");
144         evalAndExpectException("indexedDB.cmp(" + key2 + ", 'valid')", "0", "'DataError'");
145         evalAndExpectException("indexedDB.cmp('valid', " + key2 + ")", "0", "'DataError'");
146     }
149 function testIdenticalKeys()
151     debug("");
152     debug("compare identical keys");
154     shouldBe("indexedDB.cmp(0, -0)", "0");
157 test();