1 google.gears.workerPool.allowCrossOrigin();
3 // TODO(cprince): When we have include(), replace all code below with
4 // include('unit_tests_worker_same_origin.js').
6 var wp = google.gears.workerPool;
8 wp.onmessage = function(body, sender) {
10 // Do something to prove the database is functional.
12 // To prove it here, we create a table named after the message body,
13 // insert our reply message, and retrieve our reply from that table.
15 // We also use the message body to determine the table name. This allows
16 // callers to affect the table name, so they can create different tables
17 // in different scenarios to test different conditions.
19 var tableName = body.split(' ')[0];
21 var db = google.gears.factory.create('beta.database', '1.0');
24 db.execute('create table if not exists ' + tableName +
25 ' (REPLY text, ID int unique)');
26 db.execute('insert or replace into ' + tableName + ' values (?, ?)',
27 ['RE: ' + body, sender]);
28 var rs = db.execute('select * from ' + tableName + ' where ID=?', [sender]);
29 var reply = rs.field(0);
33 wp.sendMessage(reply, sender); // echo