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

Side by Side Diff: LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-blob.html

Issue 268923002: Add support of sending blob data for RTCDataChannel Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Tests RTCDataChannel sending blob data.");
9
10 var pc = null;
11 var dc = null;
12 var fileSystemSize = 1024;
13 var fileName = "rtcdatachannel-send-file-blob.txt";
14 var messageToWrite = "Hello, world!";
15 var data;
16 var blob;
17 var fileEntry = null;
18
19 function createBlobContainingAllDistinctBytes() {
20 var blobData = new Uint8Array(256);
21 for (var i = 0; i < 256; ++i)
22 blobData[i] = i;
23 return new Blob([blobData]);
24 }
25
26 function checkReceivedBlobData(arrayBuffer) {
27 if (arrayBuffer.byteLength != 256)
28 return false;
29 var result = new Uint8Array(arrayBuffer, 0, arrayBuffer.byteLength);
30
31 for (var i = 0; i < 256; ++i) {
32 if (result[i] != i)
33 return false;
34 }
35 return true;
36 }
37
38 function dc_onmessage_file(e) {
39 testPassed("dc_onmessage_file was called");
40 data = e.data;
41 shouldBeTrue("data instanceof window.Blob");
42
43 var reader = new FileReader();
44 reader.onload = function(event) {
45 if (event.target.result === messageToWrite) {
46 testPassed("File data is received correctly.");
47 } else {
48 testFailed("File data is not received correctly.");
49 }
50 endTest();
51 };
52 reader.readAsText(data);
53 }
54
55 function testSendFileBlob() {
56 if (!window.webkitRequestFileSystem) {
57 testFailed("window.webkitRequestFileSystem is not available.");
58 finishJSTest();
59 return;
60 }
61
62 webkitRequestFileSystem(TEMPORARY, fileSystemSize, didGetFileSystem, didFail );
63 }
64
65 function didGetFileSystem(fileSystem) {
66 testPassed("Got fileSystem");
67 fileSystem.root.getFile(fileName, {create: true}, didCreateFile, didFail);
68 }
69
70 function didCreateFile(entry) {
71 testPassed("File created.");
72 fileEntry = entry;
73 shouldBeTrue("fileEntry.isFile");
74 fileEntry.createWriter(didGetFileWriter, didFail);
75 }
76
77 function didGetFileWriter(writer) {
78 writer.truncate(0);
79 writer.onerror = function() {
80 testFailed("FileWriter operation failed.");
81 endTest();
82 };
83 writer.onwrite = function() {
84 writer.write(new Blob([messageToWrite]));
85 writer.onwrite = didWriteFile;
86 };
87 }
88
89 function didWriteFile() {
90 testPassed("Wrote to file.");
91 fileEntry.file(didGetFile, didFail);
92 }
93
94 var fileObject;
95
96 function didGetFile(file) {
97 testPassed("Got File object successfully.");
98
99 fileObject = file;
100 dc.onmessage = dc_onmessage_file;
101 shouldNotThrow("dc.send(fileObject);");
102 }
103
104 function dc_onmessage_blob(e) {
105 testPassed("dc_onmessage_blob was called");
106 data = e.data;
107 shouldBeTrue("data instanceof window.Blob");
108
109 var reader = new FileReader();
110 reader.onload = function(event) {
111 if (checkReceivedBlobData(event.target.result)) {
112 testPassed("Blob data was reveived correctly.");
113 testSendFileBlob();
114 } else {
115 testFailed("Blob data should be received correctly");
116 endTest();
117 }
118 };
119 reader.readAsArrayBuffer(data);
120 }
121
122 function dc_onclose() {
123 testPassed("dc_onclose was called");
124 shouldBe("dc.readyState", "'closed'");
125
126 finishJSTest();
127 }
128
129 function dc_onopen() {
130 testPassed("dc_onopen was called");
131 shouldBe("dc.readyState", "'open'");
132 shouldBe("dc.label", "'label'");
133
134 dc.onmessage = dc_onmessage_blob;
135 blob = createBlobContainingAllDistinctBytes();
136 shouldNotThrow("dc.send(blob);");
137 }
138
139 function pc_onicechange() {
140 if (pc.iceConnectionState === "completed") {
141 testPassed("pc is connected");
142 shouldNotThrow('dc = pc.createDataChannel("label");');
143 shouldBe("dc.readyState", "'connecting'");
144 shouldBeEqualToString("dc.binaryType", "blob");
145 dc.onopen = dc_onopen;
146 dc.onclose = dc_onclose;
147 }
148 }
149
150 function pc_ondatachannel(e) {
151 testPassed("pc_ondatachannel was called");
152 }
153
154 function didFail(fileError) {
155 testFailed("FileSystem API operation failed: error code = " + fileError.code );
156 endTest();
157 }
158
159 function endTest() {
160 if (fileEntry) {
161 testPassed("Deleting the file.");
162 fileEntry.remove(finishJSTest, finishJSTest);
163 }
164 dc.onclose = dc_onclose;
165 dc.close();
166 }
167
168 pc = new webkitRTCPeerConnection(null, null);
169 pc.oniceconnectionstatechange = pc_onicechange;
170 pc.ondatachannel = pc_ondatachannel;
171
172 window.jsTestIsAsync = true;
173 window.successfullyParsed = true;
174 </script>
175 </body>
176 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698