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

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

Issue 2225583002: Support devFS writes via HTTP PUT (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rmacnak review Created 4 years, 4 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
« no previous file with comments | « runtime/bin/vmservice/vmservice_io.dart ('k') | sdk/lib/vmservice/devfs.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 var filePath = '/foo/bar.dat';
28 var fileContents = [0, 1, 2, 3, 4, 5, 6, 255];
29 var fileContentsBase64 = BASE64.encode(fileContents);
30
31 var result;
32 // Create DevFS.
33 result = await vm.invokeRpcNoUpgrade('_createDevFS', { 'fsName': fsId });
34 expect(result['type'], equals('FileSystem'));
35 expect(result['name'], equals(fsId));
36 expect(result['uri'], new isInstanceOf<String>());
37
38 // Write the file by issuing an HTTP PUT.
39 HttpClient client = new HttpClient();
40 HttpClientRequest request =
41 await client.putUrl(Uri.parse(serviceHttpAddress));
42 request.headers.add('dev_fs_name', fsId);
43 request.headers.add('dev_fs_path', filePath);
44 request.add(GZIP.encode([9]));
45 HttpClientResponse response = await request.close();
46 String responseBody = await readResponse(response);
47 result = JSON.decode(responseBody);
48 expect(result['result']['type'], equals('Success'));
49
50 // Trigger an error by issuing an HTTP PUT.
51 request = await client.putUrl(Uri.parse(serviceHttpAddress));
52 request.headers.add('dev_fs_name', fsId);
53 // omit the 'dev_fs_path' parameter.
54 request.write(GZIP.encode(fileContents));
55 response = await request.close();
56 responseBody = await readResponse(response);
57 result = JSON.decode(responseBody);
58 Map error = result['error']['data'];
59 expect(error, isNotNull);
60 expect(error['details'].contains("expects the 'path' parameter"), isTrue);
61
62 // Write the file again but this time with the true file contents.
63 client = new HttpClient();
64 request =
65 await client.putUrl(Uri.parse(serviceHttpAddress));
66 request.headers.add('dev_fs_name', fsId);
67 request.headers.add('dev_fs_path', filePath);
68 request.add(GZIP.encode(fileContents));
69 response = await request.close();
70 responseBody = await readResponse(response);
71 result = JSON.decode(responseBody);
72 expect(result['result']['type'], equals('Success'));
73
74 // Close the HTTP client.
75 client.close();
76
77 // Read the file back.
78 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
79 'fsName': fsId,
80 'path': filePath,
81 });
82 expect(result['type'], equals('FSFile'));
83 expect(result['fileContents'], equals(fileContentsBase64));
84
85 // List all the files in the file system.
86 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', {
87 'fsName': fsId,
88 });
89 expect(result['type'], equals('FSFileList'));
90 expect(result['files'].length, equals(1));
91 expect(result['files'][0]['name'], equals(filePath));
92
93 // Delete DevFS.
94 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
95 'fsName': fsId,
96 });
97 expect(result['type'], equals('Success'));
98 },
99 ];
100
101 main(args) async => runVMTests(args, tests);
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/vmservice_io.dart ('k') | sdk/lib/vmservice/devfs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698