OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <script src="../../resources/js-test.js"></script> | |
3 <script src="resources/read-common.js"></script> | |
4 <script> | |
5 description("Test the Blob.close() method, revoking."); | |
6 | |
7 window.jsTestIsAsync = true; | |
8 | |
9 function base64ToUint8Array(a) | |
10 { | |
11 var binary = window.atob(a); | |
12 var buffer = new Uint8Array(binary.length); | |
13 for (var i = 0; i < binary.length; i++) | |
14 buffer[i] = binary.charCodeAt(i); | |
15 | |
16 return buffer; | |
17 } | |
18 | |
19 var pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAAsTAAA LEwEAmpwYAAAAnklEQVR42u3QMQEAAAgDoGlyo1vBzwciUJlw1ApkyZIlS5YsBbJkyZIlS5YCWbJkyZI lS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyZIlS5YsBbJkyZIlS5YCWbJ kyZIlS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyfq2MosBSIeKONMAAAA ASUVORK5CYII="; | |
20 | |
21 var blobContents = [base64ToUint8Array(pngBase64)]; | |
22 | |
23 var blob; | |
24 var blobURL1; | |
25 var blobURL2; | |
26 var img; | |
27 var worker; | |
28 var blobURLs = []; | |
29 | |
30 function testRevokeAfterCloseWorkers() | |
31 { | |
32 debug("Test that dereferencing URLs referring to closed Blobs fail, workers. "); | |
33 blob = new Blob(["postMessage('FAIL');"], {type: "application/javascript"}); | |
34 for (var i = 0; i < 10; i++) | |
35 blobURLs.push(window.URL.createObjectURL(blob)); | |
36 | |
37 function onClosedError() { | |
38 testPassed("Error triggered on starting Worker from a closed Blob."); | |
39 testNextWorker(); | |
40 } | |
41 function onClosedMessage() { | |
42 testFailed("Worker loaded."); | |
43 testNextWorker(); | |
44 } | |
45 // Initial event handler, checking that the Blob | |
46 // could be loaded. Close it after that and verify | |
47 // that the rest aren't usable. | |
48 function onNonClosedError() { | |
49 testFailed("Worker failed to load from Blob."); | |
50 blob.close(); | |
51 // Now check that URLs have become now inaccessible. | |
kinuko
2014/02/21 15:40:49
(optional) Really a nit-picky comment, but having
sof
2014/02/21 16:02:44
Done that + added a comment above them explaining
| |
52 testNextWorker(); | |
53 } | |
54 function onNonClosedMessage() { | |
55 testPassed("Worker loaded."); | |
56 blob.close(); | |
57 testNextWorker(); | |
58 } | |
59 | |
60 function testNextWorker(onerror, onmessage) { | |
61 var u = blobURLs.shift(); | |
62 if (u) { | |
63 worker = new Worker(u); | |
64 worker.onerror = onerror ? onerror : onClosedError; | |
65 worker.onmessage = onmessage ? onmessage : onClosedMessage; | |
66 } else { | |
67 runNextTest(); | |
68 } | |
69 } | |
70 testNextWorker(onNonClosedError, onNonClosedMessage); | |
71 } | |
72 | |
73 function testRevokeAfterClose() | |
74 { | |
75 debug("Test that dereferencing URLs referring to closed Blobs fail."); | |
76 blob = new Blob(blobContents, {type: "image/png"}); | |
77 img = document.createElement("img"); | |
78 img.onerror = function (e) { | |
79 testPassed("Error triggered on loading image from closed Blob."); | |
80 runNextTest(); | |
81 }; | |
82 img.onload = function () { | |
83 testFailed("Image loaded"); | |
84 runNextTest(); | |
85 }; | |
86 blobURL1 = window.URL.createObjectURL(blob); | |
87 // create some more Blob URLs. | |
88 for (var i = 0; i < 10; i++) | |
89 window.URL.createObjectURL(blob); | |
90 // Make them all inaccessible. | |
91 blob.close(); | |
92 img.src = blobURL1; | |
93 } | |
94 | |
95 function testRegisterAfterClose() | |
96 { | |
97 debug("Test creating object URLs on closed Blobs"); | |
98 blob = new Blob(["body{background: green}"], {type: "text/css"}); | |
99 blobURL1 = window.URL.createObjectURL(blob); | |
100 blob.close(); | |
101 blobURL2 = window.URL.createObjectURL(blob); | |
102 shouldBeTrue("blobURL1 !== blobURL2"); | |
103 shouldBeTrue("blobURL2.length > 0"); | |
104 runNextTest(); | |
105 } | |
106 | |
107 var tests = [ | |
108 testRevokeAfterClose, | |
109 testRevokeAfterCloseWorkers, | |
110 testRegisterAfterClose ]; | |
111 | |
112 function runNextTest() | |
113 { | |
114 if (!tests.length) { | |
115 finishJSTest(); | |
116 return; | |
117 } | |
118 tests.shift()(); | |
119 } | |
120 </script> | |
121 <body onload="runNextTest()"> | |
122 </body> | |
OLD | NEW |