1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
define([
"gtest",
// TODO(abarth): We shouldn't need to depend on codec, but there seems to
// be a bug in the module loading system whereby this test doesn't run if
// we don't import codec here.
"mojo/public/bindings/js/codec",
"mojo/public/bindings/sample/mojom/sample_service"
], function(gtest, codec, sample) {
var global = this;
function makeFoo() {
var bar = new sample.Bar();
bar.alpha = 20;
bar.beta = 40;
bar.gamma = 60;
var extra_bars = new Array(3);
for (var i = 0; i < extra_bars.length; ++i) {
var base = i * 100;
extra_bars[i] = new sample.Bar();
extra_bars[i].alpha = base;
extra_bars[i].beta = base + 20;
extra_bars[i].gamma = base + 40;
}
var data = new Array(10);
for (var i = 0; i < data.length; ++i) {
data[i] = data.length - i;
}
var files = new Array(4);
for (var i = 0; i < files.length; ++i) {
files[i] = 0xFFFF - i;
}
var foo = new sample.Foo();
foo.name = "foopy";
foo.x = 1;
foo.y = 2;
foo.a = false;
foo.b = true;
foo.c = false;
foo.bar = bar;
foo.extra_bars = extra_bars;
foo.data = data;
foo.files = files;
return foo;
}
// Check that the given |Foo| is identical to the one made by |MakeFoo()|.
function checkFoo(foo) {
gtest.expectEqual(foo.name, "foopy", "foo.name is " + foo.name);
gtest.expectEqual(foo.x, 1, "foo.x is " + foo.x);
gtest.expectEqual(foo.y, 2, "foo.y is " + foo.y);
gtest.expectFalse(foo.a, "foo.a is " + foo.a);
gtest.expectTrue(foo.b, "foo.b is " + foo.b);
gtest.expectFalse(foo.c, "foo.c is " + foo.c);
gtest.expectEqual(foo.bar.alpha, 20, "foo.bar.alpha is " + foo.bar.alpha);
gtest.expectEqual(foo.bar.beta, 40, "foo.bar.beta is " + foo.bar.beta);
gtest.expectEqual(foo.bar.gamma, 60, "foo.bar.gamma is " + foo.bar.gamma);
gtest.expectEqual(foo.extra_bars.length, 3,
"foo.extra_bars.length is " + foo.extra_bars.length);
for (var i = 0; i < foo.extra_bars.length; ++i) {
var base = i * 100;
gtest.expectEqual(foo.extra_bars[i].alpha, base,
"foo.extra_bars[" + i + "].alpha is " + foo.extra_bars[i].alpha);
gtest.expectEqual(foo.extra_bars[i].beta, base + 20,
"foo.extra_bars[" + i + "].beta is " + foo.extra_bars[i].beta);
gtest.expectEqual(foo.extra_bars[i].gamma, base + 40,
"foo.extra_bars[" + i + "].gamma is " + foo.extra_bars[i].gamma);
}
gtest.expectEqual(foo.data.length, 10,
"foo.data.length is " + foo.data.length);
for (var i = 0; i < foo.data.length; ++i) {
gtest.expectEqual(foo.data[i], foo.data.length - i,
"foo.data[" + i + "] is " + foo.data[i]);
}
gtest.expectEqual(foo.files.length, 4,
"foo.files.length " + foo.files.length);
for (var i = 0; i < foo.files.length; ++i) {
gtest.expectEqual(foo.files[i], 0xFFFF - i,
"foo.files[" + i + "] is " + foo.files[i]);
}
}
function ServiceImpl() {
}
ServiceImpl.prototype = Object.create(sample.ServiceStub.prototype);
ServiceImpl.prototype.frobinate = function(foo, baz, port) {
checkFoo(foo);
gtest.expectTrue(baz, "baz is " + baz);
gtest.expectEqual(port, 10, "port is " + port);
global.result = "PASS";
};
function SimpleMessageReceiver() {
}
SimpleMessageReceiver.prototype.accept = function(message) {
// Imagine some IPC happened here.
var serviceImpl = new ServiceImpl();
serviceImpl.accept(message);
};
var receiver = new SimpleMessageReceiver();
var serviceProxy = new sample.ServiceProxy(receiver);
var foo = makeFoo();
checkFoo(foo);
var port = 10;
serviceProxy.frobinate(foo, true, port);
});
|