Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / storage / indexeddb / blob-contenttype.html
1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script>
4 <script>
5
6 function indexeddb_test(upgrade_func, body_func, description) {
7     async_test(function(t) {
8         var dbname = location.pathname + ' - ' + description;
9         var deleteRequest = indexedDB.deleteDatabase(dbname);
10         deleteRequest.onsuccess = t.step_func(function() {
11             var openRequest = indexedDB.open(dbname);
12             openRequest.onupgradeneeded = t.step_func(function() {
13                 upgrade_func(t, openRequest.result);
14             });
15             openRequest.onsuccess = t.step_func(function() {
16                 body_func(t, openRequest.result);
17             });
18             openRequest.onerror = t.unreached_func('open failed');
19         });
20     }, description);
21 }
22
23 indexeddb_test(
24     function upgrade(t, db) {
25         db.createObjectStore('store');
26     },
27     function success(t, db) {
28         var type = 'x-files/trust-no-one';
29
30         var blob = new Blob(['mulder', 'scully'], {type: type});
31         assert_equals(blob.type, type, 'Blob type should match constructor option');
32
33         var tx = db.transaction('store', 'readwrite');
34         tx.objectStore('store').put(blob, 'key');
35
36         tx.oncomplete = t.step_func(function() {
37             var tx = db.transaction('store');
38             tx.objectStore('store').get('key').onsuccess = t.step_func(function(e) {
39                 var result = e.target.result;
40                 assert_equals(result.type, type, 'Blob type should survive round-trip');
41
42                 var url = URL.createObjectURL(result);
43                 var xhr = new XMLHttpRequest(), async = true;
44                 xhr.open('GET', url, async);
45                 xhr.send();
46                 xhr.onreadystatechange = t.step_func(function() {
47                     if (xhr.readyState !== XMLHttpRequest.DONE)
48                         return;
49                     assert_equals(xhr.getResponseHeader('Content-Type'), type,
50                                   'Blob type should be preserved when fetched');
51                     t.done();
52                 });
53             });
54         });
55     },
56     'Ensure that content type round trips when reading blob data'
57 );
58
59 </script>