1 |
|
2 | var DRIVERS = [
|
3 | localforage.INDEXEDDB,
|
4 | localforage.LOCALSTORAGE,
|
5 | localforage.WEBSQL
|
6 | ];
|
7 |
|
8 | DRIVERS.forEach(function(driverName) {
|
9 | if ((!localforage.supports(localforage.INDEXEDDB) &&
|
10 | driverName === localforage.INDEXEDDB) ||
|
11 | (!localforage.supports(localforage.LOCALSTORAGE) &&
|
12 | driverName === localforage.LOCALSTORAGE) ||
|
13 | (!localforage.supports(localforage.WEBSQL) &&
|
14 | driverName === localforage.WEBSQL)) {
|
15 |
|
16 |
|
17 | return;
|
18 | }
|
19 |
|
20 | describe('Web Worker support in ' + driverName, function() {
|
21 | 'use strict';
|
22 |
|
23 | before(function(done) {
|
24 | localforage.setDriver(driverName).then(done);
|
25 | });
|
26 |
|
27 | beforeEach(function(done) {
|
28 | localforage.clear(done);
|
29 | });
|
30 |
|
31 | if (!Modernizr.webworkers) {
|
32 | it.skip('doesn\'t have web worker support');
|
33 | return;
|
34 | }
|
35 |
|
36 | if (driverName === localforage.LOCALSTORAGE ||
|
37 | driverName === localforage.WEBSQL) {
|
38 | it.skip(driverName + ' is not supported in web workers');
|
39 | return;
|
40 | }
|
41 |
|
42 | it('saves data', function(done) {
|
43 | var webWorker = new Worker('/test/webworker-client.js');
|
44 |
|
45 | webWorker.addEventListener('message', function(e) {
|
46 | var body = e.data.body;
|
47 |
|
48 | window.console.log(body);
|
49 | expect(body).to.be('I have been set');
|
50 | done();
|
51 | });
|
52 |
|
53 | webWorker.addEventListener('error', function(e) {
|
54 | window.console.log(e);
|
55 | });
|
56 |
|
57 | webWorker.postMessage({
|
58 | driver: driverName,
|
59 | value: 'I have been set'
|
60 | });
|
61 | });
|
62 | });
|
63 | });
|