[gen_keycodes] Remove nonexistent Web keys and improve their emulation (#87098)
This commit is contained in:
@@ -22,8 +22,10 @@ String readDataFile(String fileName) {
|
||||
return File(path.join(dataRoot, fileName)).readAsStringSync();
|
||||
}
|
||||
|
||||
final String testPhysicalData = path.join(dataRoot, 'physical_key_data.json');
|
||||
final String testLogicalData = path.join(dataRoot,'logical_key_data.json');
|
||||
final PhysicalKeyData physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(readDataFile('physical_key_data.json')) as Map<String, dynamic>);
|
||||
final LogicalKeyData logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(readDataFile('logical_key_data.json')) as Map<String, dynamic>);
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
@@ -45,14 +47,6 @@ void main() {
|
||||
}
|
||||
|
||||
test('Generate Keycodes for Android', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'android';
|
||||
final PlatformCodeGenerator codeGenerator = AndroidCodeGenerator(
|
||||
physicalData,
|
||||
@@ -67,14 +61,6 @@ void main() {
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('Generate Keycodes for macOS', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'macos';
|
||||
final PlatformCodeGenerator codeGenerator = MacOSCodeGenerator(
|
||||
physicalData,
|
||||
@@ -93,14 +79,6 @@ void main() {
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('Generate Keycodes for iOS', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'ios';
|
||||
final PlatformCodeGenerator codeGenerator = IOSCodeGenerator(
|
||||
physicalData,
|
||||
@@ -120,14 +98,6 @@ void main() {
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('Generate Keycodes for Windows', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'windows';
|
||||
final PlatformCodeGenerator codeGenerator = WindowsCodeGenerator(
|
||||
physicalData,
|
||||
@@ -143,14 +113,6 @@ void main() {
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('Generate Keycodes for Linux', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'gtk';
|
||||
final PlatformCodeGenerator codeGenerator = GtkCodeGenerator(
|
||||
physicalData,
|
||||
@@ -166,14 +128,6 @@ void main() {
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('Generate Keycodes for Web', () {
|
||||
PhysicalKeyData physicalData;
|
||||
LogicalKeyData logicalData;
|
||||
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(File(testPhysicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(File(testLogicalData).readAsStringSync()) as Map<String, dynamic>);
|
||||
|
||||
const String platform = 'web';
|
||||
final PlatformCodeGenerator codeGenerator = WebCodeGenerator(
|
||||
physicalData,
|
||||
@@ -188,4 +142,25 @@ void main() {
|
||||
expect(output, contains('kWebLogicalLocationMap'));
|
||||
checkCommonOutput(output);
|
||||
});
|
||||
test('LogicalKeyData', () async {
|
||||
final List<LogicalKeyEntry> entries = logicalData.entries.toList();
|
||||
|
||||
// Regression tests for https://github.com/flutter/flutter/pull/87098
|
||||
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.name == 'ShiftLeft'),
|
||||
isNot(-1));
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('ShiftLeft')),
|
||||
-1);
|
||||
// 'Shift' maps to both 'ShiftLeft' and 'ShiftRight', and should be resolved
|
||||
// by other ways.
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Shift')),
|
||||
-1);
|
||||
// Printable keys must not be added with Web key of their names.
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Slash')),
|
||||
-1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user