2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/read-common.js"></script>
5 description("Test the Blob.close() method, revoking.");
7 window
.jsTestIsAsync
= true;
9 function base64ToUint8Array(a
)
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
);
19 var pngBase64
= "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAnklEQVR42u3QMQEAAAgDoGlyo1vBzwciUJlw1ApkyZIlS5YsBbJkyZIlS5YCWbJkyZIlS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyZIlS5YsBbJkyZIlS5YCWbJkyZIlS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyfq2MosBSIeKONMAAAAASUVORK5CYII=";
21 var blobContents
= [base64ToUint8Array(pngBase64
)];
30 function testRevokeAfterCloseWorkers()
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
));
37 // First check that the Blob URL can be used by a Worker,
38 // then close it and verify that the rest cannot.
40 function onNonClosedError() {
41 testFailed("Worker failed to load from Blob.");
45 function onNonClosedMessage() {
46 testPassed("Worker loaded.");
50 function onClosedError() {
51 testPassed("Error triggered on starting Worker from a closed Blob.");
54 function onClosedMessage() {
55 testFailed("Worker loaded.");
59 function testNextWorker(onerror
, onmessage
) {
60 var u
= blobURLs
.shift();
62 worker
= new Worker(u
);
63 worker
.onerror
= onerror
? onerror
: onClosedError
;
64 worker
.onmessage
= onmessage
? onmessage
: onClosedMessage
;
69 testNextWorker(onNonClosedError
, onNonClosedMessage
);
72 function testRevokeAfterClose()
74 debug("Test that dereferencing URLs referring to closed Blobs fail.");
75 blob
= new Blob(blobContents
, {type
: "image/png"});
76 img
= document
.createElement("img");
77 img
.onerror = function (e
) {
78 testPassed("Error triggered on loading image from closed Blob.");
81 img
.onload = function () {
82 testFailed("Image loaded");
85 blobURL1
= window
.URL
.createObjectURL(blob
);
86 // create some more Blob URLs.
87 for (var i
= 0; i
< 10; i
++)
88 window
.URL
.createObjectURL(blob
);
89 // Make them all inaccessible.
94 function testCreateAfterClose()
96 debug("Test creating object URLs on closed Blobs");
97 blob
= new Blob(["body{background: green}"], {type
: "text/css"});
99 shouldThrow("window.URL.createObjectURL(blob);");
104 testRevokeAfterClose
,
105 testRevokeAfterCloseWorkers
,
106 testCreateAfterClose
];
108 function runNextTest()
117 <body onload=
"runNextTest()">