Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -10,17 +10,13 @@ import '../common.dart';
TimelineEvent newGPUTraceEvent(double ms) => TimelineEvent(<String, dynamic>{
'name': 'AllocatorVK',
'ph': 'b',
'args': <String, String>{
'MemoryBudgetUsageMB': ms.toString()
},
'args': <String, String>{'MemoryBudgetUsageMB': ms.toString()},
});
TimelineEvent newMetalGPUTraceEvent(double ms) => TimelineEvent(<String, dynamic>{
'name': 'AllocatorMTL',
'ph': 'b',
'args': <String, String>{
'MemoryBudgetUsageMB': ms.toString()
},
'args': <String, String>{'MemoryBudgetUsageMB': ms.toString()},
});
void main() {

View File

@@ -10,9 +10,7 @@ import '../common.dart';
TimelineEvent newGPUTraceEvent(double ms) => TimelineEvent(<String, dynamic>{
'name': 'GPUStart',
'ph': 'b',
'args': <String, String>{
'FrameTimeMS': ms.toString()
},
'args': <String, String>{'FrameTimeMS': ms.toString()},
});
void main() {

File diff suppressed because it is too large Load Diff

View File

@@ -13,12 +13,7 @@ void main() {
const SerializableFinder of = ByType('Text');
final SerializableFinder matching = ByValueKey('hello');
final Ancestor a = Ancestor(
of: of,
matching: matching,
matchRoot: true,
firstMatchOnly: true,
);
final Ancestor a = Ancestor(of: of, matching: matching, matchRoot: true, firstMatchOnly: true);
expect(a.serialize(), <String, String>{
'finderType': 'Ancestor',
'of': '{"finderType":"ByType","type":"Text"}',
@@ -80,4 +75,4 @@ void main() {
});
}
class FakeDeserialize extends Fake with DeserializeFinderFactory { }
class FakeDeserialize extends Fake with DeserializeFinderFactory {}

View File

@@ -42,7 +42,7 @@ void main() {
fakeIsolate = createFakeIsolate();
fakeVM = FakeVM(fakeIsolate);
fakeClient = FakeVmService(fakeVM);
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status':'ok'});
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status': 'ok'});
});
tearDown(() {
@@ -62,15 +62,28 @@ void main() {
expect(exists, true, reason: 'Not found ${logFile.path}');
final String commandLog = await logFile.readAsString();
const String waitForCommandLog = '>>> {command: waitFor, timeout: $_kSerializedTestTimeout, finderType: ByTooltipMessage, text: foo}';
const String waitForCommandLog =
'>>> {command: waitFor, timeout: $_kSerializedTestTimeout, finderType: ByTooltipMessage, text: foo}';
const String responseLog = '<<< {isError: false, response: {status: ok}}';
expect(commandLog.contains(waitForCommandLog), true, reason: '$commandLog not contains $waitForCommandLog');
expect(commandLog.contains(responseLog), true, reason: '$commandLog not contains $responseLog');
expect(
commandLog.contains(waitForCommandLog),
true,
reason: '$commandLog not contains $waitForCommandLog',
);
expect(
commandLog.contains(responseLog),
true,
reason: '$commandLog not contains $responseLog',
);
});
test('logCommunicationToFile = false', () async {
driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate, logCommunicationToFile: false);
driver = VMServiceFlutterDriver.connectedTo(
fakeClient,
fakeIsolate,
logCommunicationToFile: false,
);
logFile = File(driver.logFilePathName);
// clear log file if left in filetree from previous run
if (logFile.existsSync()) {
@@ -101,11 +114,15 @@ void main() {
fakeIsolate = createFakeIsolate();
fakeVM = FakeVM(fakeIsolate);
fakeClient = FakeVmService(fakeVM);
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status':'ok'});
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{'status': 'ok'});
});
test('printCommunication = true', () async {
driver = VMServiceFlutterDriver.connectedTo(fakeClient, fakeIsolate, printCommunication: true);
driver = VMServiceFlutterDriver.connectedTo(
fakeClient,
fakeIsolate,
printCommunication: true,
);
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
expect(log, <String>[
'VMServiceFlutterDriver: >>> {command: waitFor, timeout: $_kSerializedTestTimeout, finderType: ByTooltipMessage, text: foo}',
@@ -152,8 +169,10 @@ void main() {
// becomes available. `.timeout` is used here to exit the infinite loop,
// expecting that no other types of error are thrown during the process.
expect(
vmServiceConnectFunction('http://foo.bar', <String, dynamic>{})
.timeout(const Duration(seconds: 1)),
vmServiceConnectFunction(
'http://foo.bar',
<String, dynamic>{},
).timeout(const Duration(seconds: 1)),
throwsA(isA<TimeoutException>()),
);
});
@@ -175,18 +194,15 @@ void main() {
fakeVM.numberOfTriesBeforeResolvingIsolate = 5;
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull);
expect(
fakeClient.connectionLog,
<String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
],
);
expect(fakeClient.connectionLog, <String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
]);
});
test('Refreshes isolate if it is not started for long time', () async {
@@ -198,40 +214,37 @@ void main() {
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull);
expect(
fakeClient.connectionLog,
<String>[
'getIsolate',
'getIsolate',
'getIsolate',
'getIsolate',
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
],
);
expect(fakeClient.connectionLog, <String>[
'getIsolate',
'getIsolate',
'getIsolate',
'getIsolate',
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
]);
});
test('Connects to isolate number', () async {
fakeIsolate.pauseEvent = vms.Event(kind: vms.EventKind.kPauseStart, timestamp: 0);
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '', isolateNumber: int.parse(fakeIsolate.number!));
expect(driver, isNotNull);
expect(
fakeClient.connectionLog,
<String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
],
final FlutterDriver driver = await FlutterDriver.connect(
dartVmServiceUrl: '',
isolateNumber: int.parse(fakeIsolate.number!),
);
expect(driver, isNotNull);
expect(fakeClient.connectionLog, <String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
]);
});
test('connects to isolate paused at start', () async {
@@ -240,18 +253,15 @@ void main() {
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull);
expectLogContains('Isolate is paused at start');
expect(
fakeClient.connectionLog,
<String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
],
);
expect(fakeClient.connectionLog, <String>[
'getIsolate',
'setFlag pause_isolates_on_start false',
'resume',
'streamListen Isolate',
'getIsolate',
'onIsolateEvent',
'streamCancel Isolate',
]);
});
test('ignores setFlag failure', () async {
@@ -259,12 +269,13 @@ void main() {
fakeClient.failOnSetFlag = true;
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expectLogContains('Failed to set pause_isolates_on_start=false, proceeding. '
'Error: Exception: setFlag failed');
expectLogContains(
'Failed to set pause_isolates_on_start=false, proceeding. '
'Error: Exception: setFlag failed',
);
expect(driver, isNotNull);
});
test('connects to isolate paused mid-flight', () async {
fakeIsolate.pauseEvent = vms.Event(kind: vms.EventKind.kPauseBreakpoint, timestamp: 0);
@@ -303,7 +314,7 @@ void main() {
});
test('connects to unpaused when onExtensionAdded does not contain the '
'driver extension', () async {
'driver extension', () async {
fakeIsolate.pauseEvent = vms.Event(kind: vms.EventKind.kResume, timestamp: 0);
fakeIsolate.extensionRPCs!.add('ext.flutter.driver');
@@ -403,9 +414,7 @@ void main() {
'tree': 'hello',
});
final LayerTree result = await driver.getLayerTree(timeout: _kTestTimeout);
final LayerTree referenceTree = LayerTree.fromJson(<String, String>{
'tree': 'hello',
});
final LayerTree referenceTree = LayerTree.fromJson(<String, String>{'tree': 'hello'});
expect(result.tree, referenceTree.tree);
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_layer_tree, timeout: $_kSerializedTestTimeout}',
@@ -462,10 +471,11 @@ void main() {
test('sends the waitForCondition of combined conditions command', () async {
fakeClient.responses['waitForCondition'] = makeFakeResponse(<String, dynamic>{});
const SerializableWaitCondition combinedCondition =
CombinedCondition(<SerializableWaitCondition>[NoPendingFrame(), NoTransientCallbacks()]);
const SerializableWaitCondition combinedCondition = CombinedCondition(
<SerializableWaitCondition>[NoPendingFrame(), NoTransientCallbacks()],
);
await driver.waitForCondition(combinedCondition, timeout: _kTestTimeout);
expect(fakeClient.commandLog, <String>[
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: waitForCondition, timeout: $_kSerializedTestTimeout, conditionName: CombinedCondition, conditions: [{"conditionName":"NoPendingFrameCondition"},{"conditionName":"NoTransientCallbacksCondition"}]}',
]);
});
@@ -493,49 +503,61 @@ void main() {
group('getOffset', () {
setUp(() {
fakeClient.responses['get_offset'] = makeFakeResponse(<String, double>{
'dx': 11,
'dy': 12,
});
fakeClient.responses['get_offset'] = makeFakeResponse(<String, double>{'dx': 11, 'dy': 12});
});
test('sends the getCenter command', () async {
final DriverOffset result = await driver.getCenter(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getCenter(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: center}',
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: center}',
]);
});
test('sends the getTopLeft command', () async {
final DriverOffset result = await driver.getTopLeft(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getTopLeft(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: topLeft}',
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: topLeft}',
]);
});
test('sends the getTopRight command', () async {
final DriverOffset result = await driver.getTopRight(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getTopRight(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: topRight}',
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: topRight}',
]);
});
test('sends the getBottomLeft command', () async {
final DriverOffset result = await driver.getBottomLeft(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getBottomLeft(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: bottomLeft}',
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: bottomLeft}',
]);
});
test('sends the getBottomRight command', () async {
final DriverOffset result = await driver.getBottomRight(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getBottomRight(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: bottomRight}',
'ext.flutter.driver {command: get_offset, timeout: 1234, finderType: ByValueKey, keyValueString: 123, keyValueType: int, offsetType: bottomRight}',
]);
});
});
@@ -585,9 +607,7 @@ void main() {
fakeClient.incrementMicros = true;
fakeClient.timelineResponses[1000001] = vms.Timeline.parse(<String, dynamic>{
'traceEvents': <dynamic>[
<String, dynamic>{
'name': 'test event 2',
},
<String, dynamic>{'name': 'test event 2'},
],
'timeOriginMicros': 1000000,
'timeExtentMicros': 999999,
@@ -618,15 +638,17 @@ void main() {
test('specify non-default timeline streams', () async {
bool actionCalled = false;
final Timeline timeline = await driver.traceAction(() async {
actionCalled = true;
},
streams: const <TimelineStream>[
TimelineStream.dart,
TimelineStream.gc,
TimelineStream.compiler,
],
retainPriorEvents: true);
final Timeline timeline = await driver.traceAction(
() async {
actionCalled = true;
},
streams: const <TimelineStream>[
TimelineStream.dart,
TimelineStream.gc,
TimelineStream.compiler,
],
retainPriorEvents: true,
);
expect(actionCalled, isTrue);
expect(fakeClient.connectionLog, <String>[
@@ -649,7 +671,9 @@ void main() {
expect(log, <String>[]);
time.elapse(kUnusuallyLongTimeout);
});
expect(log, <String>['VMServiceFlutterDriver: waitFor message is taking a long time to complete...']);
expect(log, <String>[
'VMServiceFlutterDriver: waitFor message is taking a long time to complete...',
]);
});
test('local custom timeout', () async {
@@ -661,7 +685,9 @@ void main() {
expect(log, <String>[]);
time.elapse(customTimeout);
});
expect(log, <String>['VMServiceFlutterDriver: waitFor message is taking a long time to complete...']);
expect(log, <String>[
'VMServiceFlutterDriver: waitFor message is taking a long time to complete...',
]);
});
test('remote error', () async {
@@ -670,11 +696,13 @@ void main() {
}, isError: true);
await expectLater(
() => driver.waitFor(find.byTooltip('foo')),
throwsA(isA<DriverError>().having(
(DriverError error) => error.message,
'message',
'Error in Flutter application: {message: This is a failure}',
)),
throwsA(
isA<DriverError>().having(
(DriverError error) => error.message,
'message',
'Error in Flutter application: {message: This is a failure}',
),
),
);
});
@@ -718,7 +746,7 @@ void main() {
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{});
fakeClient.responses['set_frame_sync'] = makeFakeResponse(<String, dynamic>{});
await driver.runUnsynchronized(() async {
await driver.runUnsynchronized(() async {
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
});
@@ -747,18 +775,14 @@ void main() {
test('GetHealth has no default timeout', () async {
await driver.checkHealth();
expect(
fakeClient.commandLog,
<String>['ext.flutter.driver {command: get_health}'],
);
expect(fakeClient.commandLog, <String>['ext.flutter.driver {command: get_health}']);
});
test('does not interfere with explicit timeouts', () async {
await driver.checkHealth(timeout: _kTestTimeout);
expect(
fakeClient.commandLog,
<String>['ext.flutter.driver {command: get_health, timeout: $_kSerializedTestTimeout}'],
);
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: get_health, timeout: $_kSerializedTestTimeout}',
]);
});
});
@@ -770,7 +794,9 @@ void main() {
setUp(() {
fakeConnection = FakeFlutterWebConnection();
fakeConnection.supportsTimelineAction = true;
fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'status': 'ok'}));
fakeConnection.responses['waitFor'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'status': 'ok'}),
);
});
tearDown(() {
@@ -788,10 +814,15 @@ void main() {
expect(exists, true, reason: 'Not found ${logFile.path}');
final String commandLog = await logFile.readAsString();
const String waitForCommandLog = '>>> {command: waitFor, timeout: 1234, finderType: ByTooltipMessage, text: logCommunicationToFile test}';
const String waitForCommandLog =
'>>> {command: waitFor, timeout: 1234, finderType: ByTooltipMessage, text: logCommunicationToFile test}';
const String responseLog = '<<< {isError: false, response: {status: ok}, type: Response}';
expect(commandLog, contains(waitForCommandLog), reason: '$commandLog not contains $waitForCommandLog');
expect(
commandLog,
contains(waitForCommandLog),
reason: '$commandLog not contains $waitForCommandLog',
);
expect(commandLog, contains(responseLog), reason: '$commandLog not contains $responseLog');
});
@@ -816,7 +847,9 @@ void main() {
log.clear();
fakeConnection = FakeFlutterWebConnection();
fakeConnection.supportsTimelineAction = true;
fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'status': 'ok'}));
fakeConnection.responses['waitFor'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'status': 'ok'}),
);
});
test('printCommunication = true', () async {
@@ -851,8 +884,7 @@ void main() {
group('ByValueKey', () {
test('restricts value types', () async {
expect(() => find.byValueKey(null),
throwsDriverError);
expect(() => find.byValueKey(null), throwsDriverError);
});
test('finds by ValueKey', () async {
@@ -894,7 +926,9 @@ void main() {
group('getText', () {
test('sends the getText command', () async {
fakeConnection.responses['get_text'] = jsonEncode(makeFakeResponse(<String, dynamic>{'text': 'hello'}));
fakeConnection.responses['get_text'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'text': 'hello'}),
);
final String result = await driver.getText(find.byValueKey(123), timeout: _kTestTimeout);
expect(result, 'hello');
expect(fakeConnection.commandLog, <String>[
@@ -905,7 +939,9 @@ void main() {
group('waitFor', () {
test('sends the waitFor command', () async {
fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'text': 'hello'}));
fakeConnection.responses['waitFor'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'text': 'hello'}),
);
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"waitFor","timeout":"1234","finderType":"ByTooltipMessage","text":"foo"}') 0:00:01.234000''',
@@ -915,7 +951,9 @@ void main() {
group('waitForCondition', () {
setUp(() {
fakeConnection.responses['waitForCondition'] = jsonEncode(makeFakeResponse(<String, dynamic>{'text': 'hello'}));
fakeConnection.responses['waitForCondition'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'text': 'hello'}),
);
});
test('sends the wait for NoPendingFrameCondition command', () async {
@@ -945,7 +983,9 @@ void main() {
group('waitUntilNoTransientCallbacks', () {
test('sends the waitUntilNoTransientCallbacks command', () async {
fakeConnection.responses['waitForCondition'] = jsonEncode(makeFakeResponse(<String, dynamic>{}));
fakeConnection.responses['waitForCondition'] = jsonEncode(
makeFakeResponse(<String, dynamic>{}),
);
await driver.waitUntilNoTransientCallbacks(timeout: _kTestTimeout);
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"waitForCondition","timeout":"1234","conditionName":"NoTransientCallbacksCondition"}') 0:00:01.234000''',
@@ -955,14 +995,16 @@ void main() {
group('getOffset', () {
setUp(() {
fakeConnection.responses['get_offset'] = jsonEncode(makeFakeResponse(<String, double>{
'dx': 11,
'dy': 12,
}));
fakeConnection.responses['get_offset'] = jsonEncode(
makeFakeResponse(<String, double>{'dx': 11, 'dy': 12}),
);
});
test('sends the getCenter command', () async {
final DriverOffset result = await driver.getCenter(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getCenter(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_offset","timeout":"1234","finderType":"ByValueKey","keyValueString":"123","keyValueType":"int","offsetType":"center"}') 0:00:01.234000''',
@@ -970,7 +1012,10 @@ void main() {
});
test('sends the getTopLeft command', () async {
final DriverOffset result = await driver.getTopLeft(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getTopLeft(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_offset","timeout":"1234","finderType":"ByValueKey","keyValueString":"123","keyValueType":"int","offsetType":"topLeft"}') 0:00:01.234000''',
@@ -978,7 +1023,10 @@ void main() {
});
test('sends the getTopRight command', () async {
final DriverOffset result = await driver.getTopRight(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getTopRight(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_offset","timeout":"1234","finderType":"ByValueKey","keyValueString":"123","keyValueType":"int","offsetType":"topRight"}') 0:00:01.234000''',
@@ -986,7 +1034,10 @@ void main() {
});
test('sends the getBottomLeft command', () async {
final DriverOffset result = await driver.getBottomLeft(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getBottomLeft(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_offset","timeout":"1234","finderType":"ByValueKey","keyValueString":"123","keyValueType":"int","offsetType":"bottomLeft"}') 0:00:01.234000''',
@@ -994,7 +1045,10 @@ void main() {
});
test('sends the getBottomRight command', () async {
final DriverOffset result = await driver.getBottomRight(find.byValueKey(123), timeout: _kTestTimeout);
final DriverOffset result = await driver.getBottomRight(
find.byValueKey(123),
timeout: _kTestTimeout,
);
expect(result, const DriverOffset(11, 12));
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_offset","timeout":"1234","finderType":"ByValueKey","keyValueString":"123","keyValueType":"int","offsetType":"bottomRight"}') 0:00:01.234000''',
@@ -1003,7 +1057,9 @@ void main() {
});
test('checks the health of the driver extension', () async {
fakeConnection.responses['get_health'] = jsonEncode(makeFakeResponse(<String, dynamic>{'status': 'ok'}));
fakeConnection.responses['get_health'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'status': 'ok'}),
);
await driver.checkHealth();
expect(fakeConnection.commandLog, <String>[
r'''window.$flutterDriver('{"command":"get_health"}') null''',
@@ -1034,8 +1090,12 @@ void main() {
group('runUnsynchronized', () {
test('wrap waitFor with runUnsynchronized', () async {
fakeConnection.responses['waitFor'] = jsonEncode(makeFakeResponse(<String, dynamic>{'text': 'hello'}));
fakeConnection.responses['set_frame_sync'] = jsonEncode(makeFakeResponse(<String, dynamic>{}));
fakeConnection.responses['waitFor'] = jsonEncode(
makeFakeResponse(<String, dynamic>{'text': 'hello'}),
);
fakeConnection.responses['set_frame_sync'] = jsonEncode(
makeFakeResponse(<String, dynamic>{}),
);
await driver.runUnsynchronized(() async {
await driver.waitFor(find.byTooltip('foo'), timeout: _kTestTimeout);
@@ -1060,7 +1120,12 @@ void main() {
});
test('tracing', () async {
expect(driver.traceAction(() async { return Future<dynamic>.value(); }), throwsUnsupportedError);
expect(
driver.traceAction(() async {
return Future<dynamic>.value();
}),
throwsUnsupportedError,
);
expect(driver.startTracing(), throwsUnsupportedError);
expect(driver.stopTracingAndDownloadTimeline(), throwsUnsupportedError);
expect(driver.clearTimeline(), throwsUnsupportedError);
@@ -1080,14 +1145,8 @@ String _checkAndEncode(dynamic script) {
return scriptString.substring(_kWebScriptPrefix.length, script.length - 2);
}
vms.Response? makeFakeResponse(
Map<String, dynamic> response, {
bool isError = false,
}) {
return vms.Response.parse(<String, dynamic>{
'isError': isError,
'response': response,
});
vms.Response? makeFakeResponse(Map<String, dynamic> response, {bool isError = false}) {
return vms.Response.parse(<String, dynamic>{'isError': isError, 'response': response});
}
void Function(vms.Isolate) changeIsolateEventAfter(int gets, vms.Event nextEvent) {
@@ -1108,7 +1167,8 @@ class FakeFlutterWebConnection extends Fake implements FlutterWebConnection {
@override
Future<dynamic> sendCommand(String script, Duration? duration) async {
commandLog.add('$script $duration');
final Map<String, dynamic> decoded = jsonDecode(_checkAndEncode(script)) as Map<String, dynamic>;
final Map<String, dynamic> decoded =
jsonDecode(_checkAndEncode(script)) as Map<String, dynamic>;
final dynamic response = responses[decoded['command']];
assert(response != null, 'Missing ${decoded['command']} in responses.');
return response;
@@ -1189,7 +1249,11 @@ class FakeVmService extends Fake implements vms.VmService {
Future<void>? artificialExtensionDelay;
@override
Future<vms.Response> callServiceExtension(String method, {Map<dynamic, dynamic>? args, String? isolateId}) async {
Future<vms.Response> callServiceExtension(
String method, {
Map<dynamic, dynamic>? args,
String? isolateId,
}) async {
commandLog.add('$method $args');
await artificialExtensionDelay;
@@ -1231,9 +1295,7 @@ class FakeVmService extends Fake implements vms.VmService {
final Map<int, vms.Timeline?> timelineResponses = <int, vms.Timeline?>{
1: vms.Timeline.parse(<String, dynamic>{
'traceEvents': <dynamic>[
<String, dynamic>{
'name': 'test event',
},
<String, dynamic>{'name': 'test event'},
],
'timeOriginMicros': 0,
'timeExtentMicros': 999999,
@@ -1267,15 +1329,8 @@ class FakeVM extends Fake implements vms.VM {
@override
List<vms.IsolateRef> get isolates {
numberOfTriesBeforeResolvingIsolate -= 1;
return <vms.Isolate>[
if (numberOfTriesBeforeResolvingIsolate <= 0)
isolate!,
];
return <vms.Isolate>[if (numberOfTriesBeforeResolvingIsolate <= 0) isolate!];
}
}
vms.Isolate createFakeIsolate() => vms.Isolate(
id: '123',
number: '123',
extensionRPCs: <String>[],
);
vms.Isolate createFakeIsolate() => vms.Isolate(id: '123', number: '123', extensionRPCs: <String>[]);

View File

@@ -7,7 +7,7 @@ import 'package:flutter_driver/src/extension/_extension_io.dart';
import '../../common.dart';
void main() {
group('test io_extension',() {
group('test io_extension', () {
late Future<Map<String, dynamic>> Function(Map<String, String>) call;
setUp(() {

View File

@@ -7,10 +7,9 @@ import 'package:flutter_driver/flutter_driver.dart';
class StubNestedCommand extends CommandWithTarget {
StubNestedCommand(super.finder, this.times, {super.timeout});
StubNestedCommand.deserialize(
super.json, super.finderFactory)
: times = int.parse(json['times']!),
super.deserialize();
StubNestedCommand.deserialize(super.json, super.finderFactory)
: times = int.parse(json['times']!),
super.deserialize();
@override
Map<String, String> serialize() {
@@ -27,8 +26,8 @@ class StubProberCommand extends CommandWithTarget {
StubProberCommand(super.finder, this.times, {super.timeout});
StubProberCommand.deserialize(super.json, super.finderFactory)
: times = int.parse(json['times']!),
super.deserialize();
: times = int.parse(json['times']!),
super.deserialize();
@override
Map<String, String> serialize() {
@@ -48,8 +47,6 @@ class StubCommandResult extends Result {
@override
Map<String, dynamic> toJson() {
return <String, dynamic>{
'resultParam': resultParam,
};
return <String, dynamic>{'resultParam': resultParam};
}
}

View File

@@ -13,7 +13,12 @@ class StubNestedCommandExtension extends CommandExtension {
String get commandKind => 'StubNestedCommand';
@override
Future<Result> call(Command command, WidgetController prober, CreateFinderFactory finderFactory, CommandHandlerFactory handlerFactory) async {
Future<Result> call(
Command command,
WidgetController prober,
CreateFinderFactory finderFactory,
CommandHandlerFactory handlerFactory,
) async {
final StubNestedCommand stubCommand = command as StubNestedCommand;
handlerFactory.waitForElement(finderFactory.createFinder(stubCommand.finder));
for (int index = 0; index < stubCommand.times; index++) {
@@ -23,7 +28,11 @@ class StubNestedCommandExtension extends CommandExtension {
}
@override
Command deserialize(Map<String, String> params, DeserializeFinderFactory finderFactory, DeserializeCommandFactory commandFactory) {
Command deserialize(
Map<String, String> params,
DeserializeFinderFactory finderFactory,
DeserializeCommandFactory commandFactory,
) {
return StubNestedCommand.deserialize(params, finderFactory);
}
}
@@ -33,7 +42,12 @@ class StubProberCommandExtension extends CommandExtension {
String get commandKind => 'StubProberCommand';
@override
Future<Result> call(Command command, WidgetController prober, CreateFinderFactory finderFactory, CommandHandlerFactory handlerFactory) async {
Future<Result> call(
Command command,
WidgetController prober,
CreateFinderFactory finderFactory,
CommandHandlerFactory handlerFactory,
) async {
final StubProberCommand stubCommand = command as StubProberCommand;
final Finder finder = finderFactory.createFinder(stubCommand.finder);
handlerFactory.waitForElement(finder);
@@ -44,7 +58,11 @@ class StubProberCommandExtension extends CommandExtension {
}
@override
Command deserialize(Map<String, String> params, DeserializeFinderFactory finderFactory, DeserializeCommandFactory commandFactory) {
Command deserialize(
Map<String, String> params,
DeserializeFinderFactory finderFactory,
DeserializeCommandFactory commandFactory,
) {
return StubProberCommand.deserialize(params, finderFactory);
}
}

View File

@@ -11,10 +11,7 @@ import 'stub_finder.dart';
class StubFinderExtension extends FinderExtension {
@override
Finder createFinder(
SerializableFinder finder,
CreateFinderFactory finderFactory,
) {
Finder createFinder(SerializableFinder finder, CreateFinderFactory finderFactory) {
return find.byWidgetPredicate((Widget widget) {
final Key? key = widget.key;
if (key is! ValueKey<String>) {

View File

@@ -6,14 +6,13 @@ import 'package:flutter_driver/flutter_driver.dart' as flutter_driver;
import 'package:flutter_test/flutter_test.dart';
void main() {
test('flutter_driver.TextInputAction should be sync with TextInputAction',
() {
final List<String> actual = flutter_driver.TextInputAction.values
.map((flutter_driver.TextInputAction action) => action.name)
.toList();
final List<String> matcher = TextInputAction.values
.map((TextInputAction action) => action.name)
.toList();
test('flutter_driver.TextInputAction should be sync with TextInputAction', () {
final List<String> actual =
flutter_driver.TextInputAction.values
.map((flutter_driver.TextInputAction action) => action.name)
.toList();
final List<String> matcher =
TextInputAction.values.map((TextInputAction action) => action.name).toList();
expect(actual, matcher);
});
}

View File

@@ -17,11 +17,10 @@ import '../../common.dart';
void main() {
group('TimelineSummary', () {
TimelineSummary summarize(List<Map<String, dynamic>> testEvents) {
return TimelineSummary.summarize(Timeline.fromJson(<String, dynamic>{
'traceEvents': testEvents,
}));
return TimelineSummary.summarize(
Timeline.fromJson(<String, dynamic>{'traceEvents': testEvents}),
);
}
Map<String, dynamic> frameBegin(int timeStamp) => <String, dynamic>{
@@ -52,38 +51,33 @@ void main() {
'name': 'SceneDisplayLag',
'ph': 'b',
'ts': timeStamp,
'args': <String, String>{
'vsync_transitions_missed': vsyncsMissed.toString(),
},
'args': <String, String>{'vsync_transitions_missed': vsyncsMissed.toString()},
};
Map<String, dynamic> lagEnd(int timeStamp, int vsyncsMissed) => <String, dynamic>{
'name': 'SceneDisplayLag',
'ph': 'e',
'ts': timeStamp,
'args': <String, String>{
'vsync_transitions_missed': vsyncsMissed.toString(),
},
'args': <String, String>{'vsync_transitions_missed': vsyncsMissed.toString()},
};
Map<String, dynamic> cpuUsage(int timeStamp, double cpuUsage) => <String, dynamic>{
'cat': 'embedder',
'name': 'CpuUsage',
'ts': timeStamp,
'args': <String, String>{
'total_cpu_usage': cpuUsage.toString(),
},
'args': <String, String>{'total_cpu_usage': cpuUsage.toString()},
};
Map<String, dynamic> memoryUsage(int timeStamp, double dirty, double shared) => <String, dynamic>{
'cat': 'embedder',
'name': 'MemoryUsage',
'ts': timeStamp,
'args': <String, String>{
'owned_shared_memory_usage': shared.toString(),
'dirty_memory_usage': dirty.toString(),
},
};
Map<String, dynamic> memoryUsage(int timeStamp, double dirty, double shared) =>
<String, dynamic>{
'cat': 'embedder',
'name': 'MemoryUsage',
'ts': timeStamp,
'args': <String, String>{
'owned_shared_memory_usage': shared.toString(),
'dirty_memory_usage': dirty.toString(),
},
};
Map<String, dynamic> platformVsync(int timeStamp) => <String, dynamic>{
'name': 'VSYNC',
@@ -91,14 +85,16 @@ void main() {
'ts': timeStamp,
};
Map<String, dynamic> vsyncCallback(int timeStamp, {String phase = 'B', String startTime = '2750850055428', String endTime = '2750866722095'}) => <String, dynamic>{
Map<String, dynamic> vsyncCallback(
int timeStamp, {
String phase = 'B',
String startTime = '2750850055428',
String endTime = '2750866722095',
}) => <String, dynamic>{
'name': 'VsyncProcessCallback',
'ph': phase,
'ts': timeStamp,
'args': <String, dynamic>{
'StartTime': startTime,
'TargetTime': endTime,
},
'args': <String, dynamic>{'StartTime': startTime, 'TargetTime': endTime},
};
List<Map<String, dynamic>> genGC(String name, int count, int startTime, int timeDiff) {
@@ -114,9 +110,7 @@ void main() {
'ts': ts,
'tts': ts,
'ph': begin ? 'B' : 'E',
'args': <String, dynamic>{
'isolateGroupId': 'isolateGroups/10824099774666259225',
},
'args': <String, dynamic>{'isolateGroupId': 'isolateGroups/10824099774666259225'},
});
ts = ts + timeDiff;
begin = !begin;
@@ -161,8 +155,10 @@ void main() {
test('counts frames', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(1000), frameEnd(2000),
frameBegin(3000), frameEnd(5000),
frameBegin(1000),
frameEnd(2000),
frameBegin(3000),
frameEnd(5000),
]).countFrames(),
2,
);
@@ -174,19 +170,22 @@ void main() {
expect(
() => summarize(<Map<String, dynamic>>[]).computeAverageFrameBuildTimeMillis(),
throwsA(
isA<StateError>()
.having((StateError e) => e.message,
isA<StateError>().having(
(StateError e) => e.message,
'message',
contains('The TimelineSummary had no events to summarize.'),
)),
),
),
);
});
test('computes average frame build time in milliseconds', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(1000), frameEnd(2000),
frameBegin(3000), frameEnd(5000),
frameBegin(1000),
frameEnd(2000),
frameBegin(3000),
frameEnd(5000),
]).computeAverageFrameBuildTimeMillis(),
1.5,
);
@@ -196,7 +195,8 @@ void main() {
expect(
summarize(<Map<String, dynamic>>[
frameEnd(1000),
frameBegin(2000), frameEnd(4000),
frameBegin(2000),
frameEnd(4000),
]).computeAverageFrameBuildTimeMillis(),
2.0,
);
@@ -205,7 +205,8 @@ void main() {
test('skips trailing "begin" events', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(2000), frameEnd(4000),
frameBegin(2000),
frameEnd(4000),
frameBegin(5000),
]).computeAverageFrameBuildTimeMillis(),
2.0,
@@ -243,26 +244,31 @@ void main() {
expect(
() => summarize(<Map<String, dynamic>>[]).computeWorstFrameBuildTimeMillis(),
throwsA(
isA<StateError>()
.having((StateError e) => e.message,
isA<StateError>().having(
(StateError e) => e.message,
'message',
contains('The TimelineSummary had no events to summarize.'),
)),
),
),
);
});
test('computes worst frame build time in milliseconds', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(1000), frameEnd(2000),
frameBegin(3000), frameEnd(5000),
frameBegin(1000),
frameEnd(2000),
frameBegin(3000),
frameEnd(5000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
);
expect(
summarize(<Map<String, dynamic>>[
frameBegin(3000), frameEnd(5000),
frameBegin(1000), frameEnd(2000),
frameBegin(3000),
frameEnd(5000),
frameBegin(1000),
frameEnd(2000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
);
@@ -272,7 +278,8 @@ void main() {
expect(
summarize(<Map<String, dynamic>>[
frameEnd(1000),
frameBegin(2000), frameEnd(4000),
frameBegin(2000),
frameEnd(4000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
);
@@ -281,7 +288,8 @@ void main() {
test('skips trailing "begin" events', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(2000), frameEnd(4000),
frameBegin(2000),
frameEnd(4000),
frameBegin(5000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
@@ -292,9 +300,12 @@ void main() {
group('computeMissedFrameBuildBudgetCount', () {
test('computes the number of missed build budgets', () {
final TimelineSummary summary = summarize(<Map<String, dynamic>>[
frameBegin(1000), frameEnd(18000),
frameBegin(19000), frameEnd(28000),
frameBegin(29000), frameEnd(47000),
frameBegin(1000),
frameEnd(18000),
frameBegin(19000),
frameEnd(28000),
frameBegin(29000),
frameEnd(47000),
]);
expect(summary.countFrames(), 3);
@@ -307,41 +318,46 @@ void main() {
expect(
() => summarize(<Map<String, dynamic>>[]).computeAverageFrameRasterizerTimeMillis(),
throwsA(
isA<StateError>()
.having((StateError e) => e.message,
isA<StateError>().having(
(StateError e) => e.message,
'message',
contains('The TimelineSummary had no events to summarize.'),
)),
),
),
);
});
test('computes average frame rasterizer time in milliseconds', () {
expect(
summarize(<Map<String, dynamic>>[
begin(1000), end(2000),
begin(3000), end(5000),
]).computeAverageFrameRasterizerTimeMillis(),
1.5,
summarize(<Map<String, dynamic>>[
begin(1000),
end(2000),
begin(3000),
end(5000),
]).computeAverageFrameRasterizerTimeMillis(),
1.5,
);
});
test('skips leading "end" events', () {
expect(
summarize(<Map<String, dynamic>>[
end(1000),
begin(2000), end(4000),
]).computeAverageFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
end(1000),
begin(2000),
end(4000),
]).computeAverageFrameRasterizerTimeMillis(),
2.0,
);
});
test('skips trailing "begin" events', () {
expect(
summarize(<Map<String, dynamic>>[
begin(2000), end(4000),
begin(5000),
]).computeAverageFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
begin(2000),
end(4000),
begin(5000),
]).computeAverageFrameRasterizerTimeMillis(),
2.0,
);
});
});
@@ -351,49 +367,55 @@ void main() {
expect(
() => summarize(<Map<String, dynamic>>[]).computeWorstFrameRasterizerTimeMillis(),
throwsA(
isA<StateError>()
.having((StateError e) => e.message,
isA<StateError>().having(
(StateError e) => e.message,
'message',
contains('The TimelineSummary had no events to summarize.'),
)),
),
),
);
});
test('computes worst frame rasterizer time in milliseconds', () {
expect(
summarize(<Map<String, dynamic>>[
begin(1000), end(2000),
begin(3000), end(5000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
begin(1000),
end(2000),
begin(3000),
end(5000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
);
expect(
summarize(<Map<String, dynamic>>[
begin(3000), end(5000),
begin(1000), end(2000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
begin(3000),
end(5000),
begin(1000),
end(2000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
);
});
test('skips leading "end" events', () {
expect(
summarize(<Map<String, dynamic>>[
end(1000),
begin(2000), end(4000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
end(1000),
begin(2000),
end(4000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
);
});
test('skips trailing "begin" events', () {
expect(
summarize(<Map<String, dynamic>>[
begin(2000), end(4000),
begin(5000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
summarize(<Map<String, dynamic>>[
begin(2000),
end(4000),
begin(5000),
]).computeWorstFrameRasterizerTimeMillis(),
2.0,
);
});
});
@@ -401,33 +423,32 @@ void main() {
group('percentile_frame_rasterizer_time_millis', () {
test('throws when there is no data', () {
expect(
() => summarize(<Map<String, dynamic>>[]).computePercentileFrameRasterizerTimeMillis(90.0),
() =>
summarize(<Map<String, dynamic>>[]).computePercentileFrameRasterizerTimeMillis(90.0),
throwsA(
isA<StateError>()
.having((StateError e) => e.message,
isA<StateError>().having(
(StateError e) => e.message,
'message',
contains('The TimelineSummary had no events to summarize.'),
)),
),
),
);
});
const List<List<int>> sequences = <List<int>>[
<int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
<int>[1, 2, 3, 4, 5],
<int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
];
const List<int> p90s = <int>[
9,
5,
18,
];
const List<int> p90s = <int>[9, 5, 18];
test('computes 90th frame rasterizer time in milliseconds', () {
for (int i = 0; i < sequences.length; ++i) {
expect(
summarize(rasterizeTimeSequenceInMillis(sequences[i])).computePercentileFrameRasterizerTimeMillis(90.0),
summarize(
rasterizeTimeSequenceInMillis(sequences[i]),
).computePercentileFrameRasterizerTimeMillis(90.0),
p90s[i],
);
}
@@ -439,7 +460,9 @@ void main() {
sequence.add(i);
}
expect(
summarize(rasterizeTimeSequenceInMillis(sequence)).computePercentileFrameRasterizerTimeMillis(99.0),
summarize(
rasterizeTimeSequenceInMillis(sequence),
).computePercentileFrameRasterizerTimeMillis(99.0),
99,
);
});
@@ -448,9 +471,12 @@ void main() {
group('computeMissedFrameRasterizerBudgetCount', () {
test('computes the number of missed rasterizer budgets', () {
final TimelineSummary summary = summarize(<Map<String, dynamic>>[
begin(1000), end(18000),
begin(19000), end(28000),
begin(29000), end(47000),
begin(1000),
end(18000),
begin(19000),
end(28000),
begin(29000),
end(47000),
]);
expect(summary.computeMissedFrameRasterizerBudgetCount(), 2);
@@ -461,14 +487,20 @@ void main() {
test('computes and returns summary as JSON', () {
expect(
summarize(<Map<String, dynamic>>[
begin(1000), end(19000),
begin(19001), end(29001),
begin(29002), end(49002),
begin(1000),
end(19000),
begin(19001),
end(29001),
begin(29002),
end(49002),
...newGenGC(4, 10, 100),
...oldGenGC(5, 10000, 100),
frameBegin(1000), frameEnd(18000),
frameBegin(19000), frameEnd(28000),
frameBegin(29000), frameEnd(48000),
frameBegin(1000),
frameEnd(18000),
frameBegin(19000),
frameEnd(28000),
frameBegin(29000),
frameEnd(48000),
frameRequestPendingStart('1', 1000),
frameRequestPendingEnd('1', 2000),
frameRequestPendingStart('2', 3000),
@@ -542,7 +574,6 @@ void main() {
});
group('writeTimelineToFile', () {
late Directory tempDir;
setUp(() {
@@ -556,8 +587,9 @@ void main() {
});
test('writes timeline to JSON file without summary', () async {
await summarize(<Map<String, String>>[<String, String>{'foo': 'bar'}])
.writeTimelineToFile('test', destinationDirectory: tempDir.path, includeSummary: false);
await summarize(<Map<String, String>>[
<String, String>{'foo': 'bar'},
]).writeTimelineToFile('test', destinationDirectory: tempDir.path, includeSummary: false);
final String written =
await fs.file(path.join(tempDir.path, 'test.timeline.json')).readAsString();
expect(written, '{"traceEvents":[{"foo":"bar"}]}');
@@ -566,12 +598,11 @@ void main() {
test('writes timeline to JSON file with summary', () async {
await summarize(<Map<String, dynamic>>[
<String, String>{'foo': 'bar'},
begin(1000), end(19000),
frameBegin(1000), frameEnd(18000),
]).writeTimelineToFile(
'test',
destinationDirectory: tempDir.path,
);
begin(1000),
end(19000),
frameBegin(1000),
frameEnd(18000),
]).writeTimelineToFile('test', destinationDirectory: tempDir.path);
final String written =
await fs.file(path.join(tempDir.path, 'test.timeline.json')).readAsString();
expect(
@@ -586,20 +617,32 @@ void main() {
test('writes summary to JSON file', () async {
await summarize(<Map<String, dynamic>>[
begin(1000), end(19000),
begin(19001), end(29001),
begin(29002), end(49002),
frameBegin(1000), frameEnd(18000),
frameBegin(19000), frameEnd(28000),
frameBegin(29000), frameEnd(48000),
lagBegin(1000, 4), lagEnd(2000, 4),
lagBegin(1200, 12), lagEnd(2400, 12),
lagBegin(4200, 8), lagEnd(9400, 8),
begin(1000),
end(19000),
begin(19001),
end(29001),
begin(29002),
end(49002),
frameBegin(1000),
frameEnd(18000),
frameBegin(19000),
frameEnd(28000),
frameBegin(29000),
frameEnd(48000),
lagBegin(1000, 4),
lagEnd(2000, 4),
lagBegin(1200, 12),
lagEnd(2400, 12),
lagBegin(4200, 8),
lagEnd(9400, 8),
...newGenGC(4, 10, 100),
...oldGenGC(5, 10000, 100),
cpuUsage(5000, 20), cpuUsage(5010, 60),
memoryUsage(6000, 20, 40), memoryUsage(6100, 30, 45),
platformVsync(7000), vsyncCallback(7500),
cpuUsage(5000, 20),
cpuUsage(5010, 60),
memoryUsage(6000, 20, 40),
memoryUsage(6100, 30, 45),
platformVsync(7000),
vsyncCallback(7500),
frameRequestPendingStart('1', 1000),
frameRequestPendingEnd('1', 2000),
frameRequestPendingStart('2', 3000),
@@ -681,17 +724,18 @@ void main() {
group('SceneDisplayLagSummarizer tests', () {
SceneDisplayLagSummarizer summarize(List<Map<String, dynamic>> traceEvents) {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': traceEvents,
});
return SceneDisplayLagSummarizer(timeline.events!);
final Timeline timeline = Timeline.fromJson(<String, dynamic>{'traceEvents': traceEvents});
return SceneDisplayLagSummarizer(timeline.events!);
}
test('average_vsyncs_missed', () async {
final SceneDisplayLagSummarizer summarizer = summarize(<Map<String, dynamic>>[
lagBegin(1000, 4), lagEnd(2000, 4),
lagBegin(1200, 12), lagEnd(2400, 12),
lagBegin(4200, 8), lagEnd(9400, 8),
lagBegin(1000, 4),
lagEnd(2000, 4),
lagBegin(1200, 12),
lagEnd(2400, 12),
lagBegin(4200, 8),
lagEnd(9400, 8),
]);
expect(summarizer.computeAverageVsyncTransitionsMissed(), 8.0);
});
@@ -705,26 +749,40 @@ void main() {
test('90th_percentile_vsyncs_missed', () async {
final SceneDisplayLagSummarizer summarizer = summarize(<Map<String, dynamic>>[
lagBegin(1000, 4), lagEnd(2000, 4),
lagBegin(1200, 12), lagEnd(2400, 12),
lagBegin(4200, 8), lagEnd(9400, 8),
lagBegin(6100, 14), lagEnd(11000, 14),
lagBegin(7100, 16), lagEnd(11500, 16),
lagBegin(7400, 11), lagEnd(13000, 11),
lagBegin(8200, 27), lagEnd(14100, 27),
lagBegin(8700, 7), lagEnd(14300, 7),
lagBegin(24200, 4187), lagEnd(39400, 4187),
lagBegin(1000, 4),
lagEnd(2000, 4),
lagBegin(1200, 12),
lagEnd(2400, 12),
lagBegin(4200, 8),
lagEnd(9400, 8),
lagBegin(6100, 14),
lagEnd(11000, 14),
lagBegin(7100, 16),
lagEnd(11500, 16),
lagBegin(7400, 11),
lagEnd(13000, 11),
lagBegin(8200, 27),
lagEnd(14100, 27),
lagBegin(8700, 7),
lagEnd(14300, 7),
lagBegin(24200, 4187),
lagEnd(39400, 4187),
]);
expect(summarizer.computePercentileVsyncTransitionsMissed(90), 27.0);
});
test('99th_percentile_vsyncs_missed', () async {
final SceneDisplayLagSummarizer summarizer = summarize(<Map<String, dynamic>>[
lagBegin(1000, 4), lagEnd(2000, 4),
lagBegin(1200, 12), lagEnd(2400, 12),
lagBegin(4200, 8), lagEnd(9400, 8),
lagBegin(6100, 14), lagEnd(11000, 14),
lagBegin(24200, 4187), lagEnd(39400, 4187),
lagBegin(1000, 4),
lagEnd(2000, 4),
lagBegin(1200, 12),
lagEnd(2400, 12),
lagBegin(4200, 8),
lagEnd(9400, 8),
lagBegin(6100, 14),
lagEnd(11000, 14),
lagBegin(24200, 4187),
lagEnd(39400, 4187),
]);
expect(summarizer.computePercentileVsyncTransitionsMissed(99), 4187.0);
});
@@ -732,10 +790,8 @@ void main() {
group('ProfilingSummarizer tests', () {
ProfilingSummarizer summarize(List<Map<String, dynamic>> traceEvents) {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': traceEvents,
});
return ProfilingSummarizer.fromEvents(timeline.events!);
final Timeline timeline = Timeline.fromJson(<String, dynamic>{'traceEvents': traceEvents});
return ProfilingSummarizer.fromEvents(timeline.events!);
}
test('has_both_cpu_and_memory_usage', () async {
@@ -760,10 +816,14 @@ void main() {
test('90th_percentile_cpu_usage', () async {
final ProfilingSummarizer summarizer = summarize(<Map<String, dynamic>>[
cpuUsage(0, 10), cpuUsage(1, 20),
cpuUsage(2, 20), cpuUsage(3, 80),
cpuUsage(4, 70), cpuUsage(4, 72),
cpuUsage(4, 85), cpuUsage(4, 100),
cpuUsage(0, 10),
cpuUsage(1, 20),
cpuUsage(2, 20),
cpuUsage(3, 80),
cpuUsage(4, 70),
cpuUsage(4, 72),
cpuUsage(4, 85),
cpuUsage(4, 100),
]);
expect(summarizer.computePercentile(ProfileType.CPU, 90), 85.0);
});
@@ -771,9 +831,7 @@ void main() {
group('VsyncFrameLagSummarizer tests', () {
VsyncFrameLagSummarizer summarize(List<Map<String, dynamic>> traceEvents) {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': traceEvents,
});
final Timeline timeline = Timeline.fromJson(<String, dynamic>{'traceEvents': traceEvents});
return VsyncFrameLagSummarizer(timeline.events!);
}
@@ -829,22 +887,30 @@ void main() {
});
group('RefreshRateSummarizer tests', () {
const double kCompareDelta = 0.01;
RefreshRateSummary summarizeRefresh(List<Map<String, dynamic>> traceEvents) {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': traceEvents,
});
final Timeline timeline = Timeline.fromJson(<String, dynamic>{'traceEvents': traceEvents});
return RefreshRateSummary(vsyncEvents: timeline.events!);
}
List<Map<String, dynamic>> populateEvents({required int numberOfEvents, required int startTime, required int interval, required int margin}) {
List<Map<String, dynamic>> populateEvents({
required int numberOfEvents,
required int startTime,
required int interval,
required int margin,
}) {
final List<Map<String, dynamic>> events = <Map<String, dynamic>>[];
int startTimeInNanoseconds = startTime;
for (int i = 0; i < numberOfEvents; i ++) {
final int randomMargin = margin >= 1 ? (-margin + Random().nextInt(margin*2)) : 0;
for (int i = 0; i < numberOfEvents; i++) {
final int randomMargin = margin >= 1 ? (-margin + Random().nextInt(margin * 2)) : 0;
final int endTime = startTimeInNanoseconds + interval + randomMargin;
events.add(vsyncCallback(0, startTime: startTimeInNanoseconds.toString(), endTime: endTime.toString()));
events.add(
vsyncCallback(
0,
startTime: startTimeInNanoseconds.toString(),
endTime: endTime.toString(),
),
);
startTimeInNanoseconds = endTime;
}
return events;
@@ -855,11 +921,12 @@ void main() {
const int intervalInNanoseconds = 33333333;
// allow some margins
const int margin = 3000000;
final List<Map<String, dynamic>> events = populateEvents(numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final List<Map<String, dynamic>> events = populateEvents(
numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, closeTo(100, kCompareDelta));
expect(summary.percentageOf60HzFrames, 0);
@@ -873,11 +940,12 @@ void main() {
const int intervalInNanoseconds = 16666666;
// allow some margins
const int margin = 1200000;
final List<Map<String, dynamic>> events = populateEvents(numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final List<Map<String, dynamic>> events = populateEvents(
numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, 0);
@@ -892,11 +960,12 @@ void main() {
const int intervalInNanoseconds = 11111111;
// allow some margins
const int margin = 500000;
final List<Map<String, dynamic>> events = populateEvents(numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final List<Map<String, dynamic>> events = populateEvents(
numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, 0);
@@ -911,11 +980,12 @@ void main() {
const int intervalInNanoseconds = 8333333;
// allow some margins
const int margin = 300000;
final List<Map<String, dynamic>> events = populateEvents(numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final List<Map<String, dynamic>> events = populateEvents(
numberOfEvents: 100,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: margin,
);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, 0);
expect(summary.percentageOf60HzFrames, 0);
@@ -927,11 +997,12 @@ void main() {
test('Identify illegal refresh rates.', () async {
const int startTimeInNanoseconds = 2750850055430;
const int intervalInNanoseconds = 10000000;
final List<Map<String, dynamic>> events = populateEvents(numberOfEvents: 1,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: 0,
);
final List<Map<String, dynamic>> events = populateEvents(
numberOfEvents: 1,
startTime: startTimeInNanoseconds,
interval: intervalInNanoseconds,
margin: 0,
);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, 0);
expect(summary.percentageOf60HzFrames, 0);
@@ -942,7 +1013,6 @@ void main() {
});
test('Mixed refresh rates.', () async {
final List<Map<String, dynamic>> events = <Map<String, dynamic>>[];
const int num30Hz = 10;
const int num60Hz = 20;
@@ -953,54 +1023,45 @@ void main() {
const int totalFrames = num30Hz + num60Hz + num80Hz + num90Hz + num120Hz + numIllegal;
// Add 30hz frames
events.addAll(populateEvents(numberOfEvents: num30Hz,
startTime: 0,
interval: 32000000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: num30Hz, startTime: 0, interval: 32000000, margin: 0),
);
// Add 60hz frames
events.addAll(populateEvents(numberOfEvents: num60Hz,
startTime: 0,
interval: 16000000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: num60Hz, startTime: 0, interval: 16000000, margin: 0),
);
// Add 80hz frames
events.addAll(populateEvents(numberOfEvents: num80Hz,
startTime: 0,
interval: 12000000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: num80Hz, startTime: 0, interval: 12000000, margin: 0),
);
// Add 90hz frames
events.addAll(populateEvents(numberOfEvents: num90Hz,
startTime: 0,
interval: 11000000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: num90Hz, startTime: 0, interval: 11000000, margin: 0),
);
// Add 120hz frames
events.addAll(populateEvents(numberOfEvents: num120Hz,
startTime: 0,
interval: 8000000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: num120Hz, startTime: 0, interval: 8000000, margin: 0),
);
// Add illegal refresh rate frames
events.addAll(populateEvents(numberOfEvents: numIllegal,
startTime: 0,
interval: 60000,
margin: 0,
));
events.addAll(
populateEvents(numberOfEvents: numIllegal, startTime: 0, interval: 60000, margin: 0),
);
final RefreshRateSummary summary = summarizeRefresh(events);
final RefreshRateSummary summary = summarizeRefresh(events);
expect(summary.percentageOf30HzFrames, closeTo(num30Hz/totalFrames*100, kCompareDelta));
expect(summary.percentageOf60HzFrames, closeTo(num60Hz/totalFrames*100, kCompareDelta));
expect(summary.percentageOf80HzFrames, closeTo(num80Hz/totalFrames*100, kCompareDelta));
expect(summary.percentageOf90HzFrames, closeTo(num90Hz/totalFrames*100, kCompareDelta));
expect(summary.percentageOf120HzFrames, closeTo(num120Hz/totalFrames*100, kCompareDelta));
expect(summary.percentageOf30HzFrames, closeTo(num30Hz / totalFrames * 100, kCompareDelta));
expect(summary.percentageOf60HzFrames, closeTo(num60Hz / totalFrames * 100, kCompareDelta));
expect(summary.percentageOf80HzFrames, closeTo(num80Hz / totalFrames * 100, kCompareDelta));
expect(summary.percentageOf90HzFrames, closeTo(num90Hz / totalFrames * 100, kCompareDelta));
expect(
summary.percentageOf120HzFrames,
closeTo(num120Hz / totalFrames * 100, kCompareDelta),
);
expect(summary.framesWithIllegalRefreshRate, isNotEmpty);
expect(summary.framesWithIllegalRefreshRate.length, 10);
});

View File

@@ -21,9 +21,7 @@ void main() {
'tdur': 245,
'ts': 456,
'tts': 567,
'args': <String, dynamic>{
'arg1': true,
},
'args': <String, dynamic>{'arg1': true},
},
// Tests that we don't choke on missing data
<String, dynamic>{},
@@ -60,14 +58,8 @@ void main() {
test('sorts JSON', () {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': <Map<String, dynamic>>[
<String, dynamic>{
'name': 'test event 1',
'ts': 457,
},
<String, dynamic>{
'name': 'test event 2',
'ts': 456,
},
<String, dynamic>{'name': 'test event 1', 'ts': 457},
<String, dynamic>{'name': 'test event 2', 'ts': 456},
],
});
@@ -81,22 +73,10 @@ void main() {
test('sorts JSON nulls first', () {
final Timeline timeline = Timeline.fromJson(<String, dynamic>{
'traceEvents': <Map<String, dynamic>>[
<String, dynamic>{
'name': 'test event 0',
'ts': null,
},
<String, dynamic>{
'name': 'test event 1',
'ts': 457,
},
<String, dynamic>{
'name': 'test event 2',
'ts': 456,
},
<String, dynamic>{
'name': 'test event 3',
'ts': null,
},
<String, dynamic>{'name': 'test event 0', 'ts': null},
<String, dynamic>{'name': 'test event 1', 'ts': 457},
<String, dynamic>{'name': 'test event 2', 'ts': 456},
<String, dynamic>{'name': 'test event 3', 'ts': null},
],
});

View File

@@ -9,15 +9,24 @@ import '../../common.dart';
void main() {
group('WaitForCondition', () {
test('WaitForCondition serialize', () {
expect(
const WaitForCondition(NoTransientCallbacks()).serialize(),
<String, String>{'command': 'waitForCondition', 'conditionName': 'NoTransientCallbacksCondition'});
expect(const WaitForCondition(NoTransientCallbacks()).serialize(), <String, String>{
'command': 'waitForCondition',
'conditionName': 'NoTransientCallbacksCondition',
});
});
test('WaitForCondition serialize with timeout', () {
expect(
const WaitForCondition(NoTransientCallbacks(), timeout: Duration(milliseconds: 10)).serialize(),
<String, String>{'command': 'waitForCondition', 'timeout': '10', 'conditionName': 'NoTransientCallbacksCondition'});
const WaitForCondition(
NoTransientCallbacks(),
timeout: Duration(milliseconds: 10),
).serialize(),
<String, String>{
'command': 'waitForCondition',
'timeout': '10',
'conditionName': 'NoTransientCallbacksCondition',
},
);
});
test('WaitForCondition deserialize', () {
@@ -43,22 +52,16 @@ void main() {
});
test('WaitForCondition requiresRootWidget', () {
expect(
const WaitForCondition(NoTransientCallbacks())
.requiresRootWidgetAttached,
isTrue);
expect(
const WaitForCondition(FirstFrameRasterized())
.requiresRootWidgetAttached,
isFalse);
});
expect(const WaitForCondition(NoTransientCallbacks()).requiresRootWidgetAttached, isTrue);
expect(const WaitForCondition(FirstFrameRasterized()).requiresRootWidgetAttached, isFalse);
});
});
group('NoTransientCallbacksCondition', () {
test('NoTransientCallbacksCondition serialize', () {
expect(
const NoTransientCallbacks().serialize(),
<String, String>{'conditionName': 'NoTransientCallbacksCondition'});
expect(const NoTransientCallbacks().serialize(), <String, String>{
'conditionName': 'NoTransientCallbacksCondition',
});
});
test('NoTransientCallbacksCondition deserialize', () {
@@ -72,9 +75,15 @@ void main() {
test('NoTransientCallbacksCondition deserialize error', () {
expect(
() => NoTransientCallbacks.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(predicate<SerializationException>((SerializationException e) =>
e.message == 'Error occurred during deserializing the NoTransientCallbacksCondition JSON string: {conditionName: Unknown}')));
() => NoTransientCallbacks.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(
predicate<SerializationException>(
(SerializationException e) =>
e.message ==
'Error occurred during deserializing the NoTransientCallbacksCondition JSON string: {conditionName: Unknown}',
),
),
);
});
});
@@ -96,17 +105,23 @@ void main() {
test('NoPendingFrameCondition deserialize error', () {
expect(
() => NoPendingFrame.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(predicate<SerializationException>((SerializationException e) =>
e.message == 'Error occurred during deserializing the NoPendingFrameCondition JSON string: {conditionName: Unknown}')));
() => NoPendingFrame.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(
predicate<SerializationException>(
(SerializationException e) =>
e.message ==
'Error occurred during deserializing the NoPendingFrameCondition JSON string: {conditionName: Unknown}',
),
),
);
});
});
group('FirstFrameRasterizedCondition', () {
test('FirstFrameRasterizedCondition serialize', () {
expect(
const FirstFrameRasterized().serialize(),
<String, String>{'conditionName': 'FirstFrameRasterizedCondition'});
expect(const FirstFrameRasterized().serialize(), <String, String>{
'conditionName': 'FirstFrameRasterizedCondition',
});
});
test('FirstFrameRasterizedCondition deserialize', () {
@@ -120,9 +135,15 @@ void main() {
test('FirstFrameRasterizedCondition deserialize error', () {
expect(
() => FirstFrameRasterized.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(predicate<SerializationException>((SerializationException e) =>
e.message == 'Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: {conditionName: Unknown}')));
() => FirstFrameRasterized.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(
predicate<SerializationException>(
(SerializationException e) =>
e.message ==
'Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: {conditionName: Unknown}',
),
),
);
});
test('FirstFrameRasterizedCondition requiresRootWidget', () {
@@ -132,8 +153,7 @@ void main() {
group('CombinedCondition', () {
test('CombinedCondition serialize', () {
const CombinedCondition combinedCondition =
CombinedCondition(<SerializableWaitCondition>[
const CombinedCondition combinedCondition = CombinedCondition(<SerializableWaitCondition>[
NoTransientCallbacks(),
NoPendingFrame(),
]);
@@ -170,20 +190,18 @@ void main() {
'conditions':
'[{"conditionName":"NoPendingFrameCondition"},{"conditionName":"NoTransientCallbacksCondition"}]',
};
final CombinedCondition condition =
CombinedCondition.deserialize(jsonMap);
final CombinedCondition condition = CombinedCondition.deserialize(jsonMap);
expect(
condition.conditions,
equals(<SerializableWaitCondition>[
const NoPendingFrame(),
const NoTransientCallbacks(),
]));
condition.conditions,
equals(<SerializableWaitCondition>[const NoPendingFrame(), const NoTransientCallbacks()]),
);
expect(condition.serialize(), jsonMap);
});
test('CombinedCondition deserialize - no condition list', () {
final CombinedCondition condition =
CombinedCondition.deserialize(<String, String>{'conditionName': 'CombinedCondition',});
final CombinedCondition condition = CombinedCondition.deserialize(<String, String>{
'conditionName': 'CombinedCondition',
});
expect(condition.conditions, equals(<SerializableWaitCondition>[]));
expect(condition.serialize(), <String, String>{
'conditionName': 'CombinedCondition',
@@ -193,22 +211,34 @@ void main() {
test('CombinedCondition deserialize error', () {
expect(
() => CombinedCondition.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(predicate<SerializationException>((SerializationException e) =>
e.message == 'Error occurred during deserializing the CombinedCondition JSON string: {conditionName: Unknown}')));
() => CombinedCondition.deserialize(<String, String>{'conditionName': 'Unknown'}),
throwsA(
predicate<SerializationException>(
(SerializationException e) =>
e.message ==
'Error occurred during deserializing the CombinedCondition JSON string: {conditionName: Unknown}',
),
),
);
});
test('CombinedCondition deserialize error - Unknown condition type', () {
expect(
() {
return CombinedCondition.deserialize(<String, String>{
'conditionName': 'CombinedCondition',
'conditions':
'[{"conditionName":"UnknownCondition"},{"conditionName":"NoTransientCallbacksCondition"}]',
});
},
throwsA(predicate<SerializationException>((SerializationException e) =>
e.message == 'Unsupported wait condition UnknownCondition in the JSON string {conditionName: UnknownCondition}')));
() {
return CombinedCondition.deserialize(<String, String>{
'conditionName': 'CombinedCondition',
'conditions':
'[{"conditionName":"UnknownCondition"},{"conditionName":"NoTransientCallbacksCondition"}]',
});
},
throwsA(
predicate<SerializationException>(
(SerializationException e) =>
e.message ==
'Unsupported wait condition UnknownCondition in the JSON string {conditionName: UnknownCondition}',
),
),
);
});
});
}

View File

@@ -39,7 +39,7 @@ void main() {
() => driver.sendCommand(const GetHealth()),
_throwsDriverErrorWithMessage(
'FlutterDriver command GetHealth failed due to a remote error.\n'
'Command sent: {"command":"get_health"}'
'Command sent: {"command":"get_health"}',
),
);
});
@@ -69,9 +69,7 @@ void main() {
''';
expect(
() => driver.sendCommand(const GetHealth()),
_throwsDriverErrorWithMessage(
'Error in Flutter application: test error message'
),
_throwsDriverErrorWithMessage('Error in Flutter application: test error message'),
);
});
@@ -94,20 +92,22 @@ void main() {
}
Matcher _throwsDriverErrorWithMessage(String expectedMessage) {
return throwsA(allOf(
isA<DriverError>(),
predicate<DriverError>((DriverError error) {
final String actualMessage = error.message;
return actualMessage == expectedMessage;
}, 'contains message: $expectedMessage'),
));
return throwsA(
allOf(
isA<DriverError>(),
predicate<DriverError>((DriverError error) {
final String actualMessage = error.message;
return actualMessage == expectedMessage;
}, 'contains message: $expectedMessage'),
),
);
}
Matcher _throwsDriverErrorWithDataString(String dataType, String dataString) {
return _throwsDriverErrorWithMessage(
'Received malformed response from the FlutterDriver extension.\n'
'Expected a JSON map containing a "response" field and, optionally, an '
'"isError" field, but got $dataType: $dataString'
'"isError" field, but got $dataType: $dataString',
);
}

View File

@@ -22,8 +22,7 @@ void main() {
});
test('web_extension should register a function', () {
expect(() => registerWebServiceExtension(call),
returnsNormally);
expect(() => registerWebServiceExtension(call), returnsNormally);
expect(_window.hasProperty(r'$flutterDriver'.toJS).toDart, true);
expect(_window.getProperty(r'$flutterDriver'.toJS), isNotNull);