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

Side by Side Diff: mojo/apps/js/test/js_to_cpp_unittest.js

Issue 250713003: Test sending corrupt mojo messages back from javascript. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 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/apps/js/test/js_to_cpp_unittest.cc ('k') | no next file » | 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("mojo/apps/js/test/js_to_cpp_unittest", [ 5 define("mojo/apps/js/test/js_to_cpp_unittest", [
6 "mojo/apps/js/test/js_to_cpp.mojom", 6 "mojo/apps/js/test/js_to_cpp.mojom",
7 "mojo/public/js/bindings/connection", 7 "mojo/public/js/bindings/connection",
8 ], function(jsToCpp, connector) { 8 "mojo/public/js/bindings/connector",
9 var connection, kIterations = 100, kBadValue = 13; 9 ], function(jsToCpp, connection, connector) {
10 var retainedConnection, kBadValue = 13;
10 11
11 function JsSideConnection(cppSide) { 12 function JsSideConnection(cppSide) {
12 this.cppSide_ = cppSide; 13 this.cppSide_ = cppSide;
13 cppSide.startTest(); 14 cppSide.startTest();
14 } 15 }
15 16
16 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype); 17 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype);
17 18
18 JsSideConnection.prototype.ping = function (arg) { 19 JsSideConnection.prototype.ping = function (arg) {
19 this.cppSide_.pingResponse(); 20 this.cppSide_.pingResponse();
20 21
21 }; 22 };
22 23
23 JsSideConnection.prototype.echo = function (arg) { 24 JsSideConnection.prototype.echo = function (numIterations, arg) {
24 var i, arg2; 25 var arg2;
26 var i;
25 27
26 // Ensure negative values are negative. 28 // Ensure negative values are negative.
27 if (arg.si64 > 0) 29 if (arg.si64 > 0)
28 arg.si64 = kBadValue; 30 arg.si64 = kBadValue;
29 31
30 if (arg.si32 > 0) 32 if (arg.si32 > 0)
31 arg.si32 = kBadValue; 33 arg.si32 = kBadValue;
32 34
33 if (arg.si16 > 0) 35 if (arg.si16 > 0)
34 arg.si16 = kBadValue; 36 arg.si16 = kBadValue;
35 37
36 if (arg.si8 > 0) 38 if (arg.si8 > 0)
37 arg.si8 = kBadValue; 39 arg.si8 = kBadValue;
38 40
39 for (i = 0; i < kIterations; ++i) { 41 for (i = 0; i < numIterations; ++i) {
40 arg2 = new jsToCpp.EchoArgs(); 42 arg2 = new jsToCpp.EchoArgs();
41 arg2.si64 = -1; 43 arg2.si64 = -1;
42 arg2.si32 = -1; 44 arg2.si32 = -1;
43 arg2.si16 = -1; 45 arg2.si16 = -1;
44 arg2.si8 = -1; 46 arg2.si8 = -1;
45 arg2.name = "going"; 47 arg2.name = "going";
46 this.cppSide_.echoResponse(arg, arg2); 48 this.cppSide_.echoResponse(arg, arg2);
47 } 49 }
50 this.cppSide_.testFinished();
51 };
52
53 JsSideConnection.prototype.bitFlip = function (arg) {
54 var iteration = 0;
55 var stopSignalled = false;
56 var proto = connector.Connector.prototype;
57 proto.realAccept = proto.accept;
58 proto.accept = function (message) {
59 var offset = iteration / 8;
60 var mask;
61 var value;
62 if (offset < message.buffer.arrayBuffer.byteLength) {
63 mask = 1 << (iteration % 8);
64 value = message.buffer.dataView.getUint8(offset) ^ mask;
65 message.buffer.dataView.setUint8(offset, value);
66 return this.realAccept(message);
67 }
68 stopSignalled = true;
69 return false;
70 };
71 while (!stopSignalled) {
72 this.cppSide_.bitFlipResponse(arg);
73 iteration += 1;
74 }
75 proto.accept = proto.realAccept;
76 proto.realAccept = null;
77 this.cppSide_.testFinished();
48 }; 78 };
49 79
50 return function(handle) { 80 return function(handle) {
51 connection = new connector.Connection(handle, JsSideConnection, 81 retainedConnection = new connection.Connection(handle, JsSideConnection,
52 jsToCpp.CppSideProxy); 82 jsToCpp.CppSideProxy);
53 }; 83 };
54 }); 84 });
OLDNEW
« no previous file with comments | « mojo/apps/js/test/js_to_cpp_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698