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

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

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 5 years, 11 months 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/router.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
11 var HANDLE_SIGNAL_READWRITABLE = core.HANDLE_SIGNAL_WRITABLE |
12 core.HANDLE_SIGNAL_READABLE;
13 var HANDLE_SIGNAL_ALL = core.HANDLE_SIGNAL_WRITABLE |
14 core.HANDLE_SIGNAL_READABLE |
15 core.HANDLE_SIGNAL_PEER_CLOSED;
16
10 runWithMessagePipe(testNop); 17 runWithMessagePipe(testNop);
11 runWithMessagePipe(testReadAndWriteMessage); 18 runWithMessagePipe(testReadAndWriteMessage);
12 runWithMessagePipeWithOptions(testNop); 19 runWithMessagePipeWithOptions(testNop);
13 runWithMessagePipeWithOptions(testReadAndWriteMessage); 20 runWithMessagePipeWithOptions(testReadAndWriteMessage);
14 runWithDataPipe(testNop); 21 runWithDataPipe(testNop);
15 runWithDataPipe(testReadAndWriteDataPipe); 22 runWithDataPipe(testReadAndWriteDataPipe);
16 runWithDataPipeWithOptions(testNop); 23 runWithDataPipeWithOptions(testNop);
17 runWithDataPipeWithOptions(testReadAndWriteDataPipe); 24 runWithDataPipeWithOptions(testReadAndWriteDataPipe);
25 runWithMessagePipe(testIsHandleMessagePipe);
26 runWithDataPipe(testIsHandleDataPipe);
18 gc.collectGarbage(); // should not crash 27 gc.collectGarbage(); // should not crash
19 this.result = "PASS"; 28 this.result = "PASS";
20 29
21 function runWithMessagePipe(test) { 30 function runWithMessagePipe(test) {
22 var pipe = core.createMessagePipe(); 31 var pipe = core.createMessagePipe();
23 expect(pipe.result).toBe(core.RESULT_OK); 32 expect(pipe.result).toBe(core.RESULT_OK);
24 33
25 test(pipe); 34 test(pipe);
26 35
27 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); 36 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 test(pipe); 70 test(pipe);
62 71
63 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK); 72 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
64 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK); 73 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
65 } 74 }
66 75
67 function testNop(pipe) { 76 function testNop(pipe) {
68 } 77 }
69 78
70 function testReadAndWriteMessage(pipe) { 79 function testReadAndWriteMessage(pipe) {
80 var wait = core.waitMany([], [], 0);
81 expect(wait.result).toBe(core.RESULT_INVALID_ARGUMENT);
82 expect(wait.index).toBe(null);
83 expect(wait.signalsState).toBe(null);
84
85 wait = core.wait(pipe.handle0, core.HANDLE_SIGNAL_READABLE, 0);
86 expect(wait.result).toBe(core.RESULT_DEADLINE_EXCEEDED);
87 expect(wait.signalsState.satisfiedSignals).toBe(
88 core.HANDLE_SIGNAL_WRITABLE);
89 expect(wait.signalsState.satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
90
91 wait = core.waitMany(
92 [pipe.handle0, pipe.handle1],
93 [core.HANDLE_SIGNAL_READABLE,core.HANDLE_SIGNAL_READABLE],
94 0);
95 expect(wait.result).toBe(core.RESULT_DEADLINE_EXCEEDED);
96 expect(wait.index).toBe(null);
97 expect(wait.signalsState[0].satisfiedSignals).toBe(
98 core.HANDLE_SIGNAL_WRITABLE);
99 expect(wait.signalsState[0].satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
100 expect(wait.signalsState[1].satisfiedSignals).toBe(
101 core.HANDLE_SIGNAL_WRITABLE);
102 expect(wait.signalsState[1].satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
103
104 wait = core.wait(pipe.handle0, core.HANDLE_SIGNAL_WRITABLE, 0);
105 expect(wait.result).toBe(core.RESULT_OK);
106 expect(wait.signalsState.satisfiedSignals).toBe(
107 core.HANDLE_SIGNAL_WRITABLE);
108 expect(wait.signalsState.satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
109
71 var senderData = new Uint8Array(42); 110 var senderData = new Uint8Array(42);
72 for (var i = 0; i < senderData.length; ++i) { 111 for (var i = 0; i < senderData.length; ++i) {
73 senderData[i] = i * i; 112 senderData[i] = i * i;
74 } 113 }
75 114
76 var result = core.writeMessage( 115 var result = core.writeMessage(
77 pipe.handle0, senderData, [], 116 pipe.handle0, senderData, [],
78 core.WRITE_MESSAGE_FLAG_NONE); 117 core.WRITE_MESSAGE_FLAG_NONE);
79 118
80 expect(result).toBe(core.RESULT_OK); 119 expect(result).toBe(core.RESULT_OK);
81 120
121 wait = core.waitMany(
122 [pipe.handle0, pipe.handle1],
123 [core.HANDLE_SIGNAL_WRITABLE,core.HANDLE_SIGNAL_WRITABLE],
124 0);
125 expect(wait.result).toBe(core.RESULT_OK);
126 expect(wait.index).toBe(0);
127 expect(wait.signalsState[0].satisfiedSignals).toBe(
128 core.HANDLE_SIGNAL_WRITABLE);
129 expect(wait.signalsState[0].satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
130 expect(wait.signalsState[1].satisfiedSignals).toBe(
131 HANDLE_SIGNAL_READWRITABLE);
132 expect(wait.signalsState[1].satisfiableSignals).toBe(HANDLE_SIGNAL_ALL);
133
82 var read = core.readMessage( 134 var read = core.readMessage(
83 pipe.handle1, core.READ_MESSAGE_FLAG_NONE); 135 pipe.handle1, core.READ_MESSAGE_FLAG_NONE);
84 136
85 expect(read.result).toBe(core.RESULT_OK); 137 expect(read.result).toBe(core.RESULT_OK);
86 expect(read.buffer.byteLength).toBe(42); 138 expect(read.buffer.byteLength).toBe(42);
87 expect(read.handles.length).toBe(0); 139 expect(read.handles.length).toBe(0);
88 140
89 var memory = new Uint8Array(read.buffer); 141 var memory = new Uint8Array(read.buffer);
90 for (var i = 0; i < memory.length; ++i) 142 for (var i = 0; i < memory.length; ++i)
91 expect(memory[i]).toBe((i * i) & 0xFF); 143 expect(memory[i]).toBe((i * i) & 0xFF);
(...skipping 26 matching lines...) Expand all
118 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE); 170 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
119 171
120 expect(read.result).toBe(core.RESULT_OK); 172 expect(read.result).toBe(core.RESULT_OK);
121 expect(read.buffer.byteLength).toBe(42); 173 expect(read.buffer.byteLength).toBe(42);
122 174
123 var memory = new Uint8Array(read.buffer); 175 var memory = new Uint8Array(read.buffer);
124 for (var i = 0; i < memory.length; ++i) 176 for (var i = 0; i < memory.length; ++i)
125 expect(memory[i]).toBe((i * i) & 0xFF); 177 expect(memory[i]).toBe((i * i) & 0xFF);
126 } 178 }
127 179
180 function testIsHandleMessagePipe(pipe) {
181 expect(core.isHandle(123).toBeFalsy);
182 expect(core.isHandle("123").toBeFalsy);
183 expect(core.isHandle({}).toBeFalsy);
184 expect(core.isHandle([]).toBeFalsy);
185 expect(core.isHandle(undefined).toBeFalsy);
186 expect(core.isHandle(pipe).toBeFalsy);
187 expect(core.isHandle(pipe.handle0)).toBeTruthy();
188 expect(core.isHandle(pipe.handle1)).toBeTruthy();
189 expect(core.isHandle(null)).toBeTruthy();
190 }
191
192 function testIsHandleDataPipe(pipe) {
193 expect(core.isHandle(pipe.consumerHandle)).toBeTruthy();
194 expect(core.isHandle(pipe.producerHandle)).toBeTruthy();
195 }
196
128 }); 197 });
OLDNEW
« no previous file with comments | « mojo/public/js/core.js ('k') | mojo/public/js/router.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698