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

Side by Side Diff: mojo/public/bindings/sample/sample_service_unittests.js

Issue 138143003: Support default values for POD struct fields in mojom IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 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 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([ 5 define([
6 "console", 6 "console",
7 "mojo/apps/js/test/hexdump", 7 "mojo/apps/js/test/hexdump",
8 "gin/test/expect", 8 "gin/test/expect",
9 "mojom/sample_service" 9 "mojom/sample_service"
10 ], function(console, hexdump, expect, sample) { 10 ], function(console, hexdump, expect, sample) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 expect(foo.extra_bars[i].type).toBe(type); 78 expect(foo.extra_bars[i].type).toBe(type);
79 } 79 }
80 80
81 expect(foo.data.length).toBe(10); 81 expect(foo.data.length).toBe(10);
82 for (var i = 0; i < foo.data.length; ++i) 82 for (var i = 0; i < foo.data.length; ++i)
83 expect(foo.data[i]).toBe(foo.data.length - i); 83 expect(foo.data[i]).toBe(foo.data.length - i);
84 84
85 expect(foo.source).toBe(0xFFFF); 85 expect(foo.source).toBe(0xFFFF);
86 } 86 }
87 87
88 // Check that values are set to the defaults if we don't override them.
89 function checkDefaultValues() {
90 var bar = new sample.Bar();
91 expect(bar.alpha).toBe(255);
92
93 var foo = new sample.Foo();
94 expect(foo.name).toBe("Fooby");
95 expect(foo.a).toBeTruthy();
96 }
97
88 function ServiceImpl() { 98 function ServiceImpl() {
89 } 99 }
90 100
91 ServiceImpl.prototype = Object.create(sample.ServiceStub.prototype); 101 ServiceImpl.prototype = Object.create(sample.ServiceStub.prototype);
92 102
93 ServiceImpl.prototype.frobinate = function(foo, baz, port) { 103 ServiceImpl.prototype.frobinate = function(foo, baz, port) {
94 checkFoo(foo); 104 checkFoo(foo);
95 expect(baz).toBe(sample.ServiceStub.BazOptions.BAZ_EXTRA); 105 expect(baz).toBe(sample.ServiceStub.BazOptions.BAZ_EXTRA);
96 expect(port).toBe(10); 106 expect(port).toBe(10);
97 global.result = "PASS"; 107 global.result = "PASS";
98 }; 108 };
99 109
100 function SimpleMessageReceiver() { 110 function SimpleMessageReceiver() {
101 } 111 }
102 112
103 SimpleMessageReceiver.prototype.accept = function(message) { 113 SimpleMessageReceiver.prototype.accept = function(message) {
104 if (dumpMessageAsHex) 114 if (dumpMessageAsHex)
105 console.log(hexdump.dumpArray(message.memory)); 115 console.log(hexdump.dumpArray(message.memory));
106 // Imagine some IPC happened here. 116 // Imagine some IPC happened here.
107 var serviceImpl = new ServiceImpl(); 117 var serviceImpl = new ServiceImpl();
108 serviceImpl.accept(message); 118 serviceImpl.accept(message);
109 }; 119 };
110 120
111 var receiver = new SimpleMessageReceiver(); 121 var receiver = new SimpleMessageReceiver();
112 var serviceProxy = new sample.ServiceProxy(receiver); 122 var serviceProxy = new sample.ServiceProxy(receiver);
113 123
124 checkDefaultValues();
125
114 var foo = makeFoo(); 126 var foo = makeFoo();
115 checkFoo(foo); 127 checkFoo(foo);
116 128
117 var port = 10; 129 var port = 10;
118 serviceProxy.frobinate(foo, sample.ServiceProxy.BazOptions.BAZ_EXTRA, port); 130 serviceProxy.frobinate(foo, sample.ServiceProxy.BazOptions.BAZ_EXTRA, port);
119 }); 131 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698