2018-07-10 05:51:12 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
2019-06-26 23:02:49 +00:00
|
|
|
// Integration tests which invoke flutter instead of unit testing the code
|
|
|
|
// will not produce meaningful coverage information - we can measure coverage
|
|
|
|
// from the isolate running the test, but not from the isolate started via
|
|
|
|
// the command line process.
|
|
|
|
@Tags(<String>['no_coverage'])
|
2018-07-10 05:51:12 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:file/file.dart';
|
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2018-08-15 03:33:58 +00:00
|
|
|
|
2018-11-08 07:55:54 +00:00
|
|
|
import 'package:vm_service_lib/vm_service_lib.dart';
|
2018-07-10 05:51:12 +00:00
|
|
|
|
2018-08-15 03:33:58 +00:00
|
|
|
import '../src/common.dart';
|
2018-07-10 05:51:12 +00:00
|
|
|
import 'test_data/basic_project.dart';
|
2019-01-10 15:33:59 +00:00
|
|
|
import 'test_data/tests_project.dart';
|
2018-07-10 05:51:12 +00:00
|
|
|
import 'test_driver.dart';
|
2018-10-19 11:51:31 +00:00
|
|
|
import 'test_utils.dart';
|
2018-07-10 05:51:12 +00:00
|
|
|
|
|
|
|
void main() {
|
2018-11-19 08:25:42 +00:00
|
|
|
group('flutter run expression evaluation', () {
|
2018-08-17 20:17:23 +00:00
|
|
|
Directory tempDir;
|
2018-09-12 06:29:29 +00:00
|
|
|
final BasicProject _project = BasicProject();
|
2018-11-19 08:25:42 +00:00
|
|
|
FlutterRunTestDriver _flutter;
|
2018-08-17 20:17:23 +00:00
|
|
|
|
2018-07-10 05:51:12 +00:00
|
|
|
setUp(() async {
|
2019-02-11 16:20:45 +00:00
|
|
|
tempDir = createResolvedTempDirectorySync('run_expression_eval_test.');
|
2018-07-10 05:51:12 +00:00
|
|
|
await _project.setUpIn(tempDir);
|
2018-11-19 08:25:42 +00:00
|
|
|
_flutter = FlutterRunTestDriver(tempDir);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2018-08-17 20:17:23 +00:00
|
|
|
await _flutter.stop();
|
|
|
|
tryToDelete(tempDir);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
2019-01-19 08:31:05 +00:00
|
|
|
Future<void> breakInBuildMethod(FlutterTestDriver flutter) async {
|
|
|
|
await _flutter.breakAt(
|
|
|
|
_project.buildMethodBreakpointUri,
|
|
|
|
_project.buildMethodBreakpointLine,
|
|
|
|
);
|
2018-07-10 05:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-01-19 08:31:05 +00:00
|
|
|
Future<void> breakInTopLevelFunction(FlutterTestDriver flutter) async {
|
|
|
|
await _flutter.breakAt(
|
|
|
|
_project.topLevelFunctionBreakpointUri,
|
|
|
|
_project.topLevelFunctionBreakpointLine,
|
|
|
|
);
|
2018-07-10 05:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('can evaluate trivial expressions in top level function', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInTopLevelFunction(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateTrivialExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate trivial expressions in build method', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInBuildMethod(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateTrivialExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate complex expressions in top level function', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInTopLevelFunction(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateComplexExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate complex expressions in build method', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInBuildMethod(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateComplexExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate expressions returning complex objects in top level function', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInTopLevelFunction(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateComplexReturningExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate expressions returning complex objects in build method', () async {
|
|
|
|
await _flutter.run(withDebugger: true);
|
|
|
|
await breakInBuildMethod(_flutter);
|
2018-11-19 08:25:42 +00:00
|
|
|
await evaluateComplexReturningExpressions(_flutter);
|
2018-07-10 05:51:12 +00:00
|
|
|
});
|
2019-06-26 20:55:16 +00:00
|
|
|
}, timeout: const Timeout.factor(10), tags: <String>['integration']); // The DevFS sync takes a really long time, so these tests can be slow.
|
2019-01-10 15:33:59 +00:00
|
|
|
|
|
|
|
group('flutter test expression evaluation', () {
|
|
|
|
Directory tempDir;
|
|
|
|
final TestsProject _project = TestsProject();
|
|
|
|
FlutterTestTestDriver _flutter;
|
|
|
|
|
|
|
|
setUp(() async {
|
2019-01-17 11:29:18 +00:00
|
|
|
tempDir = createResolvedTempDirectorySync('test_expression_eval_test.');
|
2019-01-10 15:33:59 +00:00
|
|
|
await _project.setUpIn(tempDir);
|
|
|
|
_flutter = FlutterTestTestDriver(tempDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await _flutter.quit();
|
|
|
|
tryToDelete(tempDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate trivial expressions in a test', () async {
|
|
|
|
await _flutter.test(
|
|
|
|
withDebugger: true,
|
|
|
|
beforeStart: () => _flutter.addBreakpoint(_project.breakpointUri, _project.breakpointLine),
|
|
|
|
);
|
2019-01-15 15:39:35 +00:00
|
|
|
await _flutter.waitForPause();
|
2019-01-10 15:33:59 +00:00
|
|
|
await evaluateTrivialExpressions(_flutter);
|
2019-07-22 18:43:37 +00:00
|
|
|
await _flutter.resume();
|
2019-01-10 15:33:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate complex expressions in a test', () async {
|
|
|
|
await _flutter.test(
|
|
|
|
withDebugger: true,
|
|
|
|
beforeStart: () => _flutter.addBreakpoint(_project.breakpointUri, _project.breakpointLine),
|
|
|
|
);
|
2019-01-15 15:39:35 +00:00
|
|
|
await _flutter.waitForPause();
|
2019-01-10 15:33:59 +00:00
|
|
|
await evaluateComplexExpressions(_flutter);
|
2019-07-22 18:43:37 +00:00
|
|
|
await _flutter.resume();
|
2019-01-10 15:33:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can evaluate expressions returning complex objects in a test', () async {
|
|
|
|
await _flutter.test(
|
|
|
|
withDebugger: true,
|
|
|
|
beforeStart: () => _flutter.addBreakpoint(_project.breakpointUri, _project.breakpointLine),
|
|
|
|
);
|
2019-01-15 15:39:35 +00:00
|
|
|
await _flutter.waitForPause();
|
2019-01-10 15:33:59 +00:00
|
|
|
await evaluateComplexReturningExpressions(_flutter);
|
2019-07-22 18:43:37 +00:00
|
|
|
await _flutter.resume();
|
2019-01-10 15:33:59 +00:00
|
|
|
});
|
2019-07-22 18:43:37 +00:00
|
|
|
}, timeout: const Timeout.factor(10), tags: <String>['integration']); // The DevFS sync takes a really long time, so these tests can be slow.
|
2018-07-10 05:51:12 +00:00
|
|
|
}
|
2018-11-19 08:25:42 +00:00
|
|
|
|
|
|
|
Future<void> evaluateTrivialExpressions(FlutterTestDriver flutter) async {
|
|
|
|
InstanceRef res;
|
|
|
|
|
|
|
|
res = await flutter.evaluateInFrame('"test"');
|
|
|
|
expect(res.kind == InstanceKind.kString && res.valueAsString == 'test', isTrue);
|
|
|
|
|
|
|
|
res = await flutter.evaluateInFrame('1');
|
|
|
|
expect(res.kind == InstanceKind.kInt && res.valueAsString == 1.toString(), isTrue);
|
|
|
|
|
|
|
|
res = await flutter.evaluateInFrame('true');
|
|
|
|
expect(res.kind == InstanceKind.kBool && res.valueAsString == true.toString(), isTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> evaluateComplexExpressions(FlutterTestDriver flutter) async {
|
|
|
|
final InstanceRef res = await flutter.evaluateInFrame('new DateTime.now().year');
|
2019-03-06 08:37:32 +00:00
|
|
|
expect(res.kind == InstanceKind.kInt && res.valueAsString == DateTime.now().year.toString(), isTrue);
|
2018-11-19 08:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> evaluateComplexReturningExpressions(FlutterTestDriver flutter) async {
|
|
|
|
final DateTime now = DateTime.now();
|
2019-03-06 08:37:32 +00:00
|
|
|
final InstanceRef resp = await flutter.evaluateInFrame('new DateTime.now()');
|
|
|
|
expect(resp.classRef.name, equals('DateTime'));
|
|
|
|
// Ensure we got a reasonable approximation. The more accurate we try to
|
|
|
|
// make this, the more likely it'll fail due to differences in the time
|
|
|
|
// in the remote VM and the local VM at the time the code runs.
|
|
|
|
final InstanceRef res = await flutter.evaluate(resp.id, r'"$year-$month-$day"');
|
|
|
|
expect(res.valueAsString, equals('${now.year}-${now.month}-${now.day}'));
|
2018-11-19 08:25:42 +00:00
|
|
|
}
|