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

Side by Side Diff: content/test/data/web_ui_mojo.js

Issue 250713003: Test sending corrupt mojo messages back from javascript. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Uint32 => Uint8 for consistency. Created 6 years, 8 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
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('main', [ 5 define('main', [
6 'mojo/public/js/bindings/connection', 6 'mojo/public/js/bindings/connection',
7 'content/test/data/web_ui_test_mojo_bindings.mojom', 7 'content/test/data/web_ui_test_mojo_bindings.mojom',
8 ], function (connection, bindings) { 8 ], function (connection, bindings) {
9 var retainedConnection, kIterations = 100, kBadValue = 13; 9 var kBadValue = 13;
10 var fuzzerInstalled = false;
11 var retainedConnection;
10 12
11 function RendererTargetTest(bindings) { 13 function RendererTargetTest(bindings) {
12 this.bindings_ = bindings; 14 this.bindings_ = bindings;
13 } 15 }
14 16
15 // TODO(aa): It is a bummer to need this stub object in JavaScript. We should 17 // TODO(aa): It is a bummer to need this stub object in JavaScript. We should
16 // have a 'client' object that contains both the sending and receiving bits of 18 // have a 'client' object that contains both the sending and receiving bits of
17 // the client side of the interface. Since JS is loosely typed, we do not need 19 // the client side of the interface. Since JS is loosely typed, we do not need
18 // a separate base class to inherit from to receive callbacks. 20 // a separate base class to inherit from to receive callbacks.
19 RendererTargetTest.prototype = 21 RendererTargetTest.prototype =
20 Object.create(bindings.RendererTargetStub.prototype); 22 Object.create(bindings.RendererTargetStub.prototype);
21 23
22 RendererTargetTest.prototype.ping = function () { 24 RendererTargetTest.prototype.ping = function () {
23 this.bindings_.pingResponse(); 25 this.bindings_.pingResponse();
24 }; 26 };
25 27
26 RendererTargetTest.prototype.echo = function (arg) { 28 RendererTargetTest.prototype.echo = function (iterations, arg) {
27 var i; 29 var i;
28 30
29 // Ensure negative values are negative. 31 // Ensure negative values are negative.
30 if (arg.si64 > 0) 32 if (arg.si64 > 0)
31 arg.si64 = kBadValue; 33 arg.si64 = kBadValue;
32 34
33 if (arg.si32 > 0) 35 if (arg.si32 > 0)
34 arg.si32 = kBadValue; 36 arg.si32 = kBadValue;
35 37
36 if (arg.si16 > 0) 38 if (arg.si16 > 0)
37 arg.si16 = kBadValue; 39 arg.si16 = kBadValue;
38 40
39 if (arg.si8 > 0) 41 if (arg.si8 > 0)
40 arg.si8 = kBadValue; 42 arg.si8 = kBadValue;
41 43
42 for (i = 0; i < kIterations; ++i) { 44 for (i = 0; i < iterations; ++i) {
43 arg2 = new bindings.EchoArgs(); 45 arg2 = new bindings.EchoArgs();
44 arg2.si64 = -1; 46 arg2.si64 = -1;
45 arg2.si32 = -1; 47 arg2.si32 = -1;
46 arg2.si16 = -1; 48 arg2.si16 = -1;
47 arg2.si8 = -1; 49 arg2.si8 = -1;
48 arg2.name = "going"; 50 arg2.name = "going";
49 this.bindings_.echoResponse(arg, arg2); 51 this.bindings_.echoResponse(arg, arg2);
50 } 52 }
51 }; 53 };
52 54
55 RendererTargetTest.prototype.flipBits = function (iterations, arg) {
56 var i;
57 if (!fuzzerInstalled) {
58 retainedConnection.setFuzzer((function () {
59 var iteration = 0;
60 return function (message) {
61 var offset = iteration / 8;
62 var mask = 1 << (iteration % 8);
63 var value = message.buffer.dataView.getUint8(offset) ^ mask;
64 message.buffer.dataView.setUint8(offset, value);
65 iteration += 1;
66 }
67 })());
abarth-chromium 2014/04/25 00:36:48 Rather than hooking in like this, you should be ab
68 fuzzerInstalled = true;
69 console.log('Tests running with fuzzers enabled.');
70 }
71 for (i = 0; i < iterations; ++i)
72 this.bindings_.flipBitsResponse(arg);
73 };
74
53 return function(handle) { 75 return function(handle) {
54 retainedConnection = new connection.Connection( 76 retainedConnection = new connection.Connection(
55 handle, RendererTargetTest, bindings.BrowserTargetProxy); 77 handle, RendererTargetTest, bindings.BrowserTargetProxy);
56 }; 78 };
57 }); 79 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698