Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web_benchmarks] Make package compatible with Chromium v89+ #518

Merged
merged 15 commits into from
Feb 17, 2022
Merged
Prev Previous commit
Next Next commit
Add browser.dart unit tests and testing information.
ditman committed Feb 15, 2022
commit 634f5e3e4c0c75f172ddf2890b5c0d83caba9e82
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2013 The Flutter 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_test/flutter_test.dart';

void main() {
test('Tell the user how to run tests within "testing" directory', () {
print('---');
print('This package also has client-server tests.');
print('Run `dart testing/web_benchmarks_test.dart` to run those.');
print('---');
});
}
55 changes: 55 additions & 0 deletions packages/web_benchmarks/test/src/browser_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2013 The Flutter 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_test/flutter_test.dart';

import 'package:web_benchmarks/src/browser.dart';

import 'browser_test_json_samples.dart';

void main() {
group('BlinkTraceEvent works with Chrome 89+', () {
ditman marked this conversation as resolved.
Show resolved Hide resolved
// Used to test 'false' results
final BlinkTraceEvent unrelatedPhX =
BlinkTraceEvent.fromJson(unrelatedPhXJson);
final BlinkTraceEvent anotherUnrelated =
BlinkTraceEvent.fromJson(anotherUnrelatedJson);

test('isBeginFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(beginMainFrameJson);

expect(event.isBeginFrame, isTrue);
expect(unrelatedPhX.isBeginFrame, isFalse);
expect(anotherUnrelated.isBeginFrame, isFalse);
});

test('isUpdateAllLifecyclePhases', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(updateLifecycleJson);

expect(event.isUpdateAllLifecyclePhases, isTrue);
expect(unrelatedPhX.isUpdateAllLifecyclePhases, isFalse);
expect(anotherUnrelated.isUpdateAllLifecyclePhases, isFalse);
});

test('isBeginMeasuredFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(beginMeasuredFrameJson);

expect(event.isBeginMeasuredFrame, isTrue);
expect(unrelatedPhX.isBeginMeasuredFrame, isFalse);
expect(anotherUnrelated.isBeginMeasuredFrame, isFalse);
});

test('isEndMeasuredFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(endMeasuredFrameJson);

expect(event.isEndMeasuredFrame, isTrue);
expect(unrelatedPhX.isEndMeasuredFrame, isFalse);
expect(anotherUnrelated.isEndMeasuredFrame, isFalse);
});
});
}
101 changes: 101 additions & 0 deletions packages/web_benchmarks/test/src/browser_test_json_samples.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2013 The Flutter 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:convert' show jsonDecode;

// JSON Event samples taken from running an instrumented version of the
// integration tests of this package that dumped all the data as captured.

/// To test isBeginFrame.
final Map<String, dynamic> beginMainFrameJson = jsonDecode('''
ditman marked this conversation as resolved.
Show resolved Hide resolved
{
"args": {
"frameTime": 2338687248768
},
"cat": "blink",
"dur": 6836,
"name": "WebFrameWidgetImpl::BeginMainFrame",
"ph": "X",
"pid": 1367081,
"tdur": 393,
"tid": 1,
"ts": 2338687258440,
"tts": 375499
}
''');

/// To test isUpdateAllLifecyclePhases.
final Map<String, dynamic> updateLifecycleJson = jsonDecode('''
{
"args": {},
"cat": "blink",
"dur": 103,
"name": "WebFrameWidgetImpl::UpdateLifecycle",
"ph": "X",
"pid": 1367081,
"tdur": 102,
"tid": 1,
"ts": 2338687265284,
"tts": 375900
}
''');

/// To test isBeginMeasuredFrame.
final Map<String, dynamic> beginMeasuredFrameJson = jsonDecode('''
{
"args": {},
"cat": "blink.user_timing",
"id": "0xea2a8b45",
"name": "measured_frame",
"ph": "b",
"pid": 1367081,
"scope": "blink.user_timing",
"tid": 1,
"ts": 2338687265932
}
''');

/// To test isEndMeasuredFrame.
final Map<String, dynamic> endMeasuredFrameJson = jsonDecode('''
{
"args": {},
"cat": "blink.user_timing",
"id": "0xea2a8b45",
"name": "measured_frame",
"ph": "e",
"pid": 1367081,
"scope": "blink.user_timing",
"tid": 1,
"ts": 2338687440485
}
''');

final Map<String, dynamic> unrelatedPhXJson = jsonDecode('''
{
"args": {},
"cat": "blink,rail",
"dur": 2,
"name": "PageAnimator::serviceScriptedAnimations",
"ph": "X",
"pid": 1367081,
"tdur": 2,
"tid": 1,
"ts": 2338691143317,
"tts": 1685405
}
''');

final Map<String, dynamic> anotherUnrelatedJson = jsonDecode('''
{
"args": {
"sort_index": -1
},
"cat": "__metadata",
"name": "thread_sort_index",
"ph": "M",
"pid": 1367081,
"tid": 1,
"ts": 2338692906482
}
''');
30 changes: 30 additions & 0 deletions packages/web_benchmarks/testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## How to run the `testing` directory tests

The tests contained in this directory use a client-server model, similar to what
the integration_test package does. In order to run the tests inside `testing`,
do the following:

* Install Chrome in a way that [tests can find it](https://github.com/flutter/packages/blob/a5a4479e176c5e909dd5d961c2c79b61ce1bf1bd/packages/web_benchmarks/lib/src/browser.dart#L216).

* Fetch dependencies for the `test_app` directory inside `testing`:

```
$ cd testing/test_app
$ flutter pub get
```

* Fetch dependencies for the `web_benchmarks` directory:

```
$ cd ../..
$ flutter pub get
```

* Run the tests with `dart`:

```
$ dart testing/web_benchmarks_test.dart
```

_(If the above stops working, take a look at what the [`web_benchmarks_test` Cirrus step](https://github.com/flutter/packages/blob/a5a4479e176c5e909dd5d961c2c79b61ce1bf1bd/.cirrus.yml#L102-L113)
is currently doing, and update this document accordingly!)_