Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / indexeddb.html
1 <!DOCTYPE html>
2 <title>Service Worker: Indexed DB</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <script>
7 var test = async_test('Verify Indexed DB operation in a Service Worker');
8 test.step(function() {
9     var scope = 'resources/blank.html';
10     navigator.serviceWorker.unregister(scope).then(
11         doTest,
12         unreached_rejection(test, 'Unregister should not fail')
13     );
14
15     function doTest() {
16       navigator.serviceWorker.register('resources/indexeddb-worker.js',
17                                       {scope: scope}).then(
18           test.step_func(function(worker) {
19               var messageChannel = new MessageChannel();
20               messageChannel.port1.onmessage = test.step_func(onMessage);
21
22               worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
23           }),
24           unreached_rejection(test, 'Registration should succeed, but failed'));
25     }
26
27     function onMessage() {
28         var openRequest = indexedDB.open('db');
29         openRequest.onsuccess = test.step_func(function() {
30             var db = openRequest.result;
31             var tx = db.transaction('store');
32             var store = tx.objectStore('store');
33             var getRequest = store.get('key');
34             getRequest.onsuccess = test.step_func(function() {
35                 assert_equals(getRequest.result, 'value',
36                               'The get() result should match what the worker put().');
37                 test.done();
38             });
39         });
40     }
41 });
42 </script>