| 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:async'; | 6 import 'dart:async'; |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:observatory/service_io.dart'; | 9 import 'package:observatory/service_io.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'test_helper.dart'; | 11 import 'test_helper.dart'; |
| 12 | 12 |
| 13 Future<String> readResponse(HttpClientResponse response) { | 13 Future<String> readResponse(HttpClientResponse response) { |
| 14 var completer = new Completer(); | 14 var completer = new Completer(); |
| 15 var contents = new StringBuffer(); | 15 var contents = new StringBuffer(); |
| 16 response.transform(UTF8.decoder).listen((String data) { | 16 response.transform(UTF8.decoder).listen((String data) { |
| 17 contents.write(data); | 17 contents.write(data); |
| 18 }, onDone: () => completer.complete(contents.toString())); | 18 }, onDone: () => completer.complete(contents.toString())); |
| 19 return completer.future; | 19 return completer.future; |
| 20 } | 20 } |
| 21 | 21 |
| 22 | |
| 23 var tests = [ | 22 var tests = [ |
| 24 // Write a file with the ? character in the filename. | 23 // Write a file with the ? character in the filename. |
| 25 (VM vm) async { | 24 (VM vm) async { |
| 26 var fsId = 'test'; | 25 var fsId = 'test'; |
| 27 var filePath = '/foo/bar.dat'; | 26 var filePath = '/foo/bar.dat'; |
| 28 var fileContents = [0, 1, 2, 3, 4, 5, 6, 255]; | 27 var fileContents = [0, 1, 2, 3, 4, 5, 6, 255]; |
| 29 var fileContentsBase64 = BASE64.encode(fileContents); | 28 var fileContentsBase64 = BASE64.encode(fileContents); |
| 30 | 29 |
| 31 var result; | 30 var result; |
| 32 // Create DevFS. | 31 // Create DevFS. |
| 33 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId }); | 32 result = await vm.invokeRpcNoUpgrade('_createDevFS', {'fsName': fsId}); |
| 34 expect(result['type'], equals('FileSystem')); | 33 expect(result['type'], equals('FileSystem')); |
| 35 expect(result['name'], equals(fsId)); | 34 expect(result['name'], equals(fsId)); |
| 36 expect(result['uri'], new isInstanceOf<String>()); | 35 expect(result['uri'], new isInstanceOf<String>()); |
| 37 | 36 |
| 38 // Write the file by issuing an HTTP PUT. | 37 // Write the file by issuing an HTTP PUT. |
| 39 HttpClient client = new HttpClient(); | 38 HttpClient client = new HttpClient(); |
| 40 HttpClientRequest request = | 39 HttpClientRequest request = |
| 41 await client.putUrl(Uri.parse(serviceHttpAddress)); | 40 await client.putUrl(Uri.parse(serviceHttpAddress)); |
| 42 request.headers.add('dev_fs_name', fsId); | 41 request.headers.add('dev_fs_name', fsId); |
| 43 request.headers.add('dev_fs_path', filePath); | 42 request.headers.add('dev_fs_path', filePath); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 request.write(GZIP.encode(fileContents)); | 53 request.write(GZIP.encode(fileContents)); |
| 55 response = await request.close(); | 54 response = await request.close(); |
| 56 responseBody = await readResponse(response); | 55 responseBody = await readResponse(response); |
| 57 result = JSON.decode(responseBody); | 56 result = JSON.decode(responseBody); |
| 58 Map error = result['error']['data']; | 57 Map error = result['error']['data']; |
| 59 expect(error, isNotNull); | 58 expect(error, isNotNull); |
| 60 expect(error['details'].contains("expects the 'path' parameter"), isTrue); | 59 expect(error['details'].contains("expects the 'path' parameter"), isTrue); |
| 61 | 60 |
| 62 // Write the file again but this time with the true file contents. | 61 // Write the file again but this time with the true file contents. |
| 63 client = new HttpClient(); | 62 client = new HttpClient(); |
| 64 request = | 63 request = await client.putUrl(Uri.parse(serviceHttpAddress)); |
| 65 await client.putUrl(Uri.parse(serviceHttpAddress)); | |
| 66 request.headers.add('dev_fs_name', fsId); | 64 request.headers.add('dev_fs_name', fsId); |
| 67 request.headers.add('dev_fs_path', filePath); | 65 request.headers.add('dev_fs_path', filePath); |
| 68 request.add(GZIP.encode(fileContents)); | 66 request.add(GZIP.encode(fileContents)); |
| 69 response = await request.close(); | 67 response = await request.close(); |
| 70 responseBody = await readResponse(response); | 68 responseBody = await readResponse(response); |
| 71 result = JSON.decode(responseBody); | 69 result = JSON.decode(responseBody); |
| 72 expect(result['result']['type'], equals('Success')); | 70 expect(result['result']['type'], equals('Success')); |
| 73 | 71 |
| 74 // Close the HTTP client. | 72 // Close the HTTP client. |
| 75 client.close(); | 73 client.close(); |
| 76 | 74 |
| 77 // Read the file back. | 75 // Read the file back. |
| 78 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { | 76 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', { |
| 79 'fsName': fsId, | 77 'fsName': fsId, |
| 80 'path': filePath, | 78 'path': filePath, |
| 81 }); | 79 }); |
| 82 expect(result['type'], equals('FSFile')); | 80 expect(result['type'], equals('FSFile')); |
| 83 expect(result['fileContents'], equals(fileContentsBase64)); | 81 expect(result['fileContents'], equals(fileContentsBase64)); |
| 84 | 82 |
| 85 // List all the files in the file system. | 83 // List all the files in the file system. |
| 86 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { | 84 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', { |
| 87 'fsName': fsId, | 85 'fsName': fsId, |
| 88 }); | 86 }); |
| 89 expect(result['type'], equals('FSFileList')); | 87 expect(result['type'], equals('FSFileList')); |
| 90 expect(result['files'].length, equals(1)); | 88 expect(result['files'].length, equals(1)); |
| 91 expect(result['files'][0]['name'], equals(filePath)); | 89 expect(result['files'][0]['name'], equals(filePath)); |
| 92 | 90 |
| 93 // Delete DevFS. | 91 // Delete DevFS. |
| 94 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { | 92 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', { |
| 95 'fsName': fsId, | 93 'fsName': fsId, |
| 96 }); | 94 }); |
| 97 expect(result['type'], equals('Success')); | 95 expect(result['type'], equals('Success')); |
| 98 }, | 96 }, |
| 99 ]; | 97 ]; |
| 100 | 98 |
| 101 main(args) async => runVMTests(args, tests); | 99 main(args) async => runVMTests(args, tests); |
| OLD | NEW |