| <!DOCTYPE html> |
| <title>Indexed DB: Serialization of constructed File attribute</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| |
| function indexeddb_test(upgrade_func, body_func, description) { |
| async_test(function(t) { |
| var dbname = location.pathname + ' - ' + description; |
| var deleteRequest = indexedDB.deleteDatabase(dbname); |
| deleteRequest.onsuccess = t.step_func(function() { |
| var openRequest = indexedDB.open(dbname); |
| openRequest.onupgradeneeded = t.step_func(function() { |
| upgrade_func(t, openRequest.result); |
| }); |
| openRequest.onsuccess = t.step_func(function() { |
| body_func(t, openRequest.result); |
| }); |
| openRequest.onerror = t.unreached_func('open failed'); |
| }); |
| }, description); |
| } |
| |
| indexeddb_test( |
| function upgrade(t, db) { |
| db.createObjectStore('store'); |
| }, |
| function success(t, db) { |
| var party_time = new Date('1999-12-31T23:59:59Z'); |
| var file = new File(['content'], 'somefile', { |
| type: 'application/x-special-snowflake', |
| lastModified: party_time |
| }); |
| var tx = db.transaction('store', 'readwrite'); |
| tx.objectStore('store').put(file, 'key'); |
| |
| tx.oncomplete = t.step_func(function() { |
| var tx = db.transaction('store'); |
| tx.objectStore('store').get('key').onsuccess = t.step_func(function(e) { |
| var result = e.target.result; |
| |
| assert_equals(result.name, file.name, |
| 'name attribute should round-trip'); |
| assert_equals(result.size, file.size, |
| 'size attribute should round-trip'); |
| assert_equals(result.type, file.type, |
| 'type attribute should round-trip'); |
| assert_equals(result.lastModified, file.lastModified, |
| 'lastModified attribute should round-trip'); |
| assert_equals(String(result.lastModifiedDate), String(file.lastModifiedDate), |
| 'lastModifiedDate attribute should round-trip'); |
| |
| t.done(); |
| }); |
| }); |
| }, |
| 'Attribute persistence of constructed File objects' |
| ); |
| |
| </script> |