1 var jsTestIsAsync = true;
2 if (self.importScripts && !self.postMessage) {
3 // Shared worker. Make postMessage send to the newest client, which in
4 // our tests is the only client.
6 // Store messages for sending until we have somewhere to send them.
7 self.postMessage = function(message)
9 if (typeof self.pendingMessages === "undefined")
10 self.pendingMessages = [];
11 self.pendingMessages.push(message);
13 self.onconnect = function(event)
15 self.postMessage = function(message)
17 event.ports[0].postMessage(message);
19 // Offload any stored messages now that someone has connected to us.
20 if (typeof self.pendingMessages === "undefined")
22 while (self.pendingMessages.length)
23 event.ports[0].postMessage(self.pendingMessages.shift());
27 function unexpectedSuccessCallback()
29 testFailed("Success function called unexpectedly.");
33 function unexpectedErrorCallback(event)
35 testFailed("Error function called unexpectedly: (" + event.target.error.name + ") " + event.target.error.message);
39 function unexpectedAbortCallback(e)
41 testFailed("Abort function called unexpectedly! Message: [" + e.target.error.message + "]");
45 function unexpectedCompleteCallback()
47 testFailed("oncomplete function called unexpectedly!");
51 function unexpectedBlockedCallback(e)
53 testFailed("onblocked called unexpectedly. oldVersion = " + e.oldVersion + ", newVersion = " + e.newVersion);
57 function unexpectedUpgradeNeededCallback()
59 testFailed("onupgradeneeded called unexpectedly");
63 function unexpectedVersionChangeCallback(e)
65 testFailed("onversionchange called unexpectedly. oldVersion = " + e.oldVersion + ". newVersion = " + e.newVersion);
69 function evalAndExpectException(cmd, exceptionCode, exceptionName, _quiet)
72 debug("Expecting exception from " + cmd);
75 testFailed("No exception thrown! Should have been " + exceptionCode);
79 testPassed("Exception was thrown.");
80 shouldBe("code", exceptionCode, _quiet);
83 shouldBe("ename", exceptionName, _quiet);
86 debug("Exception message: " + e.message);
90 function evalAndExpectExceptionClass(cmd, expected)
92 debug("Expecting " + expected + " exception from " + cmd);
95 testFailed("No exception thrown!" );
97 testPassed("Exception was thrown.");
98 if (eval("e instanceof " + expected))
99 testPassed(cmd + " threw " + e);
101 testFailed("Expected " + expected + " but saw " + e);
105 function evalAndLogCallback(cmd) {
106 function callback() {
112 // If this function is deleted, a standalone layout test exercising its
113 // functionality should be added.
114 function deleteAllObjectStores(db)
116 while (db.objectStoreNames.length)
117 db.deleteObjectStore(db.objectStoreNames.item(0));
118 debug("Deleted all object stores.");
121 function setDBNameFromPath(suffix) {
122 var name = self.location.pathname.substring(1 + self.location.pathname.lastIndexOf("/"));
125 evalAndLog('dbname = "' + name + '"');
128 function preamble(evt)
133 debug(preamble.caller.name + "():");
137 if (!self.DOMException) {
138 self.DOMException = {
140 DOMSTRING_SIZE_ERR: 2,
141 HIERARCHY_REQUEST_ERR: 3,
142 WRONG_DOCUMENT_ERR: 4,
143 INVALID_CHARACTER_ERR: 5,
144 NO_DATA_ALLOWED_ERR: 6,
145 NO_MODIFICATION_ALLOWED_ERR: 7,
147 NOT_SUPPORTED_ERR: 9,
148 INUSE_ATTRIBUTE_ERR: 10,
149 INVALID_STATE_ERR: 11,
151 INVALID_MODIFICATION_ERR: 13,
153 INVALID_ACCESS_ERR: 15,
155 TYPE_MISMATCH_ERR: 17,
159 URL_MISMATCH_ERR: 21,
160 QUOTA_EXCEEDED_ERR: 22,
162 INVALID_NODE_TYPE_ERR: 24,
167 function indexedDBTest(upgradeCallback, optionalOpenCallback, optionalParameters) {
168 if (optionalParameters && 'suffix' in optionalParameters) {
169 setDBNameFromPath(optionalParameters['suffix']);
173 var deleteRequest = evalAndLog("indexedDB.deleteDatabase(dbname)");
174 deleteRequest.onerror = unexpectedErrorCallback;
175 deleteRequest.onblocked = unexpectedBlockedCallback;
176 deleteRequest.onsuccess = function() {
177 self.openRequest = null;
178 if (optionalParameters && 'version' in optionalParameters)
179 openRequest = evalAndLog("indexedDB.open(dbname, " + optionalParameters['version'] + ")");
181 openRequest = evalAndLog("indexedDB.open(dbname)");
182 shouldBe("openRequest.readyState", "'pending'", true/*quiet*/);
183 openRequest.onerror = unexpectedErrorCallback;
184 openRequest.onupgradeneeded = upgradeCallback;
185 openRequest.onblocked = unexpectedBlockedCallback;
186 if (optionalOpenCallback)
187 openRequest.onsuccess = optionalOpenCallback;
188 delete self.openRequest;
189 if (optionalParameters && 'runAfterOpen' in optionalParameters)
190 (optionalParameters['runAfterOpen'])();
194 function waitForRequests(requests, callback) {
195 var count = requests.length;
202 requests.forEach(function(req) {
203 req.onsuccess = function() {
208 req.onerror = unexpectedErrorCallback;