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

Side by Side Diff: mojo/dart/apptests/dart_apptests/lib/src/versioning_apptests.dart

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments Created 4 years, 7 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
OLDNEW
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 library versioning_apptests; 5 library versioning_apptests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:mojo_apptest/apptest.dart'; 9 import 'package:mojo_apptest/apptest.dart';
10 import 'package:mojo/application.dart'; 10 import 'package:mojo/application.dart';
11 import 'package:mojo/bindings.dart'; 11 import 'package:mojo/bindings.dart';
12 import 'package:mojo/core.dart'; 12 import 'package:mojo/core.dart';
13 import 'package:_mojo_for_test_only/mojo/test/versioning/versioning_test_client. mojom.dart'; 13 import 'package:_mojo_for_test_only/mojo/test/versioning/versioning_test_client. mojom.dart';
14 14
15 tests(Application application, String url) { 15 tests(Application application, String url) {
16 group('Versioning Apptests', () { 16 group('Versioning Apptests', () {
17 test('Struct', () async { 17 test('Struct', () async {
18 // The service side uses a newer version of Employee definition that 18 // The service side uses a newer version of Employee definition that
19 // includes the 'birthday' field. 19 // includes the 'birthday' field.
20 20
21 // Connect to human resource database. 21 // Connect to human resource database.
22 var databaseProxy = new HumanResourceDatabaseProxy.unbound(); 22 var databaseProxy = new HumanResourceDatabaseProxy.unbound();
23 application.connectToService( 23 application.connectToService(
24 "mojo:versioning_test_service", databaseProxy); 24 "mojo:versioning_test_service", databaseProxy);
25 25
26 // Query database and get a response back (even though the client does not 26 // Query database and get a response back (even though the client does not
27 // know about the birthday field). 27 // know about the birthday field).
28 bool retrieveFingerPrint = true; 28 bool retrieveFingerPrint = true;
29 var response = 29 var response =
30 await databaseProxy.ptr.queryEmployee(1, retrieveFingerPrint); 30 await databaseProxy.queryEmployee(1, retrieveFingerPrint);
31 expect(response.employee.employeeId, equals(1)); 31 expect(response.employee.employeeId, equals(1));
32 expect(response.employee.name, equals("Homer Simpson")); 32 expect(response.employee.name, equals("Homer Simpson"));
33 expect(response.employee.department, equals(Department.dev)); 33 expect(response.employee.department, equals(Department.dev));
34 expect(response.fingerPrint, isNotNull); 34 expect(response.fingerPrint, isNotNull);
35 35
36 // Pass an Employee struct to the service side that lacks the 'birthday' 36 // Pass an Employee struct to the service side that lacks the 'birthday'
37 // field. 37 // field.
38 var newEmployee = new Employee(); 38 var newEmployee = new Employee();
39 newEmployee.employeeId = 2; 39 newEmployee.employeeId = 2;
40 newEmployee.name = "Marge Simpson"; 40 newEmployee.name = "Marge Simpson";
41 newEmployee.department = Department.sales; 41 newEmployee.department = Department.sales;
42 response = await databaseProxy.ptr.addEmployee(newEmployee); 42 response = await databaseProxy.addEmployee(newEmployee);
43 expect(response.success, isTrue); 43 expect(response.success, isTrue);
44 44
45 // Query for employee #2. 45 // Query for employee #2.
46 retrieveFingerPrint = false; 46 retrieveFingerPrint = false;
47 response = await databaseProxy.ptr.queryEmployee(2, retrieveFingerPrint); 47 response = await databaseProxy.queryEmployee(2, retrieveFingerPrint);
48 expect(response.employee.employeeId, equals(2)); 48 expect(response.employee.employeeId, equals(2));
49 expect(response.employee.name, equals("Marge Simpson")); 49 expect(response.employee.name, equals("Marge Simpson"));
50 expect(response.employee.department, equals(Department.sales)); 50 expect(response.employee.department, equals(Department.sales));
51 expect(response.fingerPrint, isNull); 51 expect(response.fingerPrint, isNull);
52 52
53 // Disconnect from database. 53 // Disconnect from database.
54 databaseProxy.close(); 54 databaseProxy.close();
55 }); 55 });
56 56
57 test('QueryVersion', () async { 57 test('QueryVersion', () async {
58 // Connect to human resource database. 58 // Connect to human resource database.
59 var databaseProxy = new HumanResourceDatabaseProxy.unbound(); 59 var databaseProxy = new HumanResourceDatabaseProxy.unbound();
60 application.connectToService( 60 application.connectToService(
61 "mojo:versioning_test_service", databaseProxy); 61 "mojo:versioning_test_service", databaseProxy);
62 // Query the version. 62 // Query the version.
63 var version = await databaseProxy.queryVersion(); 63 var version = await databaseProxy.ctrl.queryVersion();
64 // Expect it to be 1. 64 // Expect it to be 1.
65 expect(version, equals(1)); 65 expect(version, equals(1));
66 // Disconnect from database. 66 // Disconnect from database.
67 databaseProxy.close(); 67 databaseProxy.close();
68 }); 68 });
69 69
70 test('RequireVersion', () async { 70 test('RequireVersion', () async {
71 // Connect to human resource database. 71 // Connect to human resource database.
72 var databaseProxy = new HumanResourceDatabaseProxy.unbound(); 72 var databaseProxy = new HumanResourceDatabaseProxy.unbound();
73 application.connectToService( 73 application.connectToService(
74 "mojo:versioning_test_service", databaseProxy); 74 "mojo:versioning_test_service", databaseProxy);
75 75
76 // Require version 1. 76 // Require version 1.
77 databaseProxy.requireVersion(1); 77 databaseProxy.ctrl.requireVersion(1);
78 expect(databaseProxy.version, equals(1)); 78 expect(databaseProxy.ctrl.version, equals(1));
79 79
80 // Query for employee #3. 80 // Query for employee #3.
81 var retrieveFingerPrint = false; 81 var retrieveFingerPrint = false;
82 var response = 82 var response =
83 await databaseProxy.ptr.queryEmployee(3, retrieveFingerPrint); 83 await databaseProxy.queryEmployee(3, retrieveFingerPrint);
84 84
85 // Got some kind of response. 85 // Got some kind of response.
86 expect(response, isNotNull); 86 expect(response, isNotNull);
87 87
88 // Require version 3 (which cannot be satisfied). 88 // Require version 3 (which cannot be satisfied).
89 databaseProxy.requireVersion(3); 89 databaseProxy.ctrl.requireVersion(3);
90 expect(databaseProxy.version, equals(3)); 90 expect(databaseProxy.ctrl.version, equals(3));
91 91
92 // Query for employee #1, observe that the call fails. 92 // Query for employee #1, observe that the call fails.
93 bool exceptionCaught = false; 93 bool exceptionCaught = false;
94 try { 94 try {
95 response = await databaseProxy.responseOrError( 95 response = await databaseProxy.responseOrError(
96 databaseProxy.ptr.queryEmployee(1, retrieveFingerPrint)); 96 databaseProxy.queryEmployee(1, retrieveFingerPrint));
97 fail('Exception should be thrown.'); 97 fail('Exception should be thrown.');
98 } catch (e) { 98 } catch (e) {
99 exceptionCaught = true; 99 exceptionCaught = true;
100 } 100 }
101 expect(exceptionCaught, isTrue); 101 expect(exceptionCaught, isTrue);
102 102
103 // No need to disconnect from database because we were disconnected by 103 // No need to disconnect from database because we were disconnected by
104 // the requireVersion control message. 104 // the requireVersion control message.
105 }); 105 });
106 106
107 test('CallNonexistentMethod', () async { 107 test('CallNonexistentMethod', () async {
108 // Connect to human resource database. 108 // Connect to human resource database.
109 var databaseProxy = new HumanResourceDatabaseProxy.unbound(); 109 var databaseProxy = new HumanResourceDatabaseProxy.unbound();
110 application.connectToService( 110 application.connectToService(
111 "mojo:versioning_test_service", databaseProxy); 111 "mojo:versioning_test_service", databaseProxy);
112 const fingerPrintLength = 128; 112 const fingerPrintLength = 128;
113 var fingerPrint = new List(fingerPrintLength); 113 var fingerPrint = new List(fingerPrintLength);
114 for (var i = 0; i < fingerPrintLength; i++) { 114 for (var i = 0; i < fingerPrintLength; i++) {
115 fingerPrint[i] = i + 13; 115 fingerPrint[i] = i + 13;
116 } 116 }
117 // Although the client side doesn't know whether the service side supports 117 // Although the client side doesn't know whether the service side supports
118 // version 1, calling a version 1 method succeeds as long as the service 118 // version 1, calling a version 1 method succeeds as long as the service
119 // side supports version 1. 119 // side supports version 1.
120 var response = await databaseProxy.ptr.attachFingerPrint(1, fingerPrint); 120 var response = await databaseProxy.attachFingerPrint(1, fingerPrint);
121 expect(response.success, isTrue); 121 expect(response.success, isTrue);
122 122
123 // Calling a version 2 method (which the service side doesn't support) 123 // Calling a version 2 method (which the service side doesn't support)
124 // closes the pipe. 124 // closes the pipe.
125 bool exceptionCaught = false; 125 bool exceptionCaught = false;
126 try { 126 try {
127 response = await databaseProxy 127 response = await databaseProxy
128 .responseOrError(databaseProxy.ptr.listEmployeeIds()); 128 .responseOrError(databaseProxy.listEmployeeIds());
129 fail('Exception should be thrown.'); 129 fail('Exception should be thrown.');
130 } catch (e) { 130 } catch (e) {
131 exceptionCaught = true; 131 exceptionCaught = true;
132 } 132 }
133 expect(exceptionCaught, isTrue); 133 expect(exceptionCaught, isTrue);
134 134
135 // No need to disconnect from database because we were disconnected by 135 // No need to disconnect from database because we were disconnected by
136 // the call to a version 2 method. 136 // the call to a version 2 method.
137 }); 137 });
138 }); 138 });
139 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698