| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:mojo/bindings.dart' as bindings; | 9 import 'package:mojo/bindings.dart' as bindings; |
| 10 import 'package:mojo/core.dart' as core; | 10 import 'package:mojo/core.dart' as core; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 var proxy = ps[0]; | 43 var proxy = ps[0]; |
| 44 var stub = ps[1]; | 44 var stub = ps[1]; |
| 45 proxy.close(); | 45 proxy.close(); |
| 46 stub.close(); | 46 stub.close(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 testQueryVersion() async { | 49 testQueryVersion() async { |
| 50 var ps = buildConnectedProxyAndStub(); | 50 var ps = buildConnectedProxyAndStub(); |
| 51 var proxy = ps[0]; | 51 var proxy = ps[0]; |
| 52 // The version starts at 0. | 52 // The version starts at 0. |
| 53 Expect.equals(0, proxy.version); | 53 Expect.equals(0, proxy.ctrl.version); |
| 54 // We are talking to an implementation that supports version maxVersion. | 54 // We are talking to an implementation that supports version maxVersion. |
| 55 var providedVersion = await proxy.queryVersion(); | 55 var providedVersion = await proxy.ctrl.queryVersion(); |
| 56 Expect.equals(maxVersion, providedVersion); | 56 Expect.equals(maxVersion, providedVersion); |
| 57 // The proxy's version has been updated. | 57 // The proxy's version has been updated. |
| 58 Expect.equals(providedVersion, proxy.version); | 58 Expect.equals(providedVersion, proxy.ctrl.version); |
| 59 closeProxyAndStub(ps); | 59 closeProxyAndStub(ps); |
| 60 } | 60 } |
| 61 | 61 |
| 62 testRequireVersionSuccess() async { | 62 testRequireVersionSuccess() async { |
| 63 var ps = buildConnectedProxyAndStub(); | 63 var ps = buildConnectedProxyAndStub(); |
| 64 var proxy = ps[0]; | 64 var proxy = ps[0]; |
| 65 Expect.equals(0, proxy.version); | 65 Expect.equals(0, proxy.ctrl.version); |
| 66 // Require version maxVersion. | 66 // Require version maxVersion. |
| 67 proxy.requireVersion(maxVersion); | 67 proxy.ctrl.requireVersion(maxVersion); |
| 68 // Make a request and get a response. | 68 // Make a request and get a response. |
| 69 var response = await proxy.ptr.getInteger(); | 69 var response = await proxy.getInteger(); |
| 70 Expect.equals(0, response.data); | 70 Expect.equals(0, response.data); |
| 71 closeProxyAndStub(ps); | 71 closeProxyAndStub(ps); |
| 72 } | 72 } |
| 73 | 73 |
| 74 testRequireVersionDisconnect() async { | 74 testRequireVersionDisconnect() async { |
| 75 var ps = buildConnectedProxyAndStub(); | 75 var ps = buildConnectedProxyAndStub(); |
| 76 var proxy = ps[0]; | 76 var proxy = ps[0]; |
| 77 Expect.equals(0, proxy.version); | 77 Expect.equals(0, proxy.ctrl.version); |
| 78 // Require version maxVersion. | 78 // Require version maxVersion. |
| 79 proxy.requireVersion(maxVersion); | 79 proxy.ctrl.requireVersion(maxVersion); |
| 80 Expect.equals(maxVersion, proxy.version); | 80 Expect.equals(maxVersion, proxy.ctrl.version); |
| 81 // Set integer. | 81 // Set integer. |
| 82 proxy.ptr.setInteger(34, sample.Enum.value); | 82 proxy.setInteger(34, sample.Enum.value); |
| 83 // Get integer. | 83 // Get integer. |
| 84 var response = await proxy.ptr.getInteger(); | 84 var response = await proxy.getInteger(); |
| 85 Expect.equals(34, response.data); | 85 Expect.equals(34, response.data); |
| 86 // Require version maxVersion + 1 | 86 // Require version maxVersion + 1 |
| 87 proxy.requireVersion(maxVersion + 1); | 87 proxy.ctrl.requireVersion(maxVersion + 1); |
| 88 // Version number is updated synchronously. | 88 // Version number is updated synchronously. |
| 89 Expect.equals(maxVersion + 1, proxy.version); | 89 Expect.equals(maxVersion + 1, proxy.ctrl.version); |
| 90 // Get integer, expect a failure. | 90 // Get integer, expect a failure. |
| 91 bool exceptionCaught = false; | 91 bool exceptionCaught = false; |
| 92 try { | 92 try { |
| 93 response = await proxy.ptr.getInteger(); | 93 response = await proxy.getInteger(); |
| 94 Expect.fail('Should have an exception.'); | 94 Expect.fail('Should have an exception.'); |
| 95 } catch(e) { | 95 } catch(e) { |
| 96 exceptionCaught = true; | 96 exceptionCaught = true; |
| 97 } | 97 } |
| 98 Expect.isTrue(exceptionCaught); | 98 Expect.isTrue(exceptionCaught); |
| 99 closeProxyAndStub(ps); | 99 closeProxyAndStub(ps); |
| 100 } | 100 } |
| 101 | 101 |
| 102 main() async { | 102 main() async { |
| 103 await testQueryVersion(); | 103 await testQueryVersion(); |
| 104 await testRequireVersionSuccess(); | 104 await testRequireVersionSuccess(); |
| 105 await testRequireVersionDisconnect(); | 105 await testRequireVersionDisconnect(); |
| 106 } | 106 } |
| OLD | NEW |