diff --git a/packages/flutter_driver/lib/src/common/find.dart b/packages/flutter_driver/lib/src/common/find.dart index 90b7c29bc3..a5e9bcb07a 100644 --- a/packages/flutter_driver/lib/src/common/find.dart +++ b/packages/flutter_driver/lib/src/common/find.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:convert'; + import 'package:meta/meta.dart'; import 'error.dart'; @@ -338,9 +340,9 @@ class Descendant extends SerializableFinder { @override Map serialize() { return super.serialize() - ..addAll(of.serialize().map((String key, String value) => MapEntry('of_$key', value))) - ..addAll(matching.serialize().map((String key, String value) => MapEntry('matching_$key', value))) ..addAll({ + 'of': jsonEncode(of.serialize()), + 'matching': jsonEncode(matching.serialize()), 'matchRoot': matchRoot ? 'true' : 'false', 'firstMatchOnly': firstMatchOnly ? 'true' : 'false', }); @@ -348,23 +350,15 @@ class Descendant extends SerializableFinder { /// Deserializes the finder from JSON generated by [serialize]. static Descendant deserialize(Map json) { - final Map of = {}; - final Map matching = {}; - final Map other = {}; - for (String key in json.keys) { - if (key.startsWith('of_')) { - of[key.substring('of_'.length)] = json[key]; - } else if (key.startsWith('matching_')) { - matching[key.substring('matching_'.length)] = json[key]; - } else { - other[key] = json[key]; - } - } + final Map jsonOfMatcher = + Map.from(jsonDecode(json['of'])); + final Map jsonMatchingMatcher = + Map.from(jsonDecode(json['matching'])); return Descendant( - of: SerializableFinder.deserialize(of), - matching: SerializableFinder.deserialize(matching), - matchRoot: other['matchRoot'] == 'true', - firstMatchOnly: other['firstMatchOnly'] == 'true', + of: SerializableFinder.deserialize(jsonOfMatcher), + matching: SerializableFinder.deserialize(jsonMatchingMatcher), + matchRoot: json['matchRoot'] == 'true', + firstMatchOnly: json['firstMatchOnly'] == 'true', ); } } @@ -401,9 +395,9 @@ class Ancestor extends SerializableFinder { @override Map serialize() { return super.serialize() - ..addAll(of.serialize().map((String key, String value) => MapEntry('of_$key', value))) - ..addAll(matching.serialize().map((String key, String value) => MapEntry('matching_$key', value))) ..addAll({ + 'of': jsonEncode(of.serialize()), + 'matching': jsonEncode(matching.serialize()), 'matchRoot': matchRoot ? 'true' : 'false', 'firstMatchOnly': firstMatchOnly ? 'true' : 'false', }); @@ -411,23 +405,15 @@ class Ancestor extends SerializableFinder { /// Deserializes the finder from JSON generated by [serialize]. static Ancestor deserialize(Map json) { - final Map of = {}; - final Map matching = {}; - final Map other = {}; - for (String key in json.keys) { - if (key.startsWith('of_')) { - of[key.substring('of_'.length)] = json[key]; - } else if (key.startsWith('matching_')) { - matching[key.substring('matching_'.length)] = json[key]; - } else { - other[key] = json[key]; - } - } + final Map jsonOfMatcher = + Map.from(jsonDecode(json['of'])); + final Map jsonMatchingMatcher = + Map.from(jsonDecode(json['matching'])); return Ancestor( - of: SerializableFinder.deserialize(of), - matching: SerializableFinder.deserialize(matching), - matchRoot: other['matchRoot'] == 'true', - firstMatchOnly: other['firstMatchOnly'] == 'true', + of: SerializableFinder.deserialize(jsonOfMatcher), + matching: SerializableFinder.deserialize(jsonMatchingMatcher), + matchRoot: json['matchRoot'] == 'true', + firstMatchOnly: json['firstMatchOnly'] == 'true', ); } } diff --git a/packages/flutter_driver/test/src/find_test.dart b/packages/flutter_driver/test/src/find_test.dart index d15be6e927..b2e331e15b 100644 --- a/packages/flutter_driver/test/src/find_test.dart +++ b/packages/flutter_driver/test/src/find_test.dart @@ -19,11 +19,8 @@ void main() { ); expect(a.serialize(), { 'finderType': 'Ancestor', - 'of_finderType': 'ByType', - 'of_type': 'Text', - 'matching_finderType': 'ByValueKey', - 'matching_keyValueString': 'hello', - 'matching_keyValueType': 'String', + 'of': '{"finderType":"ByType","type":"Text"}', + 'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}', 'matchRoot': 'true', 'firstMatchOnly': 'true', }); @@ -32,11 +29,8 @@ void main() { test('Ancestor finder deserialize', () { final Map serialized = { 'finderType': 'Ancestor', - 'of_finderType': 'ByType', - 'of_type': 'Text', - 'matching_finderType': 'ByValueKey', - 'matching_keyValueString': 'hello', - 'matching_keyValueType': 'String', + 'of': '{"finderType":"ByType","type":"Text"}', + 'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}', 'matchRoot': 'true', 'firstMatchOnly': 'true', }; @@ -60,11 +54,8 @@ void main() { ); expect(a.serialize(), { 'finderType': 'Descendant', - 'of_finderType': 'ByType', - 'of_type': 'Text', - 'matching_finderType': 'ByValueKey', - 'matching_keyValueString': 'hello', - 'matching_keyValueType': 'String', + 'of': '{"finderType":"ByType","type":"Text"}', + 'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}', 'matchRoot': 'true', 'firstMatchOnly': 'true', }); @@ -73,11 +64,8 @@ void main() { test('Descendant finder deserialize', () { final Map serialized = { 'finderType': 'Descendant', - 'of_finderType': 'ByType', - 'of_type': 'Text', - 'matching_finderType': 'ByValueKey', - 'matching_keyValueString': 'hello', - 'matching_keyValueType': 'String', + 'of': '{"finderType":"ByType","type":"Text"}', + 'matching': '{"finderType":"ByValueKey","keyValueString":"hello","keyValueType":"String"}', 'matchRoot': 'true', 'firstMatchOnly': 'true', };