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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/observatory/tests/service/dev_fs_test.dart
diff --git a/runtime/observatory/tests/service/dev_fs_test.dart b/runtime/observatory/tests/service/dev_fs_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9f23396c37ac7ebc6ca676c8f4c1dd7dd55026e8
--- /dev/null
+++ b/runtime/observatory/tests/service/dev_fs_test.dart
@@ -0,0 +1,155 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--error_on_bad_type --error_on_bad_override
+
+import 'dart:async';
+import 'dart:convert';
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'test_helper.dart';
+
+var tests = [
+ (VM vm) async {
+ var result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
+ expect(result['type'], equals('FSList'));
+ expect(result['fsNames'].toString(), equals("[]"));
+
+ var params = {
+ 'fsName': 'alpha'
+ };
+ result = await vm.invokeRpcNoUpgrade('_createDevFS', params);
+ expect(result['type'], equals('Success'));
+
+ result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
+ expect(result['type'], equals('FSList'));
+ expect(result['fsNames'].toString(), equals('[alpha]'));
+
+ bool caughtException;
+ try {
+ await vm.invokeRpcNoUpgrade('_createDevFS', params);
+ expect(false, isTrue, reason:'Unreachable');
+ } on ServerRpcException catch(e) {
+ caughtException = true;
+ expect(e.code, equals(ServerRpcException.kFileSystemAlreadyExists));
+ expect(e.message, "_createDevFS: file system 'alpha' already exists");
+ }
+ expect(caughtException, isTrue);
+
+ result = await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
+ expect(result['type'], equals('Success'));
+
+ result = await vm.invokeRpcNoUpgrade('_listDevFS', {});
+ expect(result['type'], equals('FSList'));
+ expect(result['fsNames'].toString(), equals("[]"));
+
+ caughtException = false;
+ try {
+ await vm.invokeRpcNoUpgrade('_deleteDevFS', params);
+ expect(false, isTrue, reason:'Unreachable');
+ } on ServerRpcException catch(e) {
+ caughtException = true;
+ expect(e.code, equals(ServerRpcException.kFileSystemDoesNotExist));
+ expect(e.message, "_deleteDevFS: file system 'alpha' does not exist");
+ }
+ expect(caughtException, isTrue);
+ },
+
+ (VM vm) async {
+ var fsId = 'banana';
+ var filePath = '/foobar.dat';
+ var fileContents = BASE64.encode(UTF8.encode('fileContents'));
+
+ var result;
+ // Create DevFS.
+ result = await vm.invokeRpcNoUpgrade('_createDevFS', {
+ 'fsName': fsId
+ });
+ expect(result['type'], equals('Success'));
+
+ bool caughtException = false;
+ try {
+ await vm.invokeRpcNoUpgrade('_readDevFSFile', {
+ 'fsName': fsId,
+ 'path': filePath,
+ });
+ expect(false, isTrue, reason:'Unreachable');
+ } on ServerRpcException catch(e) {
+ caughtException = true;
+ expect(e.code, equals(ServerRpcException.kFileDoesNotExist));
+ expect(e.message,
+ "_readDevFSFile: file 'dart-devfs://banana//foobar.dat' "
+ "does not exist");
+ }
+ expect(caughtException, isTrue);
+
+ // Write a file.
+ result = await vm.invokeRpcNoUpgrade('_writeDevFSFile', {
+ 'fsName': fsId,
+ 'path': filePath,
+ 'fileContents': fileContents
+ });
+ expect(result['type'], equals('Success'));
+
+ // Read the file back.
+ result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
+ 'fsName': fsId,
+ 'path': filePath,
+ });
+ expect(result['type'], equals('FSFile'));
+ expect(result['fileContents'], equals(fileContents));
+
+ // Read a malformed path back.
+ caughtException = false;
+ try {
+ result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
+ 'fsName': fsId,
+ 'path': filePath.substring(1) // Strip the leading '/'.
+ });
+ } on ServerRpcException catch(e) {
+ caughtException = true;
+ expect(e.code, equals(ServerRpcException.kInvalidParams));
+ expect(e.message,
+ "_readDevFSFile: file system path \'foobar.dat\' "
+ "must begin with a /");
+ }
+ expect(caughtException, isTrue);
+
+ expect(result['type'], equals('FSFile'));
+ expect(result['fileContents'], equals(fileContents));
+
+ // Write a set of files.
+ result = await vm.invokeRpcNoUpgrade('_writeDevFSFiles', {
+ 'fsName': fsId,
+ 'files': [
+ ['/a', BASE64.encode(UTF8.encode('a_contents'))],
+ ['/b', BASE64.encode(UTF8.encode('b_contents'))]
+ ]
+ });
+ expect(result['type'], equals('Success'));
+
+ // Read one of the files back.
+ result = await vm.invokeRpcNoUpgrade('_readDevFSFile', {
+ 'fsName': fsId,
+ 'path': '/b',
+ });
+ expect(result['type'], equals('FSFile'));
+ expect(result['fileContents'],
+ equals(BASE64.encode(UTF8.encode('b_contents'))));
+
+ // List all the files in the file system.
+ result = await vm.invokeRpcNoUpgrade('_listDevFSFiles', {
+ 'fsName': fsId,
+ });
+ expect(result['type'], equals('FSFilesList'));
+ expect(result['files'].length, equals(3));
+
+ // Delete DevFS.
+ result = await vm.invokeRpcNoUpgrade('_deleteDevFS', {
+ 'fsName': fsId,
+ });
+ expect(result['type'], equals('Success'));
+ },
+];
+
+main(args) async => runVMTests(args, tests);
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698