Upstream version 9.38.198.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 async_test(function(t) {
8     var scope = 'resources/blank.html';
9     service_worker_unregister_and_register(
10       t, 'resources/indexeddb-worker.js', scope)
11     .then(function(registration) {
12         return wait_for_update(t, registration);
13       })
14     .then(function(sw) {
15         var messageChannel = new MessageChannel();
16         messageChannel.port1.onmessage = t.step_func(onMessage);
17         sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
18       })
19     .catch(unreached_rejection(t));
20     
21     function onMessage() {
22       var openRequest = indexedDB.open('db');
23       openRequest.onsuccess = t.step_func(function() {
24           var db = openRequest.result;
25           var tx = db.transaction('store');
26           var store = tx.objectStore('store');
27           var getRequest = store.get('key');
28           getRequest.onsuccess = t.step_func(function() {
29               assert_equals(
30                 getRequest.result, 'value',
31                 'The get() result should match what the worker put().');
32               service_worker_unregister_and_done(t, scope);
33             });
34         });
35     }
36   }, 'Verify Indexed DB operation in a Service Worker');
37 </script>