| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Service Worker: Indexed DB</title> | 2 <title>Service Worker: Indexed DB</title> |
| 3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
| 6 <script> | 6 <script> |
| 7 var test = async_test('Verify Indexed DB operation in a Service Worker'); | 7 var test = async_test('Verify Indexed DB operation in a Service Worker'); |
| 8 test.step(function() { | 8 test.step(function() { |
| 9 var scope = 'resources/blank.html'; | 9 var scope = 'resources/blank.html'; |
| 10 service_worker_unregister_and_register( | 10 service_worker_unregister_and_register( |
| 11 test, 'resources/indexeddb-worker.js', scope, onRegister); | 11 test, 'resources/indexeddb-worker.js', scope).then(test.step_func(onRegi
ster)); |
| 12 | 12 |
| 13 function onRegister(worker) { | 13 function onRegister(worker) { |
| 14 var messageChannel = new MessageChannel(); | 14 var messageChannel = new MessageChannel(); |
| 15 messageChannel.port1.onmessage = test.step_func(onMessage); | 15 messageChannel.port1.onmessage = test.step_func(onMessage); |
| 16 | 16 |
| 17 worker.postMessage({port: messageChannel.port2}, [messageChannel.port2])
; | 17 worker.postMessage({port: messageChannel.port2}, [messageChannel.port2])
; |
| 18 } | 18 } |
| 19 | 19 |
| 20 function onMessage() { | 20 function onMessage() { |
| 21 var openRequest = indexedDB.open('db'); | 21 var openRequest = indexedDB.open('db'); |
| 22 openRequest.onsuccess = test.step_func(function() { | 22 openRequest.onsuccess = test.step_func(function() { |
| 23 var db = openRequest.result; | 23 var db = openRequest.result; |
| 24 var tx = db.transaction('store'); | 24 var tx = db.transaction('store'); |
| 25 var store = tx.objectStore('store'); | 25 var store = tx.objectStore('store'); |
| 26 var getRequest = store.get('key'); | 26 var getRequest = store.get('key'); |
| 27 getRequest.onsuccess = test.step_func(function() { | 27 getRequest.onsuccess = test.step_func(function() { |
| 28 assert_equals(getRequest.result, 'value', | 28 assert_equals(getRequest.result, 'value', |
| 29 'The get() result should match what the worker put
().'); | 29 'The get() result should match what the worker put
().'); |
| 30 service_worker_unregister_and_done(test, scope); | 30 service_worker_unregister_and_done(test, scope); |
| 31 }); | 31 }); |
| 32 }); | 32 }); |
| 33 } | 33 } |
| 34 }); | 34 }); |
| 35 </script> | 35 </script> |
| OLD | NEW |