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

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

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes 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();
19 gc.collectGarbage(); // should not crash 18 gc.collectGarbage(); // should not crash
20 this.result = "PASS"; 19 this.result = "PASS";
21 20
22 function runWithMessagePipe(test) { 21 function runWithMessagePipe(test) {
23 var pipe = core.createMessagePipe(); 22 var pipe = core.createMessagePipe();
24 expect(pipe.result).toBe(core.RESULT_OK); 23 expect(pipe.result).toBe(core.RESULT_OK);
25 24
26 test(pipe); 25 test(pipe);
27 26
28 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); 27 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 senderData[i] = i * i; 97 senderData[i] = i * i;
99 } 98 }
100 99
101 var write = core.writeData( 100 var write = core.writeData(
102 pipe.producerHandle, senderData, 101 pipe.producerHandle, senderData,
103 core.WRITE_DATA_FLAG_ALL_OR_NONE); 102 core.WRITE_DATA_FLAG_ALL_OR_NONE);
104 103
105 expect(write.result).toBe(core.RESULT_OK); 104 expect(write.result).toBe(core.RESULT_OK);
106 expect(write.numBytes).toBe(42); 105 expect(write.numBytes).toBe(42);
107 106
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
108 var read = core.readData( 117 var read = core.readData(
109 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE); 118 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
110 119
111 expect(read.result).toBe(core.RESULT_OK); 120 expect(read.result).toBe(core.RESULT_OK);
112 expect(read.buffer.byteLength).toBe(42); 121 expect(read.buffer.byteLength).toBe(42);
113 122
114 var memory = new Uint8Array(read.buffer); 123 var memory = new Uint8Array(read.buffer);
115 for (var i = 0; i < memory.length; ++i) 124 for (var i = 0; i < memory.length; ++i)
116 expect(memory[i]).toBe((i * i) & 0xFF); 125 expect(memory[i]).toBe((i * i) & 0xFF);
117 } 126 }
118 127
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
133 }); 128 });
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