mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Refactor DevFS so that it's easier to add new types of content such as kernel code * add tests for DevFS package scanning * add tests for DevFS over VMService protocol * which covers _DevFSHttpWriter and ServiceProtocolDevFSOperations * replace AssetBundleEntry and DevFSEntry with DevFSContent * refactor to cleanup common code and replace some fields with locals * rework .package file generation refactor away DevFSOperations.writeSource * only update .package file if it has changed * only write/delete/evict assets that have been changed/removed
72 lines
2.7 KiB
Dart
72 lines
2.7 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:convert';
|
|
import 'package:flutter_tools/src/asset.dart';
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
import 'package:flutter_tools/src/devfs.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
// Create a temporary directory and write a single file into it.
|
|
FileSystem fs = new LocalFileSystem();
|
|
Directory tempDir = fs.systemTempDirectory.createTempSync();
|
|
String projectRoot = tempDir.path;
|
|
String assetPath = 'banana.txt';
|
|
String assetContents = 'banana';
|
|
File tempFile = fs.file(path.join(projectRoot, assetPath));
|
|
tempFile.parent.createSync(recursive: true);
|
|
tempFile.writeAsBytesSync(UTF8.encode(assetContents));
|
|
|
|
// Fixed asset bundle tests.
|
|
group('AssetBundle.fixed', () {
|
|
test('empty strings', () async {
|
|
expect(new AssetBundle.fixed(null, null), isNotNull);
|
|
expect(new AssetBundle.fixed('', ''), isNotNull);
|
|
expect(new AssetBundle.fixed(null, null).entries, isEmpty);
|
|
});
|
|
test('does not need a rebuild', () async {
|
|
expect(new AssetBundle.fixed(null, null).needsBuild(), isFalse);
|
|
});
|
|
test('empty string', () async {
|
|
AssetBundle ab = new AssetBundle.fixed('', '');
|
|
expect(ab.entries, isEmpty);
|
|
});
|
|
test('single entry', () async {
|
|
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt');
|
|
expect(ab.entries, isNotEmpty);
|
|
expect(ab.entries.length, 1);
|
|
String archivePath = ab.entries.keys.first;
|
|
expect(archivePath, isNotNull);
|
|
expect(archivePath, 'apple.txt');
|
|
});
|
|
test('two entries', () async {
|
|
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt,packages/flutter_gallery_assets/shrine/products/heels.png');
|
|
expect(ab.entries, isNotEmpty);
|
|
expect(ab.entries.length, 2);
|
|
List<String> archivePaths = ab.entries.keys.toList()..sort();
|
|
expect(archivePaths[0], 'apple.txt');
|
|
expect(archivePaths[1], 'packages/flutter_gallery_assets/shrine/products/heels.png');
|
|
});
|
|
test('file contents', () async {
|
|
AssetBundle ab = new AssetBundle.fixed(projectRoot, assetPath);
|
|
expect(ab.entries, isNotEmpty);
|
|
expect(ab.entries.length, 1);
|
|
String archivePath = ab.entries.keys.first;
|
|
DevFSContent content = ab.entries[archivePath];
|
|
expect(archivePath, assetPath);
|
|
expect(assetContents, UTF8.decode(await content.contentsAsBytes()));
|
|
});
|
|
});
|
|
|
|
group('AssetBundle.build', () {
|
|
test('nonempty', () async {
|
|
AssetBundle ab = new AssetBundle();
|
|
expect(await ab.build(), 0);
|
|
expect(ab.entries.length, greaterThan(0));
|
|
});
|
|
});
|
|
}
|