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>
7 var test = async_test('Verify Indexed DB operation in a Service Worker');
9 var scope = 'resources/blank.html';
10 navigator.serviceWorker.unregister(scope).then(
12 unreached_rejection(test, 'Unregister should not fail')
16 navigator.serviceWorker.register('resources/indexeddb-worker.js',
18 test.step_func(function(worker) {
19 var messageChannel = new MessageChannel();
20 messageChannel.port1.onmessage = test.step_func(onMessage);
22 worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
24 unreached_rejection(test, 'Registration should succeed, but failed'));
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().');