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

Side by Side Diff: mojo/dart/test/control_messages_test.dart

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 4 years, 12 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
« no previous file with comments | « mojo/dart/test/compile_all_interfaces_test.dart ('k') | mojo/dart/test/core_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:isolate';
7 import 'dart:typed_data';
8
9 import 'package:mojo/bindings.dart' as bindings;
10 import 'package:mojo/core.dart' as core;
11 import 'package:_mojo_for_test_only/expect.dart';
12 import 'package:_mojo_for_test_only/sample/sample_interfaces.mojom.dart' as samp le;
13
14 // Bump this if sample_interfaces.mojom adds higher versions.
15 const int maxVersion = 3;
16
17 // Implementation of IntegerAccessor.
18 class IntegerAccessorImpl implements sample.IntegerAccessor {
19 // Some initial value.
20 int _value = 0;
21
22 dynamic getInteger([Function responseFactory = null]) =>
23 responseFactory(_value, sample.Enum.value);
24
25 void setInteger(int data, sample.Enum type) {
26 Expect.equals(sample.Enum.value, type);
27 // Update data.
28 _value = data;
29 }
30 }
31
32 // Returns [proxy, stub].
33 List buildConnectedProxyAndStub() {
34 var pipe = new core.MojoMessagePipe();
35 var proxy = new sample.IntegerAccessorProxy.fromEndpoint(pipe.endpoints[0]);
36 var impl = new IntegerAccessorImpl();
37 var stub =
38 new sample.IntegerAccessorStub.fromEndpoint(pipe.endpoints[1], impl);
39 return [proxy, stub];
40 }
41
42 void closeProxyAndStub(List ps) {
43 var proxy = ps[0];
44 var stub = ps[1];
45 proxy.close();
46 stub.close();
47 }
48
49 testQueryVersion() async {
50 var ps = buildConnectedProxyAndStub();
51 var proxy = ps[0];
52 // The version starts at 0.
53 Expect.equals(0, proxy.version);
54 // We are talking to an implementation that supports version maxVersion.
55 var providedVersion = await proxy.queryVersion();
56 Expect.equals(maxVersion, providedVersion);
57 // The proxy's version has been updated.
58 Expect.equals(providedVersion, proxy.version);
59 closeProxyAndStub(ps);
60 }
61
62 testRequireVersionSuccess() async {
63 var ps = buildConnectedProxyAndStub();
64 var proxy = ps[0];
65 Expect.equals(0, proxy.version);
66 // Require version maxVersion.
67 proxy.requireVersion(maxVersion);
68 // Make a request and get a response.
69 var response = await proxy.ptr.getInteger();
70 Expect.equals(0, response.data);
71 closeProxyAndStub(ps);
72 }
73
74 testRequireVersionDisconnect() async {
75 var ps = buildConnectedProxyAndStub();
76 var proxy = ps[0];
77 Expect.equals(0, proxy.version);
78 // Require version maxVersion.
79 proxy.requireVersion(maxVersion);
80 Expect.equals(maxVersion, proxy.version);
81 // Set integer.
82 proxy.ptr.setInteger(34, sample.Enum.value);
83 // Get integer.
84 var response = await proxy.ptr.getInteger();
85 Expect.equals(34, response.data);
86 // Require version maxVersion + 1
87 proxy.requireVersion(maxVersion + 1);
88 // Version number is updated synchronously.
89 Expect.equals(maxVersion + 1, proxy.version);
90 // Get integer, expect a failure.
91 bool exceptionCaught = false;
92 try {
93 response = await proxy.ptr.getInteger();
94 Expect.fail('Should have an exception.');
95 } catch(e) {
96 exceptionCaught = true;
97 }
98 Expect.isTrue(exceptionCaught);
99 closeProxyAndStub(ps);
100 }
101
102 main() async {
103 await testQueryVersion();
104 await testRequireVersionSuccess();
105 await testRequireVersionDisconnect();
106 }
OLDNEW
« no previous file with comments | « mojo/dart/test/compile_all_interfaces_test.dart ('k') | mojo/dart/test/core_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698