2016-02-08 17:30:20 +00:00
|
|
|
// 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:async';
|
2016-03-29 19:14:44 +00:00
|
|
|
|
2017-11-23 01:24:41 +00:00
|
|
|
import 'package:flutter_driver/src/common/error.dart';
|
|
|
|
import 'package:flutter_driver/src/common/health.dart';
|
|
|
|
import 'package:flutter_driver/src/driver/driver.dart';
|
|
|
|
import 'package:flutter_driver/src/driver/timeline.dart';
|
2016-02-08 17:30:20 +00:00
|
|
|
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
|
2017-03-10 21:53:22 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
2016-02-08 17:30:20 +00:00
|
|
|
import 'package:vm_service_client/vm_service_client.dart';
|
2019-01-19 08:31:05 +00:00
|
|
|
import 'package:quiver/testing/async.dart';
|
2016-02-08 17:30:20 +00:00
|
|
|
|
2018-08-15 03:33:58 +00:00
|
|
|
import 'common.dart';
|
|
|
|
|
2017-03-10 00:31:48 +00:00
|
|
|
/// Magical timeout value that's different from the default.
|
2018-08-02 10:02:32 +00:00
|
|
|
const Duration _kTestTimeout = Duration(milliseconds: 1234);
|
2017-03-10 00:31:48 +00:00
|
|
|
const String _kSerializedTestTimeout = '1234';
|
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2016-02-08 17:30:20 +00:00
|
|
|
group('FlutterDriver.connect', () {
|
|
|
|
List<LogRecord> log;
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamSubscription<LogRecord> logSub;
|
2016-02-08 17:30:20 +00:00
|
|
|
MockVMServiceClient mockClient;
|
|
|
|
MockVM mockVM;
|
|
|
|
MockIsolate mockIsolate;
|
2017-05-10 22:16:45 +00:00
|
|
|
MockPeer mockPeer;
|
2016-02-08 17:30:20 +00:00
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void expectLogContains(String message) {
|
2018-10-01 19:29:08 +00:00
|
|
|
expect(log.map<String>((LogRecord r) => '$r'), anyElement(contains(message)));
|
2016-02-08 17:30:20 +00:00
|
|
|
}
|
2018-03-27 17:57:50 +00:00
|
|
|
|
2016-02-08 17:30:20 +00:00
|
|
|
setUp(() {
|
|
|
|
log = <LogRecord>[];
|
|
|
|
logSub = flutterDriverLog.listen(log.add);
|
2018-09-12 06:29:29 +00:00
|
|
|
mockClient = MockVMServiceClient();
|
|
|
|
mockVM = MockVM();
|
|
|
|
mockIsolate = MockIsolate();
|
|
|
|
mockPeer = MockPeer();
|
|
|
|
when(mockClient.getVM()).thenAnswer((_) => Future<MockVM>.value(mockVM));
|
2016-05-04 16:18:31 +00:00
|
|
|
when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]);
|
2018-09-12 06:29:29 +00:00
|
|
|
when(mockIsolate.loadRunnable()).thenAnswer((_) => Future<MockIsolate>.value(mockIsolate));
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer(
|
2017-12-19 21:13:57 +00:00
|
|
|
(Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
|
2016-03-29 20:49:34 +00:00
|
|
|
vmServiceConnectFunction = (String url) {
|
2018-09-12 06:29:29 +00:00
|
|
|
return Future<VMServiceClientConnection>.value(
|
|
|
|
VMServiceClientConnection(mockClient, mockPeer)
|
2016-03-29 20:49:34 +00:00
|
|
|
);
|
|
|
|
};
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await logSub.cancel();
|
2016-02-20 00:31:34 +00:00
|
|
|
restoreVmServiceConnectFunction();
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('connects to isolate paused at start', () async {
|
2017-05-10 22:16:45 +00:00
|
|
|
final List<String> connectionLog = <String>[];
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockPeer.sendRequest('streamListen', any)).thenAnswer((Invocation invocation) {
|
2017-05-10 22:16:45 +00:00
|
|
|
connectionLog.add('streamListen');
|
|
|
|
return null;
|
|
|
|
});
|
2018-09-12 06:29:29 +00:00
|
|
|
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
|
2017-05-10 22:16:45 +00:00
|
|
|
connectionLog.add('resume');
|
2018-10-16 20:03:06 +00:00
|
|
|
return Future<dynamic>.value(null);
|
2017-05-10 22:16:45 +00:00
|
|
|
});
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
|
2017-05-10 22:16:45 +00:00
|
|
|
connectionLog.add('onExtensionAdded');
|
2018-09-12 06:29:29 +00:00
|
|
|
return Stream<String>.fromIterable(<String>['ext.flutter.driver']);
|
2017-05-10 22:16:45 +00:00
|
|
|
});
|
2016-02-08 17:30:20 +00:00
|
|
|
|
2017-03-04 02:31:21 +00:00
|
|
|
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(driver, isNotNull);
|
|
|
|
expectLogContains('Isolate is paused at start');
|
2017-05-10 22:16:45 +00:00
|
|
|
expect(connectionLog, <String>['streamListen', 'onExtensionAdded', 'resume']);
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('connects to isolate paused mid-flight', () async {
|
2018-09-12 06:29:29 +00:00
|
|
|
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
|
2018-10-16 20:03:06 +00:00
|
|
|
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
|
2016-02-08 17:30:20 +00:00
|
|
|
|
2017-03-04 02:31:21 +00:00
|
|
|
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(driver, isNotNull);
|
|
|
|
expectLogContains('Isolate is paused mid-flight');
|
|
|
|
});
|
|
|
|
|
|
|
|
// This test simulates a situation when we believe that the isolate is
|
|
|
|
// currently paused, but something else (e.g. a debugger) resumes it before
|
|
|
|
// we do. There's no need to fail as we should be able to drive the app
|
|
|
|
// just fine.
|
|
|
|
test('connects despite losing the race to resume isolate', () async {
|
2018-09-12 06:29:29 +00:00
|
|
|
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
|
2016-02-08 17:30:20 +00:00
|
|
|
// This needs to be wrapped in a closure to not be considered uncaught
|
|
|
|
// by package:test
|
2018-10-16 20:03:06 +00:00
|
|
|
return Future<dynamic>.error(rpc.RpcException(101, ''));
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
2017-03-04 02:31:21 +00:00
|
|
|
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(driver, isNotNull);
|
|
|
|
expectLogContains('Attempted to resume an already resumed isolate');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('connects to unpaused isolate', () async {
|
2018-09-12 06:29:29 +00:00
|
|
|
when(mockIsolate.pauseEvent).thenReturn(MockVMResumeEvent());
|
2017-03-04 02:31:21 +00:00
|
|
|
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(driver, isNotNull);
|
|
|
|
expectLogContains('Isolate is not paused. Assuming application is ready.');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('FlutterDriver', () {
|
|
|
|
MockVMServiceClient mockClient;
|
2016-03-29 20:49:34 +00:00
|
|
|
MockPeer mockPeer;
|
2016-02-08 17:30:20 +00:00
|
|
|
MockIsolate mockIsolate;
|
|
|
|
FlutterDriver driver;
|
|
|
|
|
|
|
|
setUp(() {
|
2018-09-12 06:29:29 +00:00
|
|
|
mockClient = MockVMServiceClient();
|
|
|
|
mockPeer = MockPeer();
|
|
|
|
mockIsolate = MockIsolate();
|
|
|
|
driver = FlutterDriver.connectedTo(mockClient, mockPeer, mockIsolate);
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('checks the health of the driver extension', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer(
|
2017-12-19 21:13:57 +00:00
|
|
|
(Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
|
2017-03-04 02:31:21 +00:00
|
|
|
final Health result = await driver.checkHealth();
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(result.status, HealthStatus.ok);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('closes connection', () async {
|
2018-10-16 20:03:06 +00:00
|
|
|
when(mockClient.close()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
|
2016-02-08 17:30:20 +00:00
|
|
|
await driver.close();
|
|
|
|
});
|
|
|
|
|
2016-04-15 23:57:35 +00:00
|
|
|
group('ByValueKey', () {
|
2016-02-08 17:30:20 +00:00
|
|
|
test('restricts value types', () async {
|
2016-04-15 23:57:35 +00:00
|
|
|
expect(() => find.byValueKey(null),
|
2018-08-15 03:33:58 +00:00
|
|
|
throwsA(isInstanceOf<DriverError>()));
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('finds by ValueKey', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2016-05-04 16:18:31 +00:00
|
|
|
expect(i.positionalArguments[1], <String, String>{
|
2016-04-15 23:57:35 +00:00
|
|
|
'command': 'tap',
|
2017-03-10 00:31:48 +00:00
|
|
|
'timeout': _kSerializedTestTimeout,
|
2016-04-15 23:57:35 +00:00
|
|
|
'finderType': 'ByValueKey',
|
2016-02-08 17:30:20 +00:00
|
|
|
'keyValueString': 'foo',
|
2019-03-01 07:17:55 +00:00
|
|
|
'keyValueType': 'String',
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
return makeMockResponse(<String, dynamic>{});
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
2017-03-10 00:31:48 +00:00
|
|
|
await driver.tap(find.byValueKey('foo'), timeout: _kTestTimeout);
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-19 03:32:03 +00:00
|
|
|
group('BySemanticsLabel', () {
|
|
|
|
test('finds by Semantic label using String', () async {
|
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
|
|
|
expect(i.positionalArguments[1], <String, String>{
|
|
|
|
'command': 'tap',
|
|
|
|
'timeout': _kSerializedTestTimeout,
|
|
|
|
'finderType': 'BySemanticsLabel',
|
|
|
|
'label': 'foo',
|
|
|
|
});
|
|
|
|
return makeMockResponse(<String, dynamic>{});
|
|
|
|
});
|
|
|
|
await driver.tap(find.bySemanticsLabel('foo'), timeout: _kTestTimeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('finds by Semantic label using RegExp', () async {
|
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
|
|
|
expect(i.positionalArguments[1], <String, String>{
|
|
|
|
'command': 'tap',
|
|
|
|
'timeout': _kSerializedTestTimeout,
|
|
|
|
'finderType': 'BySemanticsLabel',
|
|
|
|
'label': '^foo',
|
|
|
|
'isRegExp': 'true',
|
|
|
|
});
|
|
|
|
return makeMockResponse(<String, dynamic>{});
|
|
|
|
});
|
|
|
|
await driver.tap(find.bySemanticsLabel(RegExp('^foo')), timeout: _kTestTimeout);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-08 17:30:20 +00:00
|
|
|
group('tap', () {
|
|
|
|
test('requires a target reference', () async {
|
2018-08-15 03:33:58 +00:00
|
|
|
expect(driver.tap(null), throwsA(isInstanceOf<DriverError>()));
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('sends the tap command', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2016-03-12 08:32:34 +00:00
|
|
|
expect(i.positionalArguments[1], <String, dynamic>{
|
2016-03-01 23:15:01 +00:00
|
|
|
'command': 'tap',
|
2017-03-10 00:31:48 +00:00
|
|
|
'timeout': _kSerializedTestTimeout,
|
2016-04-15 23:57:35 +00:00
|
|
|
'finderType': 'ByText',
|
|
|
|
'text': 'foo',
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
return makeMockResponse(<String, dynamic>{});
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
2017-03-10 00:31:48 +00:00
|
|
|
await driver.tap(find.text('foo'), timeout: _kTestTimeout);
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('getText', () {
|
|
|
|
test('requires a target reference', () async {
|
2018-08-15 03:33:58 +00:00
|
|
|
expect(driver.getText(null), throwsA(isInstanceOf<DriverError>()));
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('sends the getText command', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2016-03-12 08:32:34 +00:00
|
|
|
expect(i.positionalArguments[1], <String, dynamic>{
|
2016-03-01 23:15:01 +00:00
|
|
|
'command': 'get_text',
|
2017-03-10 00:31:48 +00:00
|
|
|
'timeout': _kSerializedTestTimeout,
|
2016-04-15 23:57:35 +00:00
|
|
|
'finderType': 'ByValueKey',
|
|
|
|
'keyValueString': '123',
|
2019-03-01 07:17:55 +00:00
|
|
|
'keyValueType': 'int',
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
return makeMockResponse(<String, String>{
|
2019-03-01 07:17:55 +00:00
|
|
|
'text': 'hello',
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-10 00:31:48 +00:00
|
|
|
final String result = await driver.getText(find.byValueKey(123), timeout: _kTestTimeout);
|
2016-02-08 17:30:20 +00:00
|
|
|
expect(result, 'hello');
|
|
|
|
});
|
|
|
|
});
|
2016-02-24 01:44:09 +00:00
|
|
|
|
|
|
|
group('waitFor', () {
|
2016-04-19 16:49:22 +00:00
|
|
|
test('requires a target reference', () async {
|
2018-08-15 03:33:58 +00:00
|
|
|
expect(driver.waitFor(null), throwsA(isInstanceOf<DriverError>()));
|
2016-02-24 01:44:09 +00:00
|
|
|
});
|
|
|
|
|
2016-04-19 16:49:22 +00:00
|
|
|
test('sends the waitFor command', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2016-04-19 16:49:22 +00:00
|
|
|
expect(i.positionalArguments[1], <String, dynamic>{
|
|
|
|
'command': 'waitFor',
|
|
|
|
'finderType': 'ByTooltipMessage',
|
|
|
|
'text': 'foo',
|
2017-03-10 00:31:48 +00:00
|
|
|
'timeout': _kSerializedTestTimeout,
|
2016-04-19 16:49:22 +00:00
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
return makeMockResponse(<String, dynamic>{});
|
2016-02-24 01:44:09 +00:00
|
|
|
});
|
2017-03-10 00:31:48 +00:00
|
|
|
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
|
2016-02-24 01:44:09 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-29 20:49:34 +00:00
|
|
|
|
2017-02-28 23:58:28 +00:00
|
|
|
group('waitUntilNoTransientCallbacks', () {
|
|
|
|
test('sends the waitUntilNoTransientCallbacks command', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2017-02-28 23:58:28 +00:00
|
|
|
expect(i.positionalArguments[1], <String, dynamic>{
|
|
|
|
'command': 'waitUntilNoTransientCallbacks',
|
2017-03-10 00:31:48 +00:00
|
|
|
'timeout': _kSerializedTestTimeout,
|
2017-02-28 23:58:28 +00:00
|
|
|
});
|
|
|
|
return makeMockResponse(<String, dynamic>{});
|
|
|
|
});
|
2017-03-10 00:31:48 +00:00
|
|
|
await driver.waitUntilNoTransientCallbacks(timeout: _kTestTimeout);
|
2017-02-28 23:58:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-22 23:08:09 +00:00
|
|
|
group('clearTimeline', () {
|
|
|
|
test('clears timeline', () async {
|
|
|
|
bool clearWasCalled = false;
|
|
|
|
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
|
2019-03-07 20:09:28 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
|
|
|
clearWasCalled = true;
|
|
|
|
return null;
|
|
|
|
});
|
2017-11-22 23:08:09 +00:00
|
|
|
await driver.clearTimeline();
|
|
|
|
expect(clearWasCalled, isTrue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-29 20:49:34 +00:00
|
|
|
group('traceAction', () {
|
2017-11-22 23:08:09 +00:00
|
|
|
List<String> log;
|
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
log = <String>[];
|
|
|
|
|
|
|
|
when(mockPeer.sendRequest('_clearVMTimeline', argThat(equals(<String, dynamic>{}))))
|
2019-03-07 20:09:28 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
|
|
|
log.add('clear');
|
|
|
|
return null;
|
|
|
|
});
|
2016-03-29 20:49:34 +00:00
|
|
|
|
2016-05-04 16:18:31 +00:00
|
|
|
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[all]'}))))
|
2019-03-07 20:09:28 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
|
|
|
log.add('startTracing');
|
|
|
|
return null;
|
|
|
|
});
|
2016-03-29 20:49:34 +00:00
|
|
|
|
2016-05-04 16:18:31 +00:00
|
|
|
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'}))))
|
2019-03-07 20:09:28 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
|
|
|
log.add('stopTracing');
|
|
|
|
return null;
|
|
|
|
});
|
2016-03-29 20:49:34 +00:00
|
|
|
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async {
|
2017-11-22 23:08:09 +00:00
|
|
|
log.add('download');
|
2019-03-22 23:02:21 +00:00
|
|
|
return <String, dynamic>{
|
2016-05-04 16:18:31 +00:00
|
|
|
'traceEvents': <dynamic>[
|
|
|
|
<String, String>{
|
2019-03-01 07:17:55 +00:00
|
|
|
'name': 'test event',
|
|
|
|
},
|
2016-04-05 00:07:16 +00:00
|
|
|
],
|
2016-03-29 20:49:34 +00:00
|
|
|
};
|
|
|
|
});
|
2017-11-22 23:08:09 +00:00
|
|
|
});
|
2016-03-29 20:49:34 +00:00
|
|
|
|
2017-11-22 23:08:09 +00:00
|
|
|
test('without clearing timeline', () async {
|
2018-08-28 18:22:57 +00:00
|
|
|
final Timeline timeline = await driver.traceAction(() async {
|
2017-11-22 23:08:09 +00:00
|
|
|
log.add('action');
|
|
|
|
}, retainPriorEvents: true);
|
|
|
|
|
|
|
|
expect(log, const <String>[
|
|
|
|
'startTracing',
|
|
|
|
'action',
|
|
|
|
'stopTracing',
|
|
|
|
'download',
|
|
|
|
]);
|
|
|
|
expect(timeline.events.single.name, 'test event');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('with clearing timeline', () async {
|
2018-08-28 18:22:57 +00:00
|
|
|
final Timeline timeline = await driver.traceAction(() async {
|
2017-11-22 23:08:09 +00:00
|
|
|
log.add('action');
|
2016-03-29 20:49:34 +00:00
|
|
|
});
|
|
|
|
|
2017-11-22 23:08:09 +00:00
|
|
|
expect(log, const <String>[
|
|
|
|
'clear',
|
|
|
|
'startTracing',
|
|
|
|
'action',
|
|
|
|
'stopTracing',
|
|
|
|
'download',
|
|
|
|
]);
|
2016-04-05 00:07:16 +00:00
|
|
|
expect(timeline.events.single.name, 'test event');
|
2016-03-29 20:49:34 +00:00
|
|
|
});
|
|
|
|
});
|
2016-05-04 00:37:10 +00:00
|
|
|
|
2016-05-10 00:00:49 +00:00
|
|
|
group('traceAction with timeline streams', () {
|
|
|
|
test('specify non-default timeline streams', () async {
|
2016-05-04 00:37:10 +00:00
|
|
|
bool actionCalled = false;
|
|
|
|
bool startTracingCalled = false;
|
|
|
|
bool stopTracingCalled = false;
|
|
|
|
|
2016-05-04 16:18:31 +00:00
|
|
|
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[Dart, GC, Compiler]'}))))
|
2017-12-19 21:13:57 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
2016-05-04 00:37:10 +00:00
|
|
|
startTracingCalled = true;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2016-05-04 16:18:31 +00:00
|
|
|
when(mockPeer.sendRequest('_setVMTimelineFlags', argThat(equals(<String, dynamic>{'recordedStreams': '[]'}))))
|
2017-12-19 21:13:57 +00:00
|
|
|
.thenAnswer((Invocation invocation) async {
|
2016-05-04 00:37:10 +00:00
|
|
|
stopTracingCalled = true;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2017-12-19 21:13:57 +00:00
|
|
|
when(mockPeer.sendRequest('_getVMTimeline')).thenAnswer((Invocation invocation) async {
|
2019-03-22 23:02:21 +00:00
|
|
|
return <String, dynamic>{
|
2016-05-04 16:18:31 +00:00
|
|
|
'traceEvents': <dynamic>[
|
|
|
|
<String, String>{
|
2019-03-01 07:17:55 +00:00
|
|
|
'name': 'test event',
|
|
|
|
},
|
2016-05-04 00:37:10 +00:00
|
|
|
],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-08-28 18:22:57 +00:00
|
|
|
final Timeline timeline = await driver.traceAction(() async {
|
2016-05-04 00:37:10 +00:00
|
|
|
actionCalled = true;
|
|
|
|
},
|
2016-05-10 00:00:49 +00:00
|
|
|
streams: const <TimelineStream>[
|
|
|
|
TimelineStream.dart,
|
|
|
|
TimelineStream.gc,
|
2019-03-01 07:17:55 +00:00
|
|
|
TimelineStream.compiler,
|
2017-11-22 23:08:09 +00:00
|
|
|
],
|
|
|
|
retainPriorEvents: true);
|
2016-05-04 00:37:10 +00:00
|
|
|
|
|
|
|
expect(actionCalled, isTrue);
|
|
|
|
expect(startTracingCalled, isTrue);
|
|
|
|
expect(stopTracingCalled, isTrue);
|
|
|
|
expect(timeline.events.single.name, 'test event');
|
|
|
|
});
|
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
|
|
|
|
group('sendCommand error conditions', () {
|
|
|
|
test('local timeout', () async {
|
2019-01-19 08:31:05 +00:00
|
|
|
final List<String> log = <String>[];
|
|
|
|
final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString()));
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2019-01-19 08:31:05 +00:00
|
|
|
// completer never completed to trigger timeout
|
2018-09-12 06:29:29 +00:00
|
|
|
return Completer<Map<String, dynamic>>().future;
|
2017-01-09 22:57:25 +00:00
|
|
|
});
|
2019-01-19 08:31:05 +00:00
|
|
|
FakeAsync().run((FakeAsync time) {
|
|
|
|
driver.waitFor(find.byTooltip('foo'));
|
|
|
|
expect(log, <String>[]);
|
|
|
|
time.elapse(const Duration(hours: 1));
|
|
|
|
});
|
|
|
|
expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']);
|
|
|
|
await logSub.cancel();
|
2017-01-09 22:57:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('remote error', () async {
|
2018-06-21 23:23:47 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
2017-01-09 22:57:25 +00:00
|
|
|
return makeMockResponse(<String, dynamic>{
|
2019-03-01 07:17:55 +00:00
|
|
|
'message': 'This is a failure',
|
2017-01-09 22:57:25 +00:00
|
|
|
}, isError: true);
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
await driver.waitFor(find.byTooltip('foo'));
|
|
|
|
fail('expected an exception');
|
2018-02-05 21:20:21 +00:00
|
|
|
} catch (error) {
|
2017-01-09 22:57:25 +00:00
|
|
|
expect(error is DriverError, isTrue);
|
|
|
|
expect(error.message, 'Error in Flutter application: {message: This is a failure}');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-15 01:15:00 +00:00
|
|
|
|
|
|
|
group('FlutterDriver with custom timeout', () {
|
|
|
|
MockVMServiceClient mockClient;
|
|
|
|
MockPeer mockPeer;
|
|
|
|
MockIsolate mockIsolate;
|
|
|
|
FlutterDriver driver;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockClient = MockVMServiceClient();
|
|
|
|
mockPeer = MockPeer();
|
|
|
|
mockIsolate = MockIsolate();
|
2019-01-19 08:31:05 +00:00
|
|
|
driver = FlutterDriver.connectedTo(mockClient, mockPeer, mockIsolate);
|
2018-11-15 01:15:00 +00:00
|
|
|
});
|
|
|
|
|
2019-01-19 08:31:05 +00:00
|
|
|
test('GetHealth has no default timeout', () async {
|
2018-11-15 01:15:00 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
|
|
|
expect(i.positionalArguments[1], <String, String>{
|
|
|
|
'command': 'get_health',
|
|
|
|
});
|
|
|
|
return makeMockResponse(<String, dynamic>{'status': 'ok'});
|
|
|
|
});
|
|
|
|
await driver.checkHealth();
|
|
|
|
});
|
|
|
|
|
2019-01-19 08:31:05 +00:00
|
|
|
test('does not interfere with explicit timeouts', () async {
|
2018-11-15 01:15:00 +00:00
|
|
|
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
|
|
|
expect(i.positionalArguments[1], <String, String>{
|
|
|
|
'command': 'get_health',
|
|
|
|
'timeout': _kSerializedTestTimeout,
|
|
|
|
});
|
|
|
|
return makeMockResponse(<String, dynamic>{'status': 'ok'});
|
|
|
|
});
|
|
|
|
await driver.checkHealth(timeout: _kTestTimeout);
|
|
|
|
});
|
|
|
|
});
|
2017-01-09 22:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> makeMockResponse(
|
2019-02-21 08:27:07 +00:00
|
|
|
Map<String, dynamic> response, {
|
|
|
|
bool isError = false,
|
|
|
|
}) {
|
2018-09-12 06:29:29 +00:00
|
|
|
return Future<Map<String, dynamic>>.value(<String, dynamic>{
|
2017-01-09 22:57:25 +00:00
|
|
|
'isError': isError,
|
2019-03-01 07:17:55 +00:00
|
|
|
'response': response,
|
2016-02-08 17:30:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockVMServiceClient extends Mock implements VMServiceClient { }
|
|
|
|
|
|
|
|
class MockVM extends Mock implements VM { }
|
|
|
|
|
|
|
|
class MockIsolate extends Mock implements VMRunnableIsolate { }
|
|
|
|
|
|
|
|
class MockVMPauseStartEvent extends Mock implements VMPauseStartEvent { }
|
|
|
|
|
|
|
|
class MockVMPauseBreakpointEvent extends Mock implements VMPauseBreakpointEvent { }
|
|
|
|
|
|
|
|
class MockVMResumeEvent extends Mock implements VMResumeEvent { }
|
2016-03-29 20:49:34 +00:00
|
|
|
|
|
|
|
class MockPeer extends Mock implements rpc.Peer { }
|