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

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

Issue 411553003: Validate incoming JS Message Headers: test message parser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed WebUIMojoTest.EndToEndPing Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « mojo/bindings/js/codec_unittests.js ('k') | mojo/bindings/js/run_js_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 define([
6 "gin/test/expect",
7 "mojo/public/js/bindings/core",
8 "gc",
9 ], function(expect, core, gc) {
10 runWithMessagePipe(testNop);
11 runWithMessagePipe(testReadAndWriteMessage);
12 runWithMessagePipeWithOptions(testNop);
13 runWithMessagePipeWithOptions(testReadAndWriteMessage);
14 runWithDataPipe(testNop);
15 runWithDataPipe(testReadAndWriteDataPipe);
16 runWithDataPipeWithOptions(testNop);
17 runWithDataPipeWithOptions(testReadAndWriteDataPipe);
18 gc.collectGarbage(); // should not crash
19 this.result = "PASS";
20
21 function runWithMessagePipe(test) {
22 var pipe = core.createMessagePipe();
23 expect(pipe.result).toBe(core.RESULT_OK);
24
25 test(pipe);
26
27 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
28 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK);
29 }
30
31 function runWithMessagePipeWithOptions(test) {
32 var pipe = core.createMessagePipe({
33 flags: core.CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE
34 });
35 expect(pipe.result).toBe(core.RESULT_OK);
36
37 test(pipe);
38
39 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
40 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK);
41 }
42
43 function runWithDataPipe(test) {
44 var pipe = core.createDataPipe();
45 expect(pipe.result).toBe(core.RESULT_OK);
46
47 test(pipe);
48
49 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
50 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
51 }
52
53 function runWithDataPipeWithOptions(test) {
54 var pipe = core.createDataPipe({
55 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
56 elementNumBytes: 1,
57 capacityNumBytes: 64
58 });
59 expect(pipe.result).toBe(core.RESULT_OK);
60
61 test(pipe);
62
63 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
64 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
65 }
66
67 function testNop(pipe) {
68 }
69
70 function testReadAndWriteMessage(pipe) {
71 var senderData = new Uint8Array(42);
72 for (var i = 0; i < senderData.length; ++i) {
73 senderData[i] = i * i;
74 }
75
76 var result = core.writeMessage(
77 pipe.handle0, senderData, [],
78 core.WRITE_MESSAGE_FLAG_NONE);
79
80 expect(result).toBe(core.RESULT_OK);
81
82 var read = core.readMessage(
83 pipe.handle1, core.READ_MESSAGE_FLAG_NONE);
84
85 expect(read.result).toBe(core.RESULT_OK);
86 expect(read.buffer.byteLength).toBe(42);
87 expect(read.handles.length).toBe(0);
88
89 var memory = new Uint8Array(read.buffer);
90 for (var i = 0; i < memory.length; ++i)
91 expect(memory[i]).toBe((i * i) & 0xFF);
92 }
93
94 function testReadAndWriteDataPipe(pipe) {
95 var senderData = new Uint8Array(42);
96 for (var i = 0; i < senderData.length; ++i) {
97 senderData[i] = i * i;
98 }
99
100 var write = core.writeData(
101 pipe.producerHandle, senderData,
102 core.WRITE_DATA_FLAG_ALL_OR_NONE);
103
104 expect(write.result).toBe(core.RESULT_OK);
105 expect(write.numBytes).toBe(42);
106
107 var read = core.readData(
108 pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
109
110 expect(read.result).toBe(core.RESULT_OK);
111 expect(read.buffer.byteLength).toBe(42);
112
113 var memory = new Uint8Array(read.buffer);
114 for (var i = 0; i < memory.length; ++i)
115 expect(memory[i]).toBe((i * i) & 0xFF);
116 }
117
118 });
OLDNEW
« no previous file with comments | « mojo/bindings/js/codec_unittests.js ('k') | mojo/bindings/js/run_js_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698