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

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

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « mojo/public/js/core.js ('k') | mojo/public/js/threading.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 define([ 5 define([
6 "gin/test/expect", 6 "gin/test/expect",
7 "mojo/public/js/core", 7 "mojo/public/js/core",
8 "gc", 8 "gc",
9 ], function(expect, core, gc) { 9 ], function(expect, core, gc) {
10 runWithMessagePipe(testNop); 10 runWithMessagePipe(testNop);
11 runWithMessagePipe(testReadAndWriteMessage); 11 runWithMessagePipe(testReadAndWriteMessage);
12 runWithMessagePipeWithOptions(testNop); 12 runWithMessagePipeWithOptions(testNop);
13 runWithMessagePipeWithOptions(testReadAndWriteMessage); 13 runWithMessagePipeWithOptions(testReadAndWriteMessage);
14 runWithDataPipe(testNop); 14 runWithDataPipe(testNop);
15 runWithDataPipe(testReadAndWriteDataPipe); 15 runWithDataPipe(testReadAndWriteDataPipe);
16 runWithDataPipeWithOptions(testNop); 16 runWithDataPipeWithOptions(testNop);
17 runWithDataPipeWithOptions(testReadAndWriteDataPipe); 17 runWithDataPipeWithOptions(testReadAndWriteDataPipe);
18 testHandleToString();
18 gc.collectGarbage(); // should not crash 19 gc.collectGarbage(); // should not crash
19 this.result = "PASS"; 20 this.result = "PASS";
20 21
21 function runWithMessagePipe(test) { 22 function runWithMessagePipe(test) {
22 var pipe = core.createMessagePipe(); 23 var pipe = core.createMessagePipe();
23 expect(pipe.result).toBe(core.RESULT_OK); 24 expect(pipe.result).toBe(core.RESULT_OK);
24 25
25 test(pipe); 26 test(pipe);
26 27
27 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); 28 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 senderData[i] = i * i; 98 senderData[i] = i * i;
98 } 99 }
99 100
100 var write = core.writeData( 101 var write = core.writeData(
101 pipe.producerHandle, senderData, 102 pipe.producerHandle, senderData,
102 core.WRITE_DATA_FLAG_ALL_OR_NONE); 103 core.WRITE_DATA_FLAG_ALL_OR_NONE);
103 104
104 expect(write.result).toBe(core.RESULT_OK); 105 expect(write.result).toBe(core.RESULT_OK);
105 expect(write.numBytes).toBe(42); 106 expect(write.numBytes).toBe(42);
106 107
107 var peeked = core.readData(
108 pipe.consumerHandle,
109 core.READ_DATA_FLAG_PEEK | core.READ_DATA_FLAG_ALL_OR_NONE);
110 expect(peeked.result).toBe(core.RESULT_OK);
111 expect(peeked.buffer.byteLength).toBe(42);
112
113 var peeked_memory = new Uint8Array(peeked.buffer);
114 for (var i = 0; i < peeked_memory.length; ++i)
115 expect(peeked_memory[i]).toBe((i * i) & 0xFF);
116
117 var read = core.readData( 108 var read = core.readData(
118 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE); 109 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
119 110
120 expect(read.result).toBe(core.RESULT_OK); 111 expect(read.result).toBe(core.RESULT_OK);
121 expect(read.buffer.byteLength).toBe(42); 112 expect(read.buffer.byteLength).toBe(42);
122 113
123 var memory = new Uint8Array(read.buffer); 114 var memory = new Uint8Array(read.buffer);
124 for (var i = 0; i < memory.length; ++i) 115 for (var i = 0; i < memory.length; ++i)
125 expect(memory[i]).toBe((i * i) & 0xFF); 116 expect(memory[i]).toBe((i * i) & 0xFF);
126 } 117 }
127 118
119 function testHandleToString() {
120 var pipe = core.createDataPipe();
121 expect(pipe.consumerHandle.toString).toBeDefined();
122
123 var openHandleRE = /^\[mojo\:\:Handle \d+\]$/ // e.g. "[mojo::Handle 123]"
124 var openHandleString = pipe.consumerHandle.toString();
125 expect(openHandleString.match(openHandleRE)[0]).toEqual(openHandleString);
126
127 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
128 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
129
130 expect(pipe.consumerHandle.toString()).toEqual("[mojo::Handle null]");
131 }
132
128 }); 133 });
OLDNEW
« no previous file with comments | « mojo/public/js/core.js ('k') | mojo/public/js/threading.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698