OLD | NEW |
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('FSList')); | 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 = { |
18 'fsName': 'alpha' | 18 'fsName': 'alpha' |
19 }; | 19 }; |
20 result = await vm.invokeRpcNoUpgrade('_createDevFS', params); | 20 result = await vm.invokeRpcNoUpgrade('_createDevFS', params); |
21 expect(result['type'], equals('Success')); | 21 expect(result['type'], equals('FileSystem')); |
| 22 expect(result['name'], equals('alpha')); |
| 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('FSList')); | 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('FSList')); | 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 }, |
56 | 58 |
57 (VM vm) async { | 59 (VM vm) async { |
58 var fsId = 'banana'; | 60 var fsId = 'banana'; |
59 var filePath = '/foobar.dat'; | 61 var filePath = '/foobar.dat'; |
60 var fileContents = BASE64.encode(UTF8.encode('fileContents')); | 62 var fileContents = BASE64.encode(UTF8.encode('fileContents')); |
61 | 63 |
62 var result; | 64 var result; |
63 // Create DevFS. | 65 // Create DevFS. |
64 result = await vm.invokeRpcNoUpgrade('_createDevFS', { | 66 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId }); |
65 'fsName': fsId | 67 expect(result['type'], equals('FileSystem')); |
66 }); | 68 expect(result['name'], equals(fsId)); |
67 expect(result['type'], equals('Success')); | 69 expect(result['uri'], new isInstanceOf<String>()); |
68 | 70 |
69 bool caughtException = false; | 71 bool caughtException = false; |
70 try { | 72 try { |
71 await vm.invokeRpcNoUpgrade('_readDevFSFile', { | 73 await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
72 'fsName': fsId, | 74 'fsName': fsId, |
73 'path': filePath, | 75 'path': filePath, |
74 }); | 76 }); |
75 expect(false, isTrue, reason:'Unreachable'); | 77 expect(false, isTrue, reason:'Unreachable'); |
76 } on ServerRpcException catch(e) { | 78 } on ServerRpcException catch(e) { |
77 caughtException = true; | 79 caughtException = true; |
78 expect(e.code, equals(ServerRpcException.kFileDoesNotExist)); | 80 expect(e.code, equals(ServerRpcException.kFileDoesNotExist)); |
79 expect(e.message, | 81 expect(e.message, startsWith("_readDevFSFile: FileSystemException: ")); |
80 "_readDevFSFile: file 'dart-devfs://banana//foobar.dat' " | |
81 "does not exist"); | |
82 } | 82 } |
83 expect(caughtException, isTrue); | 83 expect(caughtException, isTrue); |
84 | 84 |
85 // Write a file. | 85 // Write a file. |
86 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', { | 86 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', { |
87 'fsName': fsId, | 87 'fsName': fsId, |
88 'path': filePath, | 88 'path': filePath, |
89 'fileContents': fileContents | 89 'fileContents': fileContents |
90 }); | 90 }); |
91 expect(result['type'], equals('Success')); | 91 expect(result['type'], equals('Success')); |
92 | 92 |
93 // Read the file back. | 93 // Read the file back. |
94 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { | 94 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
95 'fsName': fsId, | 95 'fsName': fsId, |
96 'path': filePath, | 96 'path': filePath, |
97 }); | 97 }); |
98 expect(result['type'], equals('FSFile')); | 98 expect(result['type'], equals('FSFile')); |
99 expect(result['fileContents'], equals(fileContents)); | 99 expect(result['fileContents'], equals(fileContents)); |
100 | 100 |
101 // Read a malformed path back. | 101 // The leading '/' is optional. |
| 102 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
| 103 'fsName': fsId, |
| 104 'path': filePath.substring(1), |
| 105 }); |
| 106 expect(result['type'], equals('FSFile')); |
| 107 expect(result['fileContents'], equals(fileContents)); |
| 108 |
| 109 // Read a file outside of the fs. |
102 caughtException = false; | 110 caughtException = false; |
103 try { | 111 try { |
104 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { | 112 await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
105 'fsName': fsId, | 113 'fsName': fsId, |
106 'path': filePath.substring(1) // Strip the leading '/'. | 114 'path': '../foo', |
107 }); | 115 }); |
| 116 expect(false, isTrue, reason:'Unreachable'); |
108 } on ServerRpcException catch(e) { | 117 } on ServerRpcException catch(e) { |
109 caughtException = true; | 118 caughtException = true; |
110 expect(e.code, equals(ServerRpcException.kInvalidParams)); | 119 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
111 expect(e.message, | 120 expect(e.message, "_readDevFSFile: invalid 'path' parameter: ../foo"); |
112 "_readDevFSFile: file system path \'foobar.dat\' " | |
113 "must begin with a /"); | |
114 } | 121 } |
115 expect(caughtException, isTrue); | 122 expect(caughtException, isTrue); |
116 | 123 |
117 expect(result['type'], equals('FSFile')); | |
118 expect(result['fileContents'], equals(fileContents)); | |
119 | |
120 // Write a set of files. | 124 // Write a set of files. |
121 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', { | 125 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', { |
122 'fsName': fsId, | 126 'fsName': fsId, |
123 'files': [ | 127 'files': [ |
124 ['/a', BASE64.encode(UTF8.encode('a_contents'))], | 128 ['/a', BASE64.encode(UTF8.encode('a_contents'))], |
125 ['/b', BASE64.encode(UTF8.encode('b_contents'))] | 129 ['/b', BASE64.encode(UTF8.encode('b_contents'))] |
126 ] | 130 ] |
127 }); | 131 }); |
128 expect(result['type'], equals('Success')); | 132 expect(result['type'], equals('Success')); |
129 | 133 |
130 // Read one of the files back. | 134 // Read one of the files back. |
131 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { | 135 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
132 'fsName': fsId, | 136 'fsName': fsId, |
133 'path': '/b', | 137 'path': '/b', |
134 }); | 138 }); |
135 expect(result['type'], equals('FSFile')); | 139 expect(result['type'], equals('FSFile')); |
136 expect(result['fileContents'], | 140 expect(result['fileContents'], |
137 equals(BASE64.encode(UTF8.encode('b_contents')))); | 141 equals(BASE64.encode(UTF8.encode('b_contents')))); |
138 | 142 |
139 // List all the files in the file system. | 143 // List all the files in the file system. |
140 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { | 144 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { |
141 'fsName': fsId, | 145 'fsName': fsId, |
142 }); | 146 }); |
143 expect(result['type'], equals('FSFilesList')); | 147 expect(result['type'], equals('FSFileList')); |
144 expect(result['files'].length, equals(3)); | 148 expect(result['files'].length, equals(3)); |
145 | 149 |
146 // Delete DevFS. | 150 // Delete DevFS. |
147 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { | 151 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { |
148 'fsName': fsId, | 152 'fsName': fsId, |
149 }); | 153 }); |
150 expect(result['type'], equals('Success')); | 154 expect(result['type'], equals('Success')); |
151 }, | 155 }, |
152 ]; | 156 ]; |
153 | 157 |
154 main(args) async => runVMTests(args, tests); | 158 main(args) async => runVMTests(args, tests); |
OLD | NEW |