summaryrefslogtreecommitdiffstats
path: root/mojo/apps/js/bindings
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-28 06:03:43 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-28 06:03:43 +0000
commit811f5f2f1776b0f3ca85928779080e1cc3e283a7 (patch)
tree33657d55d5cf0b9cadcb35a9ae8efdc92d3e68e0 /mojo/apps/js/bindings
parent9bda4b5057f853a6f9ad8ea9601e335f4f868fe4 (diff)
downloadchromium_src-811f5f2f1776b0f3ca85928779080e1cc3e283a7.zip
chromium_src-811f5f2f1776b0f3ca85928779080e1cc3e283a7.tar.gz
chromium_src-811f5f2f1776b0f3ca85928779080e1cc3e283a7.tar.bz2
Mojo: re-organize public/bindings/ directory
The plan: - mojo/public/{subdir} contains public headers and scripts (if any). - mojo/public/{subdir}/lib contains private headers and .cc files (if any). - mojo/public/{subdir}/tests contains test files. This CL only implements the plan for the public/bindings/ directory. Other directories will follow. In addition, bindings header files are broken up a bit. In particular, buffer.{h,cc} are carved up so that buffer.h can only contain public bits. This necessitates creation of allocation_scope.h. I extracted type_converter.h instead of letting it be buried inside array_internal.h. This CL nukes bindings/sample/. R=viettrungluu@chromium.org Review URL: https://codereview.chromium.org/141703007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/apps/js/bindings')
-rw-r--r--mojo/apps/js/bindings/sample_service_unittests.js136
1 files changed, 136 insertions, 0 deletions
diff --git a/mojo/apps/js/bindings/sample_service_unittests.js b/mojo/apps/js/bindings/sample_service_unittests.js
new file mode 100644
index 0000000..9b9165d
--- /dev/null
+++ b/mojo/apps/js/bindings/sample_service_unittests.js
@@ -0,0 +1,136 @@
+// 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([
+ "console",
+ "mojo/apps/js/test/hexdump",
+ "gin/test/expect",
+ "mojom/sample_service"
+ ], function(console, hexdump, expect, sample) {
+
+ var global = this;
+
+ // Set this variable to true to print the binary message in hex.
+ var dumpMessageAsHex = false;
+
+ function makeFoo() {
+ var bar = new sample.Bar();
+ bar.alpha = 20;
+ bar.beta = 40;
+ bar.gamma = 60;
+ bar.type = sample.BarType.BAR_VERTICAL;
+
+ var extra_bars = new Array(3);
+ for (var i = 0; i < extra_bars.length; ++i) {
+ var base = i * 100;
+ var type = i % 2 ?
+ sample.BarType.BAR_VERTICAL : sample.BarType.BAR_HORIZONTAL;
+ extra_bars[i] = new sample.Bar();
+ extra_bars[i].alpha = base;
+ extra_bars[i].beta = base + 20;
+ extra_bars[i].gamma = base + 40;
+ extra_bars[i].type = type;
+ }
+
+ var data = new Array(10);
+ for (var i = 0; i < data.length; ++i) {
+ data[i] = data.length - i;
+ }
+
+ var source = 0xFFFF; // Invent a dummy handle.
+
+ 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.source = source;
+ return foo;
+ }
+
+ // Check that the given |Foo| is identical to the one made by |MakeFoo()|.
+ function checkFoo(foo) {
+ expect(foo.name).toBe("foopy");
+ expect(foo.x).toBe(1);
+ expect(foo.y).toBe(2);
+ expect(foo.a).toBeFalsy();
+ expect(foo.b).toBeTruthy();
+ expect(foo.c).toBeFalsy();
+ expect(foo.bar.alpha).toBe(20);
+ expect(foo.bar.beta).toBe(40);
+ expect(foo.bar.gamma).toBe(60);
+ expect(foo.bar.type).toBe(sample.BarType.BAR_VERTICAL);
+
+ expect(foo.extra_bars.length).toBe(3);
+ for (var i = 0; i < foo.extra_bars.length; ++i) {
+ var base = i * 100;
+ var type = i % 2 ?
+ sample.BarType.BAR_VERTICAL : sample.BarType.BAR_HORIZONTAL;
+ expect(foo.extra_bars[i].alpha).toBe(base);
+ expect(foo.extra_bars[i].beta).toBe(base + 20);
+ expect(foo.extra_bars[i].gamma).toBe(base + 40);
+ expect(foo.extra_bars[i].type).toBe(type);
+ }
+
+ expect(foo.data.length).toBe(10);
+ for (var i = 0; i < foo.data.length; ++i)
+ expect(foo.data[i]).toBe(foo.data.length - i);
+
+ expect(foo.source).toBe(0xFFFF);
+ }
+
+ // Check that values are set to the defaults if we don't override them.
+ function checkDefaultValues() {
+ var bar = new sample.Bar();
+ expect(bar.alpha).toBe(255);
+
+ var foo = new sample.Foo();
+ expect(foo.name).toBe("Fooby");
+ expect(foo.a).toBeTruthy();
+
+ expect(foo.data.length).toBe(3);
+ expect(foo.data[0]).toBe(1);
+ expect(foo.data[1]).toBe(2);
+ expect(foo.data[2]).toBe(3);
+ }
+
+ function ServiceImpl() {
+ }
+
+ ServiceImpl.prototype = Object.create(sample.ServiceStub.prototype);
+
+ ServiceImpl.prototype.frobinate = function(foo, baz, port) {
+ checkFoo(foo);
+ expect(baz).toBe(sample.ServiceStub.BazOptions.BAZ_EXTRA);
+ expect(port).toBe(10);
+ global.result = "PASS";
+ };
+
+ function SimpleMessageReceiver() {
+ }
+
+ SimpleMessageReceiver.prototype.accept = function(message) {
+ if (dumpMessageAsHex)
+ console.log(hexdump.dumpArray(message.memory));
+ // Imagine some IPC happened here.
+ var serviceImpl = new ServiceImpl();
+ serviceImpl.accept(message);
+ };
+
+ var receiver = new SimpleMessageReceiver();
+ var serviceProxy = new sample.ServiceProxy(receiver);
+
+ checkDefaultValues();
+
+ var foo = makeFoo();
+ checkFoo(foo);
+
+ var port = 10;
+ serviceProxy.frobinate(foo, sample.ServiceProxy.BazOptions.BAZ_EXTRA, port);
+});