Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: LayoutTests/fast/files/blob-close-revoke.html

Issue 157363003: Implement Blob.close(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // First check that the Blob URL can be used by a Worker,
38 // then close it and verify that the rest cannot.
39
40 function onNonClosedError() {
41 testFailed("Worker failed to load from Blob.");
42 blob.close();
43 testNextWorker();
44 }
45 function onNonClosedMessage() {
46 testPassed("Worker loaded.");
47 blob.close();
48 testNextWorker();
49 }
50 function onClosedError() {
51 testPassed("Error triggered on starting Worker from a closed Blob.");
52 testNextWorker();
53 }
54 function onClosedMessage() {
55 testFailed("Worker loaded.");
56 testNextWorker();
57 }
58
59 function testNextWorker(onerror, onmessage) {
60 var u = blobURLs.shift();
61 if (u) {
62 worker = new Worker(u);
63 worker.onerror = onerror ? onerror : onClosedError;
64 worker.onmessage = onmessage ? onmessage : onClosedMessage;
65 } else {
66 runNextTest();
67 }
68 }
69 testNextWorker(onNonClosedError, onNonClosedMessage);
70 }
71
72 function testRevokeAfterClose()
73 {
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.");
79 runNextTest();
80 };
81 img.onload = function () {
82 testFailed("Image loaded");
83 runNextTest();
84 };
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.
90 blob.close();
91 img.src = blobURL1;
92 }
93
94 function testRegisterAfterClose()
95 {
96 debug("Test creating object URLs on closed Blobs");
97 blob = new Blob(["body{background: green}"], {type: "text/css"});
98 blobURL1 = window.URL.createObjectURL(blob);
99 blob.close();
100 // Verifies createObjectURL() still works and returns a valid (non-empty) UR L
101 // without throwing an error. See http://crbug.com/344820 for this requireme nt.
102 blobURL2 = window.URL.createObjectURL(blob);
103 shouldBeTrue("blobURL1 !== blobURL2");
104 shouldBeTrue("blobURL2.length > 0");
105 runNextTest();
106 }
107
108 var tests = [
109 testRevokeAfterClose,
110 testRevokeAfterCloseWorkers,
111 testRegisterAfterClose ];
112
113 function runNextTest()
114 {
115 if (!tests.length) {
116 finishJSTest();
117 return;
118 }
119 tests.shift()();
120 }
121 </script>
122 <body onload="runNextTest()">
123 </body>
OLDNEW
« no previous file with comments | « LayoutTests/fast/files/blob-close-read-expected.txt ('k') | LayoutTests/fast/files/blob-close-revoke-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698