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

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

Issue 2059883003: DevFS initial implementation (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 'package:observatory/service_io.dart';
9 import 'package:unittest/unittest.dart';
10 import 'test_helper.dart';
11
12 var tests = [
13 (VM vm) async {
14 var result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
15 expect(result['type'], equals('FSList'));
16 expect(result['ids'].toString(), equals("[]"));
17
18 var params = {
19 'fsName': 'alpha'
20 };
21 result = await vm.invokeRpcNoUpgrade('_createDevFS', params);
22 expect(result['type'], equals('Success'));
23
24 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
25 expect(result['type'], equals('FSList'));
26 expect(result['ids'].toString(), equals('[alpha]'));
27
28 bool caughtException;
29 try {
30 await vm.invokeRpcNoUpgrade('_createDevFS', params);
31 expect(false, isTrue, reason:'Unreachable');
32 } on ServerRpcException catch(e) {
33 caughtException = true;
34 expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists));
35 expect(e.message, "_createDevFS: file system 'alpha' already exists");
36 }
37 expect(caughtException, isTrue);
38
39 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
40 expect(result['type'], equals('Success'));
41
42 result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
43 expect(result['type'], equals('FSList'));
44 expect(result['ids'].toString(), equals("[]"));
45
46 caughtException = false;
47 try {
48 await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
49 expect(false, isTrue, reason:'Unreachable');
50 } on ServerRpcException catch(e) {
51 caughtException = true;
52 expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist));
53 expect(e.message, "_deleteDevFS: file system 'alpha' does not exist");
54 }
55 expect(caughtException, isTrue);
56 },
57
58 (VM vm) async {
59 var fsId = 'banana';
60 var filePath = '/foobar.dat';
61 var fileContents = BASE64.encode(UTF8.encode('fileContents'));
62
63 var result;
64 // Create DevFS.
65 result = await vm.invokeRpcNoUpgrade('_createDevFS', {
66 'fsName': fsId
67 });
68 expect(result['type'], equals('Success'));
69
70 bool caughtException = false;
71 try {
72 await vm.invokeRpcNoUpgrade('_readDevFSFile', {
73 'fsName': fsId,
74 'path': filePath,
75 });
76 expect(false, isTrue, reason:'Unreachable');
77 } on ServerRpcException catch(e) {
78 caughtException = true;
79 expect(e.code, equals(ServerRpcException.kFileDoesNotExist));
80 expect(e.message,
81 "_readDevFSFile: file 'dart-devfs://banana//foobar.dat' "
82 "does not exist");
83 }
84 expect(caughtException, isTrue);
85
86 // Write a file.
87 result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', {
88 'fsName': fsId,
89 'path': filePath,
90 'fileContents': fileContents
91 });
92 expect(result['type'], equals('Success'));
93
94 // Read the file back.
95 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
96 'fsName': fsId,
97 'path': filePath,
98 });
99 expect(result['type'], equals('FSFile'));
100 expect(result['fileContents'], equals(fileContents));
101
102 // Write a set of files.
103 result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', {
104 'fsName': fsId,
105 'files': [
106 ['/a', BASE64.encode(UTF8.encode('a_contents'))],
107 ['/b', BASE64.encode(UTF8.encode('b_contents'))]
108 ]
109 });
110 expect(result['type'], equals('Success'));
111
112 // Read one of the files back.
113 result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
114 'fsName': fsId,
115 'path': '/b',
116 });
117 expect(result['type'], equals('FSFile'));
118 expect(result['fileContents'],
119 equals(BASE64.encode(UTF8.encode('b_contents'))));
120
121 // List all the files in the file system.
122 result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', {
123 'fsName': fsId,
124 });
125 expect(result['type'], equals('FSFilesList'));
126 expect(result['files'].length, equals(3));
127
128 // Delete DevFS.
129 result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
130 'fsName': fsId,
131 });
132 expect(result['type'], equals('Success'));
133 },
134 ];
135
136 main(args) async => runVMTests(args, tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698