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

Side by Side Diff: services/dart/dart_apptests/lib/src/versioning_apptests.dart

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

Powered by Google App Engine
This is Rietveld 408576698