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

Side by Side Diff: mojo/public/bindings/js/core_unittests.js

Issue 62333018: Implement Asynchronous Module Definition API for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar testing 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 function runWithPipe(mojo, test) { 5 define(["gtest", "core"], function(gtest, core) {
6 var pipe = mojo.core.createMessagePipe(); 6 runWithPipe(testNop);
7 runWithPipe(testReadAndWriteMessage);
8 this.result = "PASS";
7 9
8 test(mojo, pipe); 10 function runWithPipe(test) {
11 var pipe = core.createMessagePipe();
9 12
10 var result0 = mojo.core.close(pipe.handle0); 13 test(pipe);
11 mojo.gtest.expectEqual(result0, mojo.core.RESULT_OK,
12 "result0 is " + result0);
13 14
14 var result1 = mojo.core.close(pipe.handle1); 15 var result0 = core.close(pipe.handle0);
15 mojo.gtest.expectEqual(result1, mojo.core.RESULT_OK, 16 gtest.expectEqual(result0, core.RESULT_OK,
16 "result1 is " + result1); 17 "result0 is " + result0);
17 }
18 18
19 function testNop(mojo, pipe) { 19 var result1 = core.close(pipe.handle1);
20 } 20 gtest.expectEqual(result1, core.RESULT_OK,
21 21 "result1 is " + result1);
22 function testReadAndWriteMessage(mojo, pipe) {
23 var senderData = new Uint8Array(42);
24 for (var i = 0; i < senderData.length; ++i) {
25 senderData[i] = i * i;
26 } 22 }
27 23
28 var result = mojo.core.writeMessage( 24 function testNop(pipe) {
29 pipe.handle0, senderData, [], 25 }
30 mojo.core.WRITE_MESSAGE_FLAG_NONE);
31 26
32 mojo.gtest.expectEqual(result, mojo.core.RESULT_OK, 27 function testReadAndWriteMessage(pipe) {
33 "writeMessage returned RESULT_OK: " + result); 28 var senderData = new Uint8Array(42);
29 for (var i = 0; i < senderData.length; ++i) {
30 senderData[i] = i * i;
31 }
34 32
35 var receiverData = new Uint8Array(50); 33 var result = core.writeMessage(
34 pipe.handle0, senderData, [],
35 core.WRITE_MESSAGE_FLAG_NONE);
36 36
37 var mesage = mojo.core.readMessage( 37 gtest.expectEqual(result, core.RESULT_OK,
38 pipe.handle1, receiverData, 10, 38 "writeMessage returned RESULT_OK: " + result);
39 mojo.core.READ_MESSAGE_FLAG_NONE)
40 39
41 mojo.gtest.expectEqual(mesage.result, mojo.core.RESULT_OK, 40 var receiverData = new Uint8Array(50);
42 "mesage.result is " + mesage.result);
43 mojo.gtest.expectEqual(mesage.bytesRead, 42,
44 "mesage.bytesRead is " + mesage.bytesRead);
45 mojo.gtest.expectEqual(mesage.handles.length, 0,
46 "mesage.handles.length is " + mesage.handles.length);
47 41
48 for (var i = 0; i < mesage.bytesRead; ++i) { 42 var mesage = core.readMessage(
49 mojo.gtest.expectEqual(receiverData[i], (i * i) & 0xFF, 43 pipe.handle1, receiverData, 10,
50 "receiverData[" + i + "] is " + receiverData[i]); 44 core.READ_MESSAGE_FLAG_NONE)
45
46 gtest.expectEqual(mesage.result, core.RESULT_OK,
47 "mesage.result is " + mesage.result);
48 gtest.expectEqual(mesage.bytesRead, 42,
49 "mesage.bytesRead is " + mesage.bytesRead);
50 gtest.expectEqual(mesage.handles.length, 0,
51 "mesage.handles.length is " + mesage.handles.length);
52
53 for (var i = 0; i < mesage.bytesRead; ++i) {
54 gtest.expectEqual(receiverData[i], (i * i) & 0xFF,
55 "receiverData[" + i + "] is " + receiverData[i]);
56 }
51 } 57 }
52 } 58 });
53
54 function main(mojo) {
55 runWithPipe(mojo, testNop);
56 runWithPipe(mojo, testReadAndWriteMessage);
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698