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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-blob.html
diff --git a/LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-blob.html b/LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-blob.html
new file mode 100644
index 0000000000000000000000000000000000000000..c696db2ef7a9f160f7049d165049e916baf236ed
--- /dev/null
+++ b/LayoutTests/fast/mediastream/RTCPeerConnection-datachannel-blob.html
@@ -0,0 +1,176 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<script>
+description("Tests RTCDataChannel sending blob data.");
+
+var pc = null;
+var dc = null;
+var fileSystemSize = 1024;
+var fileName = "rtcdatachannel-send-file-blob.txt";
+var messageToWrite = "Hello, world!";
+var data;
+var blob;
+var fileEntry = null;
+
+function createBlobContainingAllDistinctBytes() {
+ var blobData = new Uint8Array(256);
+ for (var i = 0; i < 256; ++i)
+ blobData[i] = i;
+ return new Blob([blobData]);
+}
+
+function checkReceivedBlobData(arrayBuffer) {
+ if (arrayBuffer.byteLength != 256)
+ return false;
+ var result = new Uint8Array(arrayBuffer, 0, arrayBuffer.byteLength);
+
+ for (var i = 0; i < 256; ++i) {
+ if (result[i] != i)
+ return false;
+ }
+ return true;
+}
+
+function dc_onmessage_file(e) {
+ testPassed("dc_onmessage_file was called");
+ data = e.data;
+ shouldBeTrue("data instanceof window.Blob");
+
+ var reader = new FileReader();
+ reader.onload = function(event) {
+ if (event.target.result === messageToWrite) {
+ testPassed("File data is received correctly.");
+ } else {
+ testFailed("File data is not received correctly.");
+ }
+ endTest();
+ };
+ reader.readAsText(data);
+}
+
+function testSendFileBlob() {
+ if (!window.webkitRequestFileSystem) {
+ testFailed("window.webkitRequestFileSystem is not available.");
+ finishJSTest();
+ return;
+ }
+
+ webkitRequestFileSystem(TEMPORARY, fileSystemSize, didGetFileSystem, didFail);
+}
+
+function didGetFileSystem(fileSystem) {
+ testPassed("Got fileSystem");
+ fileSystem.root.getFile(fileName, {create: true}, didCreateFile, didFail);
+}
+
+function didCreateFile(entry) {
+ testPassed("File created.");
+ fileEntry = entry;
+ shouldBeTrue("fileEntry.isFile");
+ fileEntry.createWriter(didGetFileWriter, didFail);
+}
+
+function didGetFileWriter(writer) {
+ writer.truncate(0);
+ writer.onerror = function() {
+ testFailed("FileWriter operation failed.");
+ endTest();
+ };
+ writer.onwrite = function() {
+ writer.write(new Blob([messageToWrite]));
+ writer.onwrite = didWriteFile;
+ };
+}
+
+function didWriteFile() {
+ testPassed("Wrote to file.");
+ fileEntry.file(didGetFile, didFail);
+}
+
+var fileObject;
+
+function didGetFile(file) {
+ testPassed("Got File object successfully.");
+
+ fileObject = file;
+ dc.onmessage = dc_onmessage_file;
+ shouldNotThrow("dc.send(fileObject);");
+}
+
+function dc_onmessage_blob(e) {
+ testPassed("dc_onmessage_blob was called");
+ data = e.data;
+ shouldBeTrue("data instanceof window.Blob");
+
+ var reader = new FileReader();
+ reader.onload = function(event) {
+ if (checkReceivedBlobData(event.target.result)) {
+ testPassed("Blob data was reveived correctly.");
+ testSendFileBlob();
+ } else {
+ testFailed("Blob data should be received correctly");
+ endTest();
+ }
+ };
+ reader.readAsArrayBuffer(data);
+}
+
+function dc_onclose() {
+ testPassed("dc_onclose was called");
+ shouldBe("dc.readyState", "'closed'");
+
+ finishJSTest();
+}
+
+function dc_onopen() {
+ testPassed("dc_onopen was called");
+ shouldBe("dc.readyState", "'open'");
+ shouldBe("dc.label", "'label'");
+
+ dc.onmessage = dc_onmessage_blob;
+ blob = createBlobContainingAllDistinctBytes();
+ shouldNotThrow("dc.send(blob);");
+}
+
+function pc_onicechange() {
+ if (pc.iceConnectionState === "completed") {
+ testPassed("pc is connected");
+ shouldNotThrow('dc = pc.createDataChannel("label");');
+ shouldBe("dc.readyState", "'connecting'");
+ shouldBeEqualToString("dc.binaryType", "blob");
+ dc.onopen = dc_onopen;
+ dc.onclose = dc_onclose;
+ }
+}
+
+function pc_ondatachannel(e) {
+ testPassed("pc_ondatachannel was called");
+}
+
+function didFail(fileError) {
+ testFailed("FileSystem API operation failed: error code = " + fileError.code);
+ endTest();
+}
+
+function endTest() {
+ if (fileEntry) {
+ testPassed("Deleting the file.");
+ fileEntry.remove(finishJSTest, finishJSTest);
+ }
+ dc.onclose = dc_onclose;
+ dc.close();
+}
+
+pc = new webkitRTCPeerConnection(null, null);
+pc.oniceconnectionstatechange = pc_onicechange;
+pc.ondatachannel = pc_ondatachannel;
+
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698