tizen beta release
[profile/ivi/webkit-efl.git] / LayoutTests / storage / indexeddb / factory-cmp.html
1 <html>
2 <head>
3 <script src="../../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10
11 description("Test IndexedDB key comparison using IDBFactory.cmp().");
12 if (window.layoutTestController) 
13     layoutTestController.waitUntilDone();
14
15 function test()
16 {
17     indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
18     shouldBeFalse("indexedDB == null");
19     IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
20     shouldBeFalse("IDBDatabaseException == null");
21
22     shouldBeTrue("typeof indexedDB.cmp === 'function'");
23
24     testValidKeys();
25     testInvalidKeys();
26     testIdenticalKeys();
27     done();
28 }
29
30 function testValidKeys()
31 {
32     debug("");
33     debug("compare valid keys");
34
35     var keys = [
36         "-Infinity",
37         "-Number.MAX_VALUE",
38         "-1",
39         "-Number.MIN_VALUE",
40         "0",
41         "Number.MIN_VALUE",
42         "1",
43         "Number.MAX_VALUE",
44         "Infinity",
45  
46         "new Date(0)",
47         "new Date(1000)",
48         "new Date(1317399931023)",
49         
50         "''",
51         "'\x00'",
52         "'a'",
53         "'aa'",
54         "'b'",
55         "'ba'",
56
57         "'\xA2'", // U+00A2 CENT SIGN
58         "'\u6C34'", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
59         "'\uD834\uDD1E'", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
60         "'\uFFFD'", // U+FFFD REPLACEMENT CHARACTER
61
62         "[]",
63
64         "[-Infinity]",
65         "[-Number.MAX_VALUE]",
66         "[-1]",
67         "[-Number.MIN_VALUE]",
68         "[0]",
69         "[Number.MIN_VALUE]",
70         "[1]",
71         "[Number.MAX_VALUE]",
72         "[Infinity]",
73  
74         "[new Date(0)]",
75         "[new Date(1000)]",
76         "[new Date(1317399931023)]",
77         
78         "['']",
79         "['\x00']",
80         "['a']",
81         "['aa']",
82         "['b']",
83         "['ba']",
84
85         "['\xA2']", // U+00A2 CENT SIGN
86         "['\u6C34']", // U+6C34 CJK UNIFIED IDEOGRAPH (water)
87         "['\uD834\uDD1E']", // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
88         "['\uFFFD']", // U+FFFD REPLACEMENT CHARACTER
89
90         "[[]]",
91         
92         "[[], []]",
93         "[[], [], []]",
94
95         "[[[]]]",
96         "[[[[]]]]"
97     ];
98
99     var i, key1, key2;
100     for (i = 0; i < keys.length - 1; i += 1) {
101         key1 = keys[i];
102         key2 = keys[i + 1];
103         shouldBeTrue("indexedDB.cmp(" + key1 + "," + key2 + ") === -1");
104         shouldBeTrue("indexedDB.cmp(" + key2 + "," + key1 + ") === 1");
105         shouldBeTrue("indexedDB.cmp(" + key1 + "," + key1 + ") === 0");
106         shouldBeTrue("indexedDB.cmp(" + key2 + "," + key2 + ") === 0");
107     }
108 }
109
110 function testInvalidKeys()
111 {
112     debug("");
113     debug("compare invalid keys");
114
115     var invalidKeys = [
116         "void 0", // undefined
117         "true",
118         "false",
119         "NaN",
120         "null",
121         "{}",
122         "function () {}",
123         "/regex/",
124         "window",
125         "window.document",
126         "window.document.body"
127     ];
128
129     var i, key1, key2;
130     for (i = 0; i < invalidKeys.length - 1; i += 1) {
131         key1 = invalidKeys[i];
132         key2 = invalidKeys[i + 1];
133         evalAndExpectException("indexedDB.cmp(" + key1 + ", " + key2 + ")", "IDBDatabaseException.DATA_ERR");
134         evalAndExpectException("indexedDB.cmp(" + key2 + ", " + key1 + ")", "IDBDatabaseException.DATA_ERR");
135         evalAndExpectException("indexedDB.cmp(" + key1 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
136         evalAndExpectException("indexedDB.cmp('valid', " + key1 + ")", "IDBDatabaseException.DATA_ERR");
137         evalAndExpectException("indexedDB.cmp(" + key2 + ", 'valid')", "IDBDatabaseException.DATA_ERR");
138         evalAndExpectException("indexedDB.cmp('valid', " + key2 + ")", "IDBDatabaseException.DATA_ERR");
139     }
140 }
141
142 function testIdenticalKeys()
143 {
144     debug("");
145     debug("compare identical keys");
146
147     shouldBeTrue("indexedDB.cmp(0, -0) === 0");
148 }
149
150
151 test();
152
153 </script>
154 </body>
155 </html>