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

* Extract some of startApp into a reusable method * Get basic attach --machine working * Attach --machine tweaks Move validation to validate method and create daemon early so we get the startup event before trying to get a connection. * Bump daemon version so we know whether it's valid to flutter attach * Tweak output text * Swap package imports for relative * Review tweaks (naming, formatting, typedefs) * Separate arguments from process spawning This will make calling attach easier * Add a basic test for flutter attach --machine * Fix crash if port unforward modifies the list of forwarded ports * Add a no-op port forwarder for flutter-tester * Switch to using BasicProject instead of our own inline code * Fix expectation in test now we have a portForwarder * Remove stale TODO (this is done) * Tweak formatting * Change some Completers to void to fix Dart 2 issues
93 lines
2.8 KiB
Dart
93 lines
2.8 KiB
Dart
// Copyright 2017 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';
|
|
import 'package:flutter_tools/src/device.dart';
|
|
import 'package:flutter_tools/src/resident_runner.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'src/context.dart';
|
|
|
|
class TestRunner extends ResidentRunner {
|
|
TestRunner(List<FlutterDevice> devices)
|
|
: super(devices);
|
|
|
|
bool hasHelpBeenPrinted = false;
|
|
String receivedCommand;
|
|
|
|
@override
|
|
Future<Null> cleanupAfterSignal() => null;
|
|
|
|
@override
|
|
Future<Null> cleanupAtFinish() => null;
|
|
|
|
@override
|
|
Future<Null> handleTerminalCommand(String code) async {
|
|
receivedCommand = code;
|
|
}
|
|
|
|
@override
|
|
void printHelp({ bool details }) {
|
|
hasHelpBeenPrinted = true;
|
|
}
|
|
|
|
@override
|
|
Future<int> run({
|
|
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
|
Completer<void> appStartedCompleter,
|
|
String route,
|
|
bool shouldBuild = true,
|
|
}) => null;
|
|
}
|
|
|
|
void main() {
|
|
TestRunner createTestRunner() {
|
|
// TODO(jacobr): make these tests run with `previewDart2: true` and
|
|
// `trackWidgetCreation: true` as well as the default flags.
|
|
// Currently the TestRunner is not properly configured to be able to run
|
|
// with `previewDart2: true` due to missing resources.
|
|
return new TestRunner(
|
|
<FlutterDevice>[new FlutterDevice(
|
|
new MockDevice(),
|
|
previewDart2: false,
|
|
trackWidgetCreation: false,
|
|
)],
|
|
);
|
|
}
|
|
|
|
group('keyboard input handling', () {
|
|
testUsingContext('single help character', () async {
|
|
final TestRunner testRunner = createTestRunner();
|
|
expect(testRunner.hasHelpBeenPrinted, isFalse);
|
|
await testRunner.processTerminalInput('h');
|
|
expect(testRunner.hasHelpBeenPrinted, isTrue);
|
|
});
|
|
testUsingContext('help character surrounded with newlines', () async {
|
|
final TestRunner testRunner = createTestRunner();
|
|
expect(testRunner.hasHelpBeenPrinted, isFalse);
|
|
await testRunner.processTerminalInput('\nh\n');
|
|
expect(testRunner.hasHelpBeenPrinted, isTrue);
|
|
});
|
|
testUsingContext('reload character with trailing newline', () async {
|
|
final TestRunner testRunner = createTestRunner();
|
|
expect(testRunner.receivedCommand, isNull);
|
|
await testRunner.processTerminalInput('r\n');
|
|
expect(testRunner.receivedCommand, equals('r'));
|
|
});
|
|
testUsingContext('newlines', () async {
|
|
final TestRunner testRunner = createTestRunner();
|
|
expect(testRunner.receivedCommand, isNull);
|
|
await testRunner.processTerminalInput('\n\n');
|
|
expect(testRunner.receivedCommand, equals(''));
|
|
});
|
|
});
|
|
}
|
|
|
|
class MockDevice extends Mock implements Device {
|
|
MockDevice() {
|
|
when(isSupported()).thenReturn(true);
|
|
}
|
|
}
|