Index: third_party/WebKit/LayoutTests/mojo/message-pipe.html |
diff --git a/third_party/WebKit/LayoutTests/mojo/message-pipe.html b/third_party/WebKit/LayoutTests/mojo/message-pipe.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4d2e307d7b5974af892d33d6eb35efbaf539baff |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/mojo/message-pipe.html |
@@ -0,0 +1,108 @@ |
+<!DOCTYPE html> |
+<title>Mojo message pipe tests</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script> |
+ |
+let testData = (() => { |
+ let dataIn = new Uint8Array(42); |
+ for (let i = 0; i < dataIn.length; ++i) |
+ dataIn[i] = i * i; |
+ |
+ return { |
+ read: (handle) => { |
jbroman
2017/01/27 20:35:16
super-nit: while you're being fancy with JavaScrip
alokp
2017/01/27 23:54:46
Nice. Done.
|
+ let {result, buffer, handles} = handle.readMessage(); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ assert_array_equals(handles, []); |
+ let dataOut = new Uint8Array(buffer); |
+ assert_equals(dataOut.length, dataIn.length); |
+ dataOut.every((value, index) => { assert_equals(value, dataIn[index]); }); |
jbroman
2017/01/27 20:35:16
nit: isn't this (and the previous line) what asser
alokp
2017/01/27 23:54:46
I was not sure if assert_array_equals works on typ
|
+ }, |
+ write: (handle) => { |
+ let result = handle.writeMessage(dataIn, []); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ } |
+ }; |
+})(); |
+ |
+test(() => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ assert_true(handle0 instanceof MojoHandle); |
+ assert_true(handle1 instanceof MojoHandle); |
+}, "Create pipe"); |
+ |
+test(() => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
jbroman
2017/01/27 20:35:16
nit: either check result or remove it from the des
alokp
2017/01/27 23:54:46
I thought it was necessary to extract all keys. Re
|
+ handle0.close(); |
+ { |
+ let {result, buffer, handles} = handle0.readMessage(); |
+ assert_equals(result, Mojo.RESULT_INVALID_ARGUMENT); |
+ } |
+}, "Read from invalid handle"); |
+ |
+test(() => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
+ { |
+ let {result, buffer, handles} = handle0.readMessage(); |
+ assert_equals(result, Mojo.RESULT_SHOULD_WAIT); |
+ } |
+}, "Read from empty pipe"); |
+ |
+test(() => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
+ handle0.close(); |
+ { |
+ let result = handle0.writeMessage(new ArrayBuffer(4), []); |
+ assert_equals(result, Mojo.RESULT_INVALID_ARGUMENT); |
+ } |
+}, "Write to invalid handle"); |
+ |
+async_test((test) => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
+ |
+ handle0.watch({readable: true}, test.step_func_done((result) => { |
+ assert_equals(result, Mojo.RESULT_OK); |
+ { |
+ let {result, buffer, handles} = handle0.readMessage(); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ assert_equals(buffer, undefined); |
+ assert_equals(handles, undefined); |
+ } |
+ })); |
+ { |
+ let result = handle1.writeMessage(new ArrayBuffer(0), []); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ } |
+}, "Send empty message"); |
+ |
+async_test((test) => { |
+ let {result, handle0, handle1} = Mojo.createMessagePipe(); |
+ |
+ handle0.watch({readable: true}, test.step_func_done((result) => { |
+ assert_equals(result, Mojo.RESULT_OK); |
+ testData.read(handle0); |
+ })); |
+ testData.write(handle1); |
+}, "Send buffer"); |
+ |
+async_test((test) => { |
+ let pipe1 = Mojo.createMessagePipe(); |
+ let pipe2 = Mojo.createMessagePipe(); |
+ pipe2.handle0.watch({readable: true}, test.step_func_done((result) => { |
+ assert_equals(result, Mojo.RESULT_OK); |
+ testData.read(pipe2.handle0); |
+ })); |
+ pipe1.handle0.watch({readable: true}, test.step_func((result) => { |
+ assert_equals(result, Mojo.RESULT_OK); |
+ { |
+ let {result, buffer, handles} = pipe1.handle0.readMessage(); |
+ assert_equals(result, Mojo.RESULT_OK); |
+ assert_equals(1, handles.length); |
+ testData.write(handles[0]); |
+ } |
+ })); |
+ pipe1.handle1.writeMessage(new ArrayBuffer(0), [pipe2.handle1]); |
+}, "Send handle"); |
+ |
+</script> |