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

Side by Side Diff: runtime/observatory/tests/service/dev_fs_test.dart

Issue 2759973004: Fix observatory tests broken by running dartfmt. Temporarily reverted formatting for evaluate_activ… (Closed)
Patch Set: Created 3 years, 9 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 (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // VMOptions=--error_on_bad_type --error_on_bad_override 4 // VMOptions=--error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'package:observatory/service_io.dart'; 7 import 'package:observatory/service_io.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'test_helper.dart'; 9 import 'test_helper.dart';
10 10
11 var tests = [ 11 var tests = [
12 (VM vm) async { 12 (VM vm) async {
13 var result = await vm.invokeRpcNoUpgrade('_listDevFS', {}); 13 var result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
14 expect(result['type'], equals('FileSystemList')); 14 expect(result['type'], equals('FileSystemList'));
15 expect(result['fsNames'].toString(), equals("[]")); 15 expect(result['fsNames'].toString(), equals("[]"));
16 16
17 var params = { 17 var params = {'fsName': 'alpha'};
18 'fsName': 'alpha'
19 };
20 result = await vm.invokeRpcNoUpgrade('_createDevFS', params); 18 result = await vm.invokeRpcNoUpgrade('_createDevFS', params);
21 expect(result['type'], equals('FileSystem')); 19 expect(result['type'], equals('FileSystem'));
22 expect(result['name'], equals('alpha')); 20 expect(result['name'], equals('alpha'));
23 expect(result['uri'], new isInstanceOf<String>()); 21 expect(result['uri'], new isInstanceOf<String>());
24 22
25 result = await vm.invokeRpcNoUpgrade('_listDevFS', {}); 23 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
26 expect(result['type'], equals('FileSystemList')); 24 expect(result['type'], equals('FileSystemList'));
27 expect(result['fsNames'].toString(), equals('[alpha]')); 25 expect(result['fsNames'].toString(), equals('[alpha]'));
28 26
29 bool caughtException; 27 bool caughtException;
30 try { 28 try {
31 await vm.invokeRpcNoUpgrade('_createDevFS', params); 29 await vm.invokeRpcNoUpgrade('_createDevFS', params);
32 expect(false, isTrue, reason:'Unreachable'); 30 expect(false, isTrue, reason: 'Unreachable');
33 } on ServerRpcException catch(e) { 31 } on ServerRpcException catch (e) {
34 caughtException = true; 32 caughtException = true;
35 expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists)); 33 expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists));
36 expect(e.message, "_createDevFS: file system 'alpha' already exists"); 34 expect(e.message, "_createDevFS: file system 'alpha' already exists");
37 } 35 }
38 expect(caughtException, isTrue); 36 expect(caughtException, isTrue);
39 37
40 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params); 38 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
41 expect(result['type'], equals('Success')); 39 expect(result['type'], equals('Success'));
42 40
43 result = await vm.invokeRpcNoUpgrade('_listDevFS', {}); 41 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
44 expect(result['type'], equals('FileSystemList')); 42 expect(result['type'], equals('FileSystemList'));
45 expect(result['fsNames'].toString(), equals("[]")); 43 expect(result['fsNames'].toString(), equals("[]"));
46 44
47 caughtException = false; 45 caughtException = false;
48 try { 46 try {
49 await vm.invokeRpcNoUpgrade('_deleteDevFS', params); 47 await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
50 expect(false, isTrue, reason:'Unreachable'); 48 expect(false, isTrue, reason: 'Unreachable');
51 } on ServerRpcException catch(e) { 49 } on ServerRpcException catch (e) {
52 caughtException = true; 50 caughtException = true;
53 expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist)); 51 expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist));
54 expect(e.message, "_deleteDevFS: file system 'alpha' does not exist"); 52 expect(e.message, "_deleteDevFS: file system 'alpha' does not exist");
55 } 53 }
56 expect(caughtException, isTrue); 54 expect(caughtException, isTrue);
57 }, 55 },
58
59 (VM vm) async { 56 (VM vm) async {
60 var fsId = 'banana'; 57 var fsId = 'banana';
61 var filePath = '/foo/bar.dat'; 58 var filePath = '/foo/bar.dat';
62 var fileContents = BASE64.encode(UTF8.encode('fileContents')); 59 var fileContents = BASE64.encode(UTF8.encode('fileContents'));
63 60
64 var result; 61 var result;
65 // Create DevFS. 62 // Create DevFS.
66 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId }); 63 result = await vm.invokeRpcNoUpgrade('_createDevFS', {'fsName': fsId});
67 expect(result['type'], equals('FileSystem')); 64 expect(result['type'], equals('FileSystem'));
68 expect(result['name'], equals(fsId)); 65 expect(result['name'], equals(fsId));
69 expect(result['uri'], new isInstanceOf<String>()); 66 expect(result['uri'], new isInstanceOf<String>());
70 67
71 bool caughtException = false; 68 bool caughtException = false;
72 try { 69 try {
73 await vm.invokeRpcNoUpgrade('_readDevFSFile', { 70 await vm.invokeRpcNoUpgrade('_readDevFSFile', {
74 'fsName': fsId, 71 'fsName': fsId,
75 'path': filePath, 72 'path': filePath,
76 }); 73 });
77 expect(false, isTrue, reason:'Unreachable'); 74 expect(false, isTrue, reason: 'Unreachable');
78 } on ServerRpcException catch(e) { 75 } on ServerRpcException catch (e) {
79 caughtException = true; 76 caughtException = true;
80 expect(e.code, equals(ServerRpcException.kFileDoesNotExist)); 77 expect(e.code, equals(ServerRpcException.kFileDoesNotExist));
81 expect(e.message, startsWith("_readDevFSFile: FileSystemException: ")); 78 expect(e.message, startsWith("_readDevFSFile: FileSystemException: "));
82 } 79 }
83 expect(caughtException, isTrue); 80 expect(caughtException, isTrue);
84 81
85 // Write a file. 82 // Write a file.
86 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', { 83 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile',
87 'fsName': fsId, 84 {'fsName': fsId, 'path': filePath, 'fileContents': fileContents});
88 'path': filePath,
89 'fileContents': fileContents
90 });
91 expect(result['type'], equals('Success')); 85 expect(result['type'], equals('Success'));
92 86
93 // Read the file back. 87 // Read the file back.
94 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 88 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
95 'fsName': fsId, 89 'fsName': fsId,
96 'path': filePath, 90 'path': filePath,
97 }); 91 });
98 expect(result['type'], equals('FSFile')); 92 expect(result['type'], equals('FSFile'));
99 expect(result['fileContents'], equals(fileContents)); 93 expect(result['fileContents'], equals(fileContents));
100 94
101 // The leading '/' is optional. 95 // The leading '/' is optional.
102 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 96 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
103 'fsName': fsId, 97 'fsName': fsId,
104 'path': filePath.substring(1), 98 'path': filePath.substring(1),
105 }); 99 });
106 expect(result['type'], equals('FSFile')); 100 expect(result['type'], equals('FSFile'));
107 expect(result['fileContents'], equals(fileContents)); 101 expect(result['fileContents'], equals(fileContents));
108 102
109 // Read a file outside of the fs. 103 // Read a file outside of the fs.
110 caughtException = false; 104 caughtException = false;
111 try { 105 try {
112 await vm.invokeRpcNoUpgrade('_readDevFSFile', { 106 await vm.invokeRpcNoUpgrade('_readDevFSFile', {
113 'fsName': fsId, 107 'fsName': fsId,
114 'path': '../foo', 108 'path': '../foo',
115 }); 109 });
116 expect(false, isTrue, reason:'Unreachable'); 110 expect(false, isTrue, reason: 'Unreachable');
117 } on ServerRpcException catch(e) { 111 } on ServerRpcException catch (e) {
118 caughtException = true; 112 caughtException = true;
119 expect(e.code, equals(ServerRpcException.kInvalidParams)); 113 expect(e.code, equals(ServerRpcException.kInvalidParams));
120 expect(e.message, "_readDevFSFile: invalid 'path' parameter: ../foo"); 114 expect(e.message, "_readDevFSFile: invalid 'path' parameter: ../foo");
121 } 115 }
122 expect(caughtException, isTrue); 116 expect(caughtException, isTrue);
123 117
124 // Write a set of files. 118 // Write a set of files.
125 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', { 119 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', {
126 'fsName': fsId, 120 'fsName': fsId,
127 'files': [ 121 'files': [
128 ['/a', BASE64.encode(UTF8.encode('a_contents'))], 122 ['/a', BASE64.encode(UTF8.encode('a_contents'))],
129 ['/b', BASE64.encode(UTF8.encode('b_contents'))] 123 ['/b', BASE64.encode(UTF8.encode('b_contents'))]
130 ] 124 ]
131 }); 125 });
132 expect(result['type'], equals('Success')); 126 expect(result['type'], equals('Success'));
133 127
134 // Read one of the files back. 128 // Read one of the files back.
135 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 129 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
136 'fsName': fsId, 130 'fsName': fsId,
137 'path': '/b', 131 'path': '/b',
138 }); 132 });
139 expect(result['type'], equals('FSFile')); 133 expect(result['type'], equals('FSFile'));
140 expect(result['fileContents'], 134 expect(result['fileContents'],
141 equals(BASE64.encode(UTF8.encode('b_contents')))); 135 equals(BASE64.encode(UTF8.encode('b_contents'))));
142 136
143 // List all the files in the file system. 137 // List all the files in the file system.
144 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { 138 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', {
145 'fsName': fsId, 139 'fsName': fsId,
146 }); 140 });
147 expect(result['type'], equals('FSFileList')); 141 expect(result['type'], equals('FSFileList'));
148 expect(result['files'].length, equals(3)); 142 expect(result['files'].length, equals(3));
149 143
150 // Delete DevFS. 144 // Delete DevFS.
151 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { 145 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
152 'fsName': fsId, 146 'fsName': fsId,
153 }); 147 });
154 expect(result['type'], equals('Success')); 148 expect(result['type'], equals('Success'));
155 }, 149 },
156 ]; 150 ];
157 151
158 main(args) async => runVMTests(args, tests); 152 main(args) async => runVMTests(args, tests);
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/dev_fs_spawn_test.dart ('k') | runtime/observatory/tests/service/dev_fs_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698