Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / odd-strings.js
blobc148e844e10da6093fd429fe4e941e63d33be43b
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test IndexedDB odd value datatypes");
8 function test()
10     testData = [{ description: 'empty string',       name: '' },
11                 { description: 'null',               name: '\u0000' },
12                 { description: 'faihu',              name: '\ud800\udf46' },
13                 { description: 'unpaired surrogate', name: '\ud800' },
14                 { description: 'fffe',               name: '\ufffe' },
15                 { description: 'ffff',               name: '\uffff' },
16                 { description: 'line separator',     name: '\u2028' }
17     ];
18     nextToOpen = 0;
19     var numDeleted = 0;
20     debug("Deleting all the databases...");
21     for (var i = 0; i < testData.length; i++)
22     {
23         request = indexedDB.deleteDatabase(testData[i].name);
24         request.onblocked = unexpectedBlockedCallback;
25         request.onerror = unexpectedErrorCallback;
26         request.onsuccess = function() {
27             if (++numDeleted == testData.length)
28                 openNextDatabase();
29         };
30     }
33 function openNextDatabase()
35     debug("opening a database named " + testData[nextToOpen].description);
36     request = evalAndLog("indexedDB.open(testData[nextToOpen].name, 1)");
37     request.onsuccess = unexpectedSuccessCallback;
38     request.onblocked = unexpectedBlockedCallback;
39     request.onupgradeneeded = addAKey;
42 function addAKey()
44     db = event.target.result;
45     evalAndLog("objectStore = db.createObjectStore(testData[nextToOpen].name);");
46     evalAndLog("index = objectStore.createIndex(testData[nextToOpen].name, 'keyPath');");
47     evalAndLog("key = testData[nextToOpen].name");
48     evalAndLog("request = objectStore.add(key, key);");
49     request.onsuccess = closeDatabase;
50     request.onerror = unexpectedErrorCallback;
53 function closeDatabase()
55     evalAndLog("db.close()");
56     debug("");
57     if (++nextToOpen < testData.length) {
58         openNextDatabase();
59     } else {
60         nextToOpen = 0;
61         verifyNextDatabase();
62     }
65 function verifyNextDatabase()
67     debug("reopening a database named " + testData[nextToOpen].description);
68     request = evalAndLog("indexedDB.open(testData[nextToOpen].name, 2)");
69     request.onblocked = unexpectedBlockedCallback;
70     request.onerror = unexpectedErrorCallback;
71     request.onupgradeneeded = getAKey;
74 function getAKey()
76     evalAndLog("trans = event.target.transaction");
77     evalAndLog("objectStore = trans.objectStore(testData[nextToOpen].name);");
78     evalAndLog("key = testData[nextToOpen].name");
79     evalAndLog("request = objectStore.openCursor();");
80     request.onerror = unexpectedErrorCallback;
81     request.onsuccess = openCursorSuccess;
84 function openCursorSuccess()
86     evalAndLog("cursor = event.target.result;");
87     shouldBe("cursor.key", "testData[nextToOpen].name");
88     shouldBe("cursor.value", "testData[nextToOpen].name");
89     if (++nextToOpen < testData.length) {
90         debug("");
91         verifyNextDatabase();
92     } else {
93         finishJSTest();
94     }
97 test();