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

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

Issue 2733413003: Support DevFS paths encoded as URIs (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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // VMOptions=--error_on_bad_type --error_on_bad_override
5
6 import 'dart:async';
7 import 'dart:convert';
8 import 'dart:io';
9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart';
11 import 'test_helper.dart';
12
13 Future<String> readResponse(HttpClientResponse response) {
14 var completer = new Completer();
15 var contents = new StringBuffer();
16 response.transform(UTF8.decoder).listen((String data) {
17 contents.write(data);
18 }, onDone: () => completer.complete(contents.toString()));
19 return completer.future;
20 }
21
22
23 var tests = [
24 // Write a file with the ? character in the filename.
25 (VM vm) async {
26 var fsId = 'test';
27 // NOTE: When using the URI encoding scheme, paths cannot be absolute.
28 var filePath = 'foo/bar.dat';
29 var fileUri = Uri.parse(filePath);
30 var fileUriBase64 = BASE64.encode(UTF8.encode(fileUri.toString()));
31 var fileContents = [0, 1, 2, 3, 4, 5, 6, 255];
32 var fileContentsBase64 = BASE64.encode(fileContents);
33
34 var filePath2 = 'baz/boo.dat';
35 var fileUri2 = Uri.parse(filePath2);
36
37 var result;
38 // Create DevFS.
39 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId });
40 expect(result['type'], equals('FileSystem'));
41 expect(result['name'], equals(fsId));
42 expect(result['uri'], new isInstanceOf<String>());
43
44 // Write the file by issuing an HTTP PUT.
45 HttpClient client = new HttpClient();
46 HttpClientRequest request =
47 await client.putUrl(Uri.parse(serviceHttpAddress));
48 request.headers.add('dev_fs_name', fsId);
49 request.headers.add('dev_fs_uri_b64', fileUriBase64);
50 request.add(GZIP.encode([9]));
51 HttpClientResponse response = await request.close();
52 String responseBody = await readResponse(response);
53 result = JSON.decode(responseBody);
54 print(result);
55 expect(result['result']['type'], equals('Success'));
56
57 // Trigger an error by issuing an HTTP PUT.
58 request = await client.putUrl(Uri.parse(serviceHttpAddress));
59 request.headers.add('dev_fs_name', fsId);
60 // omit the 'dev_fs_path' parameter.
61 request.write(GZIP.encode(fileContents));
62 response = await request.close();
63 responseBody = await readResponse(response);
64 result = JSON.decode(responseBody);
65 Map error = result['error']['data'];
66 expect(error, isNotNull);
67 expect(error['details'].contains("expects the 'path' parameter"), isTrue);
68
69 // Write the file again but this time with the true file contents.
70 client = new HttpClient();
71 request =
72 await client.putUrl(Uri.parse(serviceHttpAddress));
73 request.headers.add('dev_fs_name', fsId);
74 request.headers.add('dev_fs_uri_b64', fileUriBase64);
75 request.add(GZIP.encode(fileContents));
76 response = await request.close();
77 responseBody = await readResponse(response);
78 result = JSON.decode(responseBody);
79 expect(result['result']['type'], equals('Success'));
80
81 // Close the HTTP client.
82 client.close();
83
84 // Read the file back.
85 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
86 'fsName': fsId,
87 'uri': fileUri.toString(),
88 });
89 expect(result['type'], equals('FSFile'));
90 expect(result['fileContents'], equals(fileContentsBase64));
91
92 // Write a second file via URI.
93 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', {
94 'fsName': fsId,
95 'uri': fileUri2.toString(),
96 'fileContents': fileContentsBase64
97 });
98
99 // Read the second file back.
100 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
101 'fsName': fsId,
102 'uri': fileUri2.toString(),
103 });
104 expect(result['type'], equals('FSFile'));
105 expect(result['fileContents'], equals(fileContentsBase64));
106
107 // Delete DevFS.
108 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
109 'fsName': fsId,
110 });
111 expect(result['type'], equals('Success'));
112 },
113 ];
114
115 main(args) async => runVMTests(args, tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698