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

* Moved the default BinaryMessenger instance to ServicesBinding
This reverts commit 821602aef3
.
* Added assertion in defaultBinaryMessenger. Also fixed the devicelab tests.
131 lines
5.4 KiB
Dart
131 lines
5.4 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 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart' show TestWidgetsFlutterBinding;
|
|
import '../flutter_test_alternative.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('TextInputConfiguration', () {
|
|
test('sets expected defaults', () {
|
|
const TextInputConfiguration configuration = TextInputConfiguration();
|
|
expect(configuration.inputType, TextInputType.text);
|
|
expect(configuration.obscureText, false);
|
|
expect(configuration.autocorrect, true);
|
|
expect(configuration.actionLabel, null);
|
|
expect(configuration.textCapitalization, TextCapitalization.none);
|
|
expect(configuration.keyboardAppearance, Brightness.light);
|
|
});
|
|
|
|
test('text serializes to JSON', () async {
|
|
const TextInputConfiguration configuration = TextInputConfiguration(
|
|
inputType: TextInputType.text,
|
|
obscureText: true,
|
|
autocorrect: false,
|
|
actionLabel: 'xyzzy',
|
|
);
|
|
final Map<String, dynamic> json = configuration.toJson();
|
|
expect(json['inputType'], <String, dynamic>{
|
|
'name': 'TextInputType.text',
|
|
'signed': null,
|
|
'decimal': null,
|
|
});
|
|
expect(json['obscureText'], true);
|
|
expect(json['autocorrect'], false);
|
|
expect(json['actionLabel'], 'xyzzy');
|
|
});
|
|
|
|
test('number serializes to JSON', () async {
|
|
const TextInputConfiguration configuration = TextInputConfiguration(
|
|
inputType: TextInputType.numberWithOptions(decimal: true),
|
|
obscureText: true,
|
|
autocorrect: false,
|
|
actionLabel: 'xyzzy',
|
|
);
|
|
final Map<String, dynamic> json = configuration.toJson();
|
|
expect(json['inputType'], <String, dynamic>{
|
|
'name': 'TextInputType.number',
|
|
'signed': false,
|
|
'decimal': true,
|
|
});
|
|
expect(json['obscureText'], true);
|
|
expect(json['autocorrect'], false);
|
|
expect(json['actionLabel'], 'xyzzy');
|
|
});
|
|
|
|
test('basic structure', () async {
|
|
const TextInputType text = TextInputType.text;
|
|
const TextInputType number = TextInputType.number;
|
|
const TextInputType number2 = TextInputType.numberWithOptions();
|
|
const TextInputType signed = TextInputType.numberWithOptions(signed: true);
|
|
const TextInputType signed2 = TextInputType.numberWithOptions(signed: true);
|
|
const TextInputType decimal = TextInputType.numberWithOptions(decimal: true);
|
|
const TextInputType signedDecimal =
|
|
TextInputType.numberWithOptions(signed: true, decimal: true);
|
|
|
|
expect(text.toString(), 'TextInputType(name: TextInputType.text, signed: null, decimal: null)');
|
|
expect(number.toString(), 'TextInputType(name: TextInputType.number, signed: false, decimal: false)');
|
|
expect(signed.toString(), 'TextInputType(name: TextInputType.number, signed: true, decimal: false)');
|
|
expect(decimal.toString(), 'TextInputType(name: TextInputType.number, signed: false, decimal: true)');
|
|
expect(signedDecimal.toString(), 'TextInputType(name: TextInputType.number, signed: true, decimal: true)');
|
|
|
|
expect(text == number, false);
|
|
expect(number == number2, true);
|
|
expect(number == signed, false);
|
|
expect(signed == signed2, true);
|
|
expect(signed == decimal, false);
|
|
expect(signed == signedDecimal, false);
|
|
expect(decimal == signedDecimal, false);
|
|
|
|
expect(text.hashCode == number.hashCode, false);
|
|
expect(number.hashCode == number2.hashCode, true);
|
|
expect(number.hashCode == signed.hashCode, false);
|
|
expect(signed.hashCode == signed2.hashCode, true);
|
|
expect(signed.hashCode == decimal.hashCode, false);
|
|
expect(signed.hashCode == signedDecimal.hashCode, false);
|
|
expect(decimal.hashCode == signedDecimal.hashCode, false);
|
|
});
|
|
|
|
test('The framework TextInputConnection closes when the platform loses its input connection', () async {
|
|
// Assemble a TextInputConnection so we can verify its change in state.
|
|
final TextInputClient client = NoOpTextInputClient();
|
|
const TextInputConfiguration configuration = TextInputConfiguration();
|
|
final TextInputConnection textInputConnection = TextInput.attach(client, configuration);
|
|
|
|
// Verify that TextInputConnection think its attached to a client. This is
|
|
// an intermediate verification of expected state.
|
|
expect(textInputConnection.attached, true);
|
|
|
|
// Pretend that the platform has lost its input connection.
|
|
final ByteData messageBytes = const JSONMessageCodec().encodeMessage(
|
|
<String, dynamic>{
|
|
'args': <dynamic>[1],
|
|
'method': 'TextInputClient.onConnectionClosed',
|
|
}
|
|
);
|
|
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
|
'flutter/textinput',
|
|
messageBytes,
|
|
(ByteData _) {},
|
|
);
|
|
|
|
// Verify that textInputConnection no longer think its attached to an input
|
|
// connection. This is the critical verification of this test.
|
|
expect(textInputConnection.attached, false);
|
|
});
|
|
});
|
|
}
|
|
|
|
class NoOpTextInputClient extends TextInputClient {
|
|
@override
|
|
void performAction(TextInputAction action) {}
|
|
|
|
@override
|
|
void updateEditingValue(TextEditingValue value) {}
|
|
|
|
@override
|
|
void updateFloatingCursor(RawFloatingCursorPoint point) {}
|
|
} |