Skip to content

Commit

Permalink
sync web engine; run web engine tests (flutter#11031)
Browse files Browse the repository at this point in the history
sync web engine; run web engine tests
  • Loading branch information
yjbanov authored Aug 22, 2019
1 parent a1fe6a6 commit fad38e2
Show file tree
Hide file tree
Showing 64 changed files with 6,023 additions and 1,092 deletions.
4 changes: 4 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ task:
test_host_script: |
cd $ENGINE_PATH/src
./flutter/testing/run_tests.sh host_debug_unopt
test_web_engine_script: |
cd $ENGINE_PATH/src/flutter/lib/web_ui
$ENGINE_PATH/src/out/host_debug_unopt/dart-sdk/bin/pub get
$ENGINE_PATH/src/out/host_debug_unopt/dart-sdk/bin/dart dev/test.dart
fetch_framework_script: |
mkdir -p $FRAMEWORK_PATH
cd $FRAMEWORK_PATH
Expand Down
7 changes: 6 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ FILE: ../../../flutter/lib/ui/window/viewport_metrics.cc
FILE: ../../../flutter/lib/ui/window/viewport_metrics.h
FILE: ../../../flutter/lib/ui/window/window.cc
FILE: ../../../flutter/lib/ui/window/window.h
FILE: ../../../flutter/lib/web_ui/dev/test.dart
FILE: ../../../flutter/lib/web_ui/lib/assets/houdini_painter.js
FILE: ../../../flutter/lib/web_ui/lib/src/engine.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/alarm_clock.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/assets.dart
Expand All @@ -353,11 +355,12 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/browser_detection.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/browser_location.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/engine_delegate.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/fonts.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/image.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/initialization.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/layer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/layer_scene_builder.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/layer_tree.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/matrix.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/path.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/picture.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/picture_recorder.dart
Expand All @@ -367,6 +370,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/rasterizer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/recording_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/runtime_delegate.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/surface.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/util.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/compositor/viewport_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/conic.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_canvas.dart
Expand Down Expand Up @@ -395,6 +399,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/buffers.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codec.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/serialization.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/shader.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/shadow.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/surface/backdrop_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/surface/clip.dart
Expand Down
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: 2009f69daad0d2b8a8037b2903f145ee
Signature: 24e0fa6ad08ae80380158c2b4ba44c65

18 changes: 18 additions & 0 deletions lib/web_ui/dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Sources of inspiration for this file:
#
# * https://github.com/dart-lang/angular/blob/master/dev/tool/test/dart_test_repo.yaml
# * https://github.com/dart-lang/angular/blob/master/_tests/dart_test.yaml

platforms:
- chrome
- vm
presets:
cirrus:
override_platforms:
chrome:
settings:
# Required because Cirrus runs us as root.
# https://chromium.googlesource.com/chromium/src/+/master/docs/design/sandbox.md
# https://docs.travis-ci.com/user/chrome#Sandboxing
arguments: --no-sandbox
reporter: expanded
189 changes: 189 additions & 0 deletions lib/web_ui/dev/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright 2013 The Flutter 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:async';
import 'dart:io' as io;

import 'package:path/path.dart' as pathlib;

final Environment environment = Environment();

void main() async {
if (io.Directory.current.absolute.path != environment.webUiRootDir.absolute.path) {
io.stderr.writeln('Current directory is not the root of the web_ui package directory.');
io.stderr.writeln('web_ui directory is: ${environment.webUiRootDir.absolute.path}');
io.stderr.writeln('current directory is: ${io.Directory.current.absolute.path}');
io.exit(1);
}

await _checkLicenseHeaders();
await _runTests();
}

void _checkLicenseHeaders() {
final List<io.File> allSourceFiles = _flatListSourceFiles(environment.webUiRootDir);
_expect(allSourceFiles.isNotEmpty, 'Dart source listing of ${environment.webUiRootDir.path} must not be empty.');

final List<String> allDartPaths = allSourceFiles.map((f) => f.path).toList();
print(allDartPaths.join('\n'));

for (String expectedDirectory in const <String>['lib', 'test', 'dev', 'tool']) {
final String expectedAbsoluteDirectory = pathlib.join(environment.webUiRootDir.path, expectedDirectory);
_expect(
allDartPaths.where((p) => p.startsWith(expectedAbsoluteDirectory)).isNotEmpty,
'Must include the $expectedDirectory/ directory',
);
}

allSourceFiles.forEach(_expectLicenseHeader);
}

final _copyRegex = RegExp(r'// Copyright 2013 The Flutter Authors\. All rights reserved\.');

void _expectLicenseHeader(io.File file) {
List<String> head = file.readAsStringSync().split('\n').take(3).toList();

_expect(head.length >= 3, 'File too short: ${file.path}');
_expect(
_copyRegex.firstMatch(head[0]) != null,
'Invalid first line of license header in file ${file.path}',
);
_expect(
head[1] == '// Use of this source code is governed by a BSD-style license that can be',
'Invalid second line of license header in file ${file.path}',
);
_expect(
head[2] == '// found in the LICENSE file.',
'Invalid second line of license header in file ${file.path}',
);
}

void _expect(bool value, String requirement) {
if (!value) {
throw Exception('Test failed: ${requirement}');
}
}

List<io.File> _flatListSourceFiles(io.Directory directory) {
return directory
.listSync(recursive: true)
.whereType<io.File>()
.where((f) => f.path.endsWith('.dart') || f.path.endsWith('.js'))
.toList();
}

Future<void> _runTests() async {
// TODO(yjbanov): make the following tests pass.
const List<String> testBlacklist = <String>[
'test/text/measurement_test.dart',
'test/paragraph_test.dart',
'test/text_test.dart',
];

final List<String> testFiles = io.Directory('test')
.listSync(recursive: true)
.whereType<io.File>()
.map<String>((io.File file) => file.path)
.where((String path) => path.endsWith('_test.dart') && !testBlacklist.contains(path))
.toList();

final io.Process pubRunTest = await io.Process.start(
environment.pubExecutable,
<String>[
'run',
'test',
'--preset=cirrus',
'--platform=chrome',
...testFiles,
],
);

final StreamSubscription stdoutSub = pubRunTest.stdout.listen(io.stdout.add);
final StreamSubscription stderrSub = pubRunTest.stderr.listen(io.stderr.add);
final int exitCode = await pubRunTest.exitCode;
stdoutSub.cancel();
stderrSub.cancel();

if (exitCode != 0) {
io.stderr.writeln('Test process exited with exit code $exitCode');
io.exit(1);
}
}

class Environment {
factory Environment() {
final io.File self = io.File.fromUri(io.Platform.script);
final io.Directory webUiRootDir = self.parent.parent;
final io.Directory engineSrcDir = webUiRootDir.parent.parent.parent;
final io.Directory outDir = io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory hostDebugUnoptDir = io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final String dartExecutable = pathlib.canonicalize(io.File(_which(io.Platform.executable)).absolute.path);
final io.Directory dartSdkDir = io.File(dartExecutable).parent.parent;

// Googlers frequently have their Dart SDK misconfigured for open-source projects. Let's help them out.
if (dartExecutable.startsWith('/usr/lib/google-dartlang')) {
io.stderr.writeln('ERROR: Using unsupported version of the Dart SDK: $dartExecutable');
io.exit(1);
}

return Environment._(
self: self,
webUiRootDir: webUiRootDir,
engineSrcDir: engineSrcDir,
outDir: outDir,
hostDebugUnoptDir: hostDebugUnoptDir,
dartExecutable: dartExecutable,
dartSdkDir: dartSdkDir,
);
}

Environment._({
this.self,
this.webUiRootDir,
this.engineSrcDir,
this.outDir,
this.hostDebugUnoptDir,
this.dartSdkDir,
this.dartExecutable,
});

final io.File self;
final io.Directory webUiRootDir;
final io.Directory engineSrcDir;
final io.Directory outDir;
final io.Directory hostDebugUnoptDir;
final io.Directory dartSdkDir;
final String dartExecutable;

String get pubExecutable => pathlib.join(dartSdkDir.path, 'bin', 'pub');

@override
String toString() {
return '''
runTest.dart script:
${self.path}
web_ui directory:
${webUiRootDir.path}
engine/src directory:
${engineSrcDir.path}
out directory:
${outDir.path}
out/host_debug_unopt directory:
${hostDebugUnoptDir.path}
Dart SDK directory:
${dartSdkDir.path}
dart executable:
${dartExecutable}
''';
}
}

String _which(String executable) {
final io.ProcessResult result = io.Process.runSync('which', <String>[executable]);
if (result.exitCode != 0) {
io.stderr.writeln(result.stderr);
io.exit(result.exitCode);
}
return result.stdout;
}
1 change: 1 addition & 0 deletions lib/web_ui/lib/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ahem.ttf
Loading

0 comments on commit fad38e2

Please sign in to comment.