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

Unified Diff: mojo/public/bindings/js/core_unittests.js

Issue 67173007: Add more unit tests for JS bindings to Core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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: mojo/public/bindings/js/core_unittests.js
diff --git a/mojo/public/bindings/js/core_unittests.js b/mojo/public/bindings/js/core_unittests.js
new file mode 100644
index 0000000000000000000000000000000000000000..2c085489c59180fa8dc54b2d106de1dd8a352790
--- /dev/null
+++ b/mojo/public/bindings/js/core_unittests.js
@@ -0,0 +1,57 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function runWithPipe(mojo, test) {
+ var pipe = mojo.core.createMessagePipe();
+
+ test(mojo, pipe);
+
+ var result0 = mojo.core.close(pipe.handle0);
+ mojo.gtest.expectEqual(result0, mojo.core.RESULT_OK,
+ "result0 is " + result0);
+
+ var result1 = mojo.core.close(pipe.handle1);
+ mojo.gtest.expectEqual(result1, mojo.core.RESULT_OK,
+ "result1 is " + result1);
+}
+
+function testNop(mojo, pipe) {
+}
+
+function testReadAndWriteMessage(mojo, pipe) {
+ var senderData = new Uint8Array(42);
+ for (var i = 0; i < senderData.length; ++i) {
+ senderData[i] = i * i;
+ }
+
+ var result = mojo.core.writeMessage(
+ pipe.handle0, senderData, [],
+ mojo.core.WRITE_MESSAGE_FLAG_NONE);
+
+ mojo.gtest.expectEqual(result, mojo.core.RESULT_OK,
+ "writeMessage returned RESULT_OK: " + result);
+
+ var receiverData = new Uint8Array(50);
+
+ var mesage = mojo.core.readMessage(
+ pipe.handle1, receiverData, 10,
+ mojo.core.READ_MESSAGE_FLAG_NONE)
+
+ mojo.gtest.expectEqual(mesage.result, mojo.core.RESULT_OK,
+ "mesage.result is " + mesage.result);
+ mojo.gtest.expectEqual(mesage.bytesRead, 42,
+ "mesage.bytesRead is " + mesage.bytesRead);
+ mojo.gtest.expectEqual(mesage.handles.length, 0,
+ "mesage.handles.length is " + mesage.handles.length);
+
+ for (var i = 0; i < mesage.bytesRead; ++i) {
+ mojo.gtest.expectEqual(receiverData[i], (i * i) & 0xFF,
+ "receiverData[" + i + "] is " + receiverData[i]);
+ }
+}
+
+function main(mojo) {
+ runWithPipe(mojo, testNop);
+ runWithPipe(mojo, testReadAndWriteMessage);
+}

Powered by Google App Engine
This is Rietveld 408576698