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

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

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (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 = {'fsName': 'alpha'}; 17 var params = {
18 'fsName': 'alpha'
19 };
18 result = await vm.invokeRpcNoUpgrade('_createDevFS', params); 20 result = await vm.invokeRpcNoUpgrade('_createDevFS', params);
19 expect(result['type'], equals('FileSystem')); 21 expect(result['type'], equals('FileSystem'));
20 expect(result['name'], equals('alpha')); 22 expect(result['name'], equals('alpha'));
21 expect(result['uri'], new isInstanceOf<String>()); 23 expect(result['uri'], new isInstanceOf<String>());
22 24
23 result = await vm.invokeRpcNoUpgrade('_listDevFS', {}); 25 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
24 expect(result['type'], equals('FileSystemList')); 26 expect(result['type'], equals('FileSystemList'));
25 expect(result['fsNames'].toString(), equals('[alpha]')); 27 expect(result['fsNames'].toString(), equals('[alpha]'));
26 28
27 bool caughtException; 29 bool caughtException;
28 try { 30 try {
29 await vm.invokeRpcNoUpgrade('_createDevFS', params); 31 await vm.invokeRpcNoUpgrade('_createDevFS', params);
30 expect(false, isTrue, reason: 'Unreachable'); 32 expect(false, isTrue, reason:'Unreachable');
31 } on ServerRpcException catch (e) { 33 } on ServerRpcException catch(e) {
32 caughtException = true; 34 caughtException = true;
33 expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists)); 35 expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists));
34 expect(e.message, "_createDevFS: file system 'alpha' already exists"); 36 expect(e.message, "_createDevFS: file system 'alpha' already exists");
35 } 37 }
36 expect(caughtException, isTrue); 38 expect(caughtException, isTrue);
37 39
38 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params); 40 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
39 expect(result['type'], equals('Success')); 41 expect(result['type'], equals('Success'));
40 42
41 result = await vm.invokeRpcNoUpgrade('_listDevFS', {}); 43 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
42 expect(result['type'], equals('FileSystemList')); 44 expect(result['type'], equals('FileSystemList'));
43 expect(result['fsNames'].toString(), equals("[]")); 45 expect(result['fsNames'].toString(), equals("[]"));
44 46
45 caughtException = false; 47 caughtException = false;
46 try { 48 try {
47 await vm.invokeRpcNoUpgrade('_deleteDevFS', params); 49 await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
48 expect(false, isTrue, reason: 'Unreachable'); 50 expect(false, isTrue, reason:'Unreachable');
49 } on ServerRpcException catch (e) { 51 } on ServerRpcException catch(e) {
50 caughtException = true; 52 caughtException = true;
51 expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist)); 53 expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist));
52 expect(e.message, "_deleteDevFS: file system 'alpha' does not exist"); 54 expect(e.message, "_deleteDevFS: file system 'alpha' does not exist");
53 } 55 }
54 expect(caughtException, isTrue); 56 expect(caughtException, isTrue);
55 }, 57 },
58
56 (VM vm) async { 59 (VM vm) async {
57 var fsId = 'banana'; 60 var fsId = 'banana';
58 var filePath = '/foo/bar.dat'; 61 var filePath = '/foo/bar.dat';
59 var fileContents = BASE64.encode(UTF8.encode('fileContents')); 62 var fileContents = BASE64.encode(UTF8.encode('fileContents'));
60 63
61 var result; 64 var result;
62 // Create DevFS. 65 // Create DevFS.
63 result = await vm.invokeRpcNoUpgrade('_createDevFS', {'fsName': fsId}); 66 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId });
64 expect(result['type'], equals('FileSystem')); 67 expect(result['type'], equals('FileSystem'));
65 expect(result['name'], equals(fsId)); 68 expect(result['name'], equals(fsId));
66 expect(result['uri'], new isInstanceOf<String>()); 69 expect(result['uri'], new isInstanceOf<String>());
67 70
68 bool caughtException = false; 71 bool caughtException = false;
69 try { 72 try {
70 await vm.invokeRpcNoUpgrade('_readDevFSFile', { 73 await vm.invokeRpcNoUpgrade('_readDevFSFile', {
71 'fsName': fsId, 74 'fsName': fsId,
72 'path': filePath, 75 'path': filePath,
73 }); 76 });
74 expect(false, isTrue, reason: 'Unreachable'); 77 expect(false, isTrue, reason:'Unreachable');
75 } on ServerRpcException catch (e) { 78 } on ServerRpcException catch(e) {
76 caughtException = true; 79 caughtException = true;
77 expect(e.code, equals(ServerRpcException.kFileDoesNotExist)); 80 expect(e.code, equals(ServerRpcException.kFileDoesNotExist));
78 expect(e.message, startsWith("_readDevFSFile: FileSystemException: ")); 81 expect(e.message, startsWith("_readDevFSFile: FileSystemException: "));
79 } 82 }
80 expect(caughtException, isTrue); 83 expect(caughtException, isTrue);
81 84
82 // Write a file. 85 // Write a file.
83 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', 86 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', {
84 {'fsName': fsId, 'path': filePath, 'fileContents': fileContents}); 87 'fsName': fsId,
88 'path': filePath,
89 'fileContents': fileContents
90 });
85 expect(result['type'], equals('Success')); 91 expect(result['type'], equals('Success'));
86 92
87 // Read the file back. 93 // Read the file back.
88 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 94 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
89 'fsName': fsId, 95 'fsName': fsId,
90 'path': filePath, 96 'path': filePath,
91 }); 97 });
92 expect(result['type'], equals('FSFile')); 98 expect(result['type'], equals('FSFile'));
93 expect(result['fileContents'], equals(fileContents)); 99 expect(result['fileContents'], equals(fileContents));
94 100
95 // The leading '/' is optional. 101 // The leading '/' is optional.
96 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 102 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
97 'fsName': fsId, 103 'fsName': fsId,
98 'path': filePath.substring(1), 104 'path': filePath.substring(1),
99 }); 105 });
100 expect(result['type'], equals('FSFile')); 106 expect(result['type'], equals('FSFile'));
101 expect(result['fileContents'], equals(fileContents)); 107 expect(result['fileContents'], equals(fileContents));
102 108
103 // Read a file outside of the fs. 109 // Read a file outside of the fs.
104 caughtException = false; 110 caughtException = false;
105 try { 111 try {
106 await vm.invokeRpcNoUpgrade('_readDevFSFile', { 112 await vm.invokeRpcNoUpgrade('_readDevFSFile', {
107 'fsName': fsId, 113 'fsName': fsId,
108 'path': '../foo', 114 'path': '../foo',
109 }); 115 });
110 expect(false, isTrue, reason: 'Unreachable'); 116 expect(false, isTrue, reason:'Unreachable');
111 } on ServerRpcException catch (e) { 117 } on ServerRpcException catch(e) {
112 caughtException = true; 118 caughtException = true;
113 expect(e.code, equals(ServerRpcException.kInvalidParams)); 119 expect(e.code, equals(ServerRpcException.kInvalidParams));
114 expect(e.message, "_readDevFSFile: invalid 'path' parameter: ../foo"); 120 expect(e.message, "_readDevFSFile: invalid 'path' parameter: ../foo");
115 } 121 }
116 expect(caughtException, isTrue); 122 expect(caughtException, isTrue);
117 123
118 // Write a set of files. 124 // Write a set of files.
119 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', { 125 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', {
120 'fsName': fsId, 126 'fsName': fsId,
121 'files': [ 127 'files': [
122 ['/a', BASE64.encode(UTF8.encode('a_contents'))], 128 ['/a', BASE64.encode(UTF8.encode('a_contents'))],
123 ['/b', BASE64.encode(UTF8.encode('b_contents'))] 129 ['/b', BASE64.encode(UTF8.encode('b_contents'))]
124 ] 130 ]
125 }); 131 });
126 expect(result['type'], equals('Success')); 132 expect(result['type'], equals('Success'));
127 133
128 // Read one of the files back. 134 // Read one of the files back.
129 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { 135 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
130 'fsName': fsId, 136 'fsName': fsId,
131 'path': '/b', 137 'path': '/b',
132 }); 138 });
133 expect(result['type'], equals('FSFile')); 139 expect(result['type'], equals('FSFile'));
134 expect(result['fileContents'], 140 expect(result['fileContents'],
135 equals(BASE64.encode(UTF8.encode('b_contents')))); 141 equals(BASE64.encode(UTF8.encode('b_contents'))));
136 142
137 // List all the files in the file system. 143 // List all the files in the file system.
138 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { 144 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', {
139 'fsName': fsId, 145 'fsName': fsId,
140 }); 146 });
141 expect(result['type'], equals('FSFileList')); 147 expect(result['type'], equals('FSFileList'));
142 expect(result['files'].length, equals(3)); 148 expect(result['files'].length, equals(3));
143 149
144 // Delete DevFS. 150 // Delete DevFS.
145 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { 151 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
146 'fsName': fsId, 152 'fsName': fsId,
147 }); 153 });
148 expect(result['type'], equals('Success')); 154 expect(result['type'], equals('Success'));
149 }, 155 },
150 ]; 156 ];
151 157
152 main(args) async => runVMTests(args, tests); 158 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