2010-05-28 Eric Uhrhane <ericu@chromium.org>
[WebKit-https.git] / LayoutTests / fast / workers / storage / resources / database-worker.js
1 var window = {
2     layoutTestController: {
3         notifyDone: function() { postMessage("notifyDone"); }
4     }
5 };
6 var layoutTestController = window.layoutTestController;
7
8 function log(s) {
9     postMessage("log:" + s);
10 }
11
12 onmessage = function(event) {
13     try {
14         if (event.data.indexOf("importScripts:") == 0) {
15             var scripts = event.data.substring("importScripts:".length).split(",");
16             for (var i in scripts)
17                 scripts[i] = "../" + scripts[i];
18             importScripts(scripts);
19         } else if (event.data == "runTest")
20             runTest(); // Must be defined by some imported script.
21         else
22             log("Received unexpected message: " + event.data);
23     } catch (ex) {
24         log("Worker caught exception: " + ex);
25         window.layoutTestController.notifyDone();
26     }
27 };
28
29 var DB_TEST_SUFFIX = "_worker";
30
31 function openDatabaseWithSuffix(name, version, description, size, callback)
32 {
33     if (arguments.length > 4) {
34         return openDatabase(name + DB_TEST_SUFFIX, version, description, size, callback);
35     } else {
36         return openDatabase(name + DB_TEST_SUFFIX, version, description, size);
37     }
38 }
39