[flutter_driver] Fix browser check (#54741)

This commit is contained in:
Pierre-Louis 2020-04-15 17:40:03 +00:00 committed by GitHub
parent b6262e7c1c
commit 21588019bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 28 deletions

View File

@ -167,7 +167,7 @@ abstract class FlutterDriver {
/// ///
/// * [VMServiceFlutterDriver], which uses vmservice to implement. /// * [VMServiceFlutterDriver], which uses vmservice to implement.
/// * [WebFlutterDriver], which uses webdriver to implement. /// * [WebFlutterDriver], which uses webdriver to implement.
Future<Map<String, dynamic>> sendCommand(Command command) => throw UnimplementedError(); Future<Map<String, dynamic>> sendCommand(Command command) async => throw UnimplementedError();
/// Checks the status of the Flutter Driver extension. /// Checks the status of the Flutter Driver extension.
Future<Health> checkHealth({ Duration timeout }) async { Future<Health> checkHealth({ Duration timeout }) async {
@ -560,7 +560,7 @@ abstract class FlutterDriver {
/// In practice, sometimes the device gets really busy for a while and /// In practice, sometimes the device gets really busy for a while and
/// even two seconds isn't enough, which means that this is still racy /// even two seconds isn't enough, which means that this is still racy
/// and a source of flakes. /// and a source of flakes.
Future<List<int>> screenshot() { Future<List<int>> screenshot() async {
throw UnimplementedError(); throw UnimplementedError();
} }
@ -585,7 +585,7 @@ abstract class FlutterDriver {
/// [getFlagList]: https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#getflaglist /// [getFlagList]: https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#getflaglist
/// ///
/// Throws [UnimplementedError] on [WebFlutterDriver] instances. /// Throws [UnimplementedError] on [WebFlutterDriver] instances.
Future<List<Map<String, dynamic>>> getVmFlags() { Future<List<Map<String, dynamic>>> getVmFlags() async {
throw UnimplementedError(); throw UnimplementedError();
} }
/// Starts recording performance traces. /// Starts recording performance traces.
@ -598,7 +598,7 @@ abstract class FlutterDriver {
Future<void> startTracing({ Future<void> startTracing({
List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all], List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
Duration timeout = kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) { }) async {
throw UnimplementedError(); throw UnimplementedError();
} }
@ -611,7 +611,7 @@ abstract class FlutterDriver {
/// For [WebFlutterDriver], this is only supported for Chrome. /// For [WebFlutterDriver], this is only supported for Chrome.
Future<Timeline> stopTracingAndDownloadTimeline({ Future<Timeline> stopTracingAndDownloadTimeline({
Duration timeout = kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) { }) async {
throw UnimplementedError(); throw UnimplementedError();
} }
/// Runs [action] and outputs a performance trace for it. /// Runs [action] and outputs a performance trace for it.
@ -637,7 +637,7 @@ abstract class FlutterDriver {
Future<dynamic> action(), { Future<dynamic> action(), {
List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all], List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
bool retainPriorEvents = false, bool retainPriorEvents = false,
}) { }) async {
throw UnimplementedError(); throw UnimplementedError();
} }
@ -650,7 +650,7 @@ abstract class FlutterDriver {
/// For [WebFlutterDriver], this is only supported for Chrome. /// For [WebFlutterDriver], this is only supported for Chrome.
Future<void> clearTimeline({ Future<void> clearTimeline({
Duration timeout = kUnusuallyLongTimeout, Duration timeout = kUnusuallyLongTimeout,
}) { }) async {
throw UnimplementedError(); throw UnimplementedError();
} }
/// [action] will be executed with the frame sync mechanism disabled. /// [action] will be executed with the frame sync mechanism disabled.
@ -683,14 +683,14 @@ abstract class FlutterDriver {
/// Force a garbage collection run in the VM. /// Force a garbage collection run in the VM.
/// ///
/// Throws [UnimplementedError] on [WebFlutterDriver] instances. /// Throws [UnimplementedError] on [WebFlutterDriver] instances.
Future<void> forceGC() { Future<void> forceGC() async {
throw UnimplementedError(); throw UnimplementedError();
} }
/// Closes the underlying connection to the VM service. /// Closes the underlying connection to the VM service.
/// ///
/// Returns a [Future] that fires once the connection has been closed. /// Returns a [Future] that fires once the connection has been closed.
Future<void> close() { Future<void> close() async {
throw UnimplementedError(); throw UnimplementedError();
} }
} }

View File

@ -154,7 +154,7 @@ class WebFlutterDriver extends FlutterDriver {
/// Checks whether browser supports Timeline related operations /// Checks whether browser supports Timeline related operations
void _checkBrowserSupportsTimeline() { void _checkBrowserSupportsTimeline() {
if (_connection.supportsTimelineAction) { if (!_connection.supportsTimelineAction) {
throw UnsupportedError('Timeline action is not supported by current testing browser'); throw UnsupportedError('Timeline action is not supported by current testing browser');
} }
} }
@ -164,22 +164,12 @@ class WebFlutterDriver extends FlutterDriver {
class FlutterWebConnection { class FlutterWebConnection {
/// Creates a FlutterWebConnection with WebDriver /// Creates a FlutterWebConnection with WebDriver
/// and whether the WebDriver supports timeline action /// and whether the WebDriver supports timeline action
FlutterWebConnection(this._driver, this._supportsTimelineAction); FlutterWebConnection(this._driver, this.supportsTimelineAction);
final async_io.WebDriver _driver; final async_io.WebDriver _driver;
bool _supportsTimelineAction;
/// Whether the connected WebDriver supports timeline action for Flutter Web Driver /// Whether the connected WebDriver supports timeline action for Flutter Web Driver
// ignore: unnecessary_getters_setters bool supportsTimelineAction;
bool get supportsTimelineAction => _supportsTimelineAction;
/// Setter for _supportsTimelineAction
@visibleForTesting
// ignore: unnecessary_getters_setters
set supportsTimelineAction(bool value) {
_supportsTimelineAction = value;
}
/// Starts WebDriver with the given [settings] and /// Starts WebDriver with the given [settings] and
/// establishes the connection to Flutter Web application. /// establishes the connection to Flutter Web application.

View File

@ -693,7 +693,7 @@ void main() {
setUp(() { setUp(() {
mockConnection = MockFlutterWebConnection(); mockConnection = MockFlutterWebConnection();
mockConnection.supportsTimelineAction = true; when(mockConnection.supportsTimelineAction).thenReturn(true);
driver = WebFlutterDriver.connectedTo(mockConnection); driver = WebFlutterDriver.connectedTo(mockConnection);
}); });
@ -1033,19 +1033,19 @@ void main() {
setUp(() { setUp(() {
mockConnection = MockFlutterWebConnection(); mockConnection = MockFlutterWebConnection();
mockConnection.supportsTimelineAction = false; when(mockConnection.supportsTimelineAction).thenReturn(false);
driver = WebFlutterDriver.connectedTo(mockConnection); driver = WebFlutterDriver.connectedTo(mockConnection);
}); });
test('tracing', () async { test('tracing', () async {
expect(driver.traceAction(() async { return Future<dynamic>.value(); }), expect(driver.traceAction(() async { return Future<dynamic>.value(); }),
throwsA(isA<UnimplementedError>())); throwsA(isA<UnsupportedError>()));
expect(driver.startTracing(), expect(driver.startTracing(),
throwsA(isA<UnimplementedError>())); throwsA(isA<UnsupportedError>()));
expect(driver.stopTracingAndDownloadTimeline(), expect(driver.stopTracingAndDownloadTimeline(),
throwsA(isA<UnimplementedError>())); throwsA(isA<UnsupportedError>()));
expect(driver.clearTimeline(), expect(driver.clearTimeline(),
throwsA(isA<UnimplementedError>())); throwsA(isA<UnsupportedError>()));
}); });
}); });
} }