Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/web_ui/lib/ui_web/src/ui_web/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ bool get debugEmulateFlutterTesterEnvironment =>
set debugEmulateFlutterTesterEnvironment(bool value) {
_debugEmulateFlutterTesterEnvironment = value;
if (_debugEmulateFlutterTesterEnvironment) {
ensureImplicitViewInitialized();
const ui.Size logicalSize = ui.Size(800.0, 600.0);
window.debugPhysicalSizeOverride = logicalSize * window.devicePixelRatio;
final EngineFlutterWindow? implicitView = EnginePlatformDispatcher.instance.implicitView;
implicitView?.debugPhysicalSizeOverride = logicalSize * implicitView.devicePixelRatio;
}
debugDisableFontFallbacks = value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/backdrop_filter_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 500);

void testMain() {
group('BackdropFilter', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);
EngineFlutterDisplay.instance.debugOverrideDevicePixelRatio(1.0);

test('blur renders to the edges', () async {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ui.Rect kDefaultRegion = ui.Rect.fromLTRB(0, 0, 500, 250);

void testMain() {
group('CkCanvas', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

setUp(() {
renderer.fontCollection.debugResetFallbackFonts();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/color_filter_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

void testMain() {
group('ColorFilter', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('ColorFilter.matrix applies a color filter', () async {
final LayerSceneBuilder builder = LayerSceneBuilder();
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/test/canvaskit/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export '../common/rendering.dart' show renderScene;
const MethodCodec codec = StandardMethodCodec();

/// Common test setup for all CanvasKit unit-tests.
void setUpCanvasKitTest() {
void setUpCanvasKitTest({bool withImplicitView = false}) {
setUpUnitTests(
withImplicitView: withImplicitView,
emulateTesterEnvironment: false,
setUpTestViewDimensions: false,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {

void testMain() {
group('$HtmlViewEmbedder', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

setUp(() {
EngineFlutterDisplay.instance.debugOverrideDevicePixelRatio(1);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testMain() {
return filters;
}

setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

group('ImageFilters', () {
test('can be constructed', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testMain() {
ui_web.debugEmulateFlutterTesterEnvironment = true;

group('flutter_tester emulation', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('defaults to FlutterTest font family',
() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/frame_timings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {

void testMain() {
group('frame timings', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('collects frame timings', () async {
await runFrameTimingsTest();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/image_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {

void testMain() {
group('CanvasKit Images', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

tearDown(() {
mockHttpFetchResponseFactory = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/layer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {

void testMain() {
group('CanvasKit', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

// Regression test for https://github.com/flutter/flutter/issues/63715
test('TransformLayer prerolls correctly', () async {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/linear_gradient_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

void testMain() {
group('Linear', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('is correctly rendered', () async {
final CkPictureRecorder recorder = CkPictureRecorder();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/multi_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {

void testMain() {
group('CanvasKit', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

late LayerScene scene;

Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/no_create_image_bitmap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);
/// Test that we can render even if `createImageBitmap` is not supported.
void testMain() {
group('CanvasKit', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);
setUp(() async {
EngineFlutterDisplay.instance.debugOverrideDevicePixelRatio(1.0);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/render_canvas_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {

void testMain() {
group('$RenderCanvasFactory', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('getCanvas', () {
final RenderCanvasFactory factory = RenderCanvasFactory();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {
// semantics.
Future<void> testMain() async {
group('CanvasKit semantics', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

runSemanticsTests();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/shader_mask_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

void testMain() {
group('ShaderMask', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('Renders sweep gradient with color blend', () async {
final LayerSceneBuilder builder = LayerSceneBuilder();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/sweep_gradient_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

void testMain() {
group('SweepGradient', () {
setUpCanvasKitTest();
setUpCanvasKitTest(withImplicitView: true);

test('is correctly rendered', () async {
final CkPictureRecorder recorder = CkPictureRecorder();
Expand Down
27 changes: 17 additions & 10 deletions lib/web_ui/test/common/test_initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,28 @@ import 'fake_asset_manager.dart';
import 'rendering.dart';

void setUpUnitTests({
bool withImplicitView = false,
bool emulateTesterEnvironment = true,
bool setUpTestViewDimensions = true,
}) {
late final FakeAssetScope debugFontsScope;
setUpAll(() async {
// The implicit view is needed for `debugEmulateFlutterTesterEnvironment`,
// `flutterViewEmbedder`, and `debugPhysicalSizeOverride`.
engine.ensureImplicitViewInitialized();

if (emulateTesterEnvironment) {
ui_web.debugEmulateFlutterTesterEnvironment = true;
}

debugFontsScope = configureDebugFontsAssetScope(fakeAssetManager);
debugOnlyAssetManager = fakeAssetManager;
await bootstrapAndRunApp();
await bootstrapAndRunApp(withImplicitView: withImplicitView);
engine.renderer.fontCollection.fontFallbackManager?.downloadQueue.fallbackFontUrlPrefixOverride = 'assets/fallback_fonts/';

if (setUpTestViewDimensions) {
// Force-initialize FlutterViewEmbedder so it doesn't overwrite test pixel ratio.
engine.ensureFlutterViewEmbedderInitialized();

// The following parameters are hard-coded in Flutter's test embedder. Since
// we don't have an embedder yet this is the lowest-most layer we can put
// this stuff in.
const double devicePixelRatio = 3.0;
engine.EngineFlutterDisplay.instance.debugOverrideDevicePixelRatio(devicePixelRatio);
engine.EnginePlatformDispatcher.instance.implicitView!.debugPhysicalSizeOverride =
engine.EnginePlatformDispatcher.instance.implicitView?.debugPhysicalSizeOverride =
const ui.Size(800 * devicePixelRatio, 600 * devicePixelRatio);
engine.scheduleFrameCallback = () {};
}
Expand All @@ -54,8 +48,21 @@ void setUpUnitTests({
});
}

Future<void> bootstrapAndRunApp() async {
Future<void> bootstrapAndRunApp({bool withImplicitView = false}) async {
final Completer<void> completer = Completer<void>();
await ui_web.bootstrapEngine(runApp: () => completer.complete());
await completer.future;
if (!withImplicitView) {
_disableImplicitView();
}
}

void _disableImplicitView() {
// TODO(mdebbar): Instead of disabling the implicit view, we should be able to
// initialize tests without an implicit view to begin with.
// https://github.com/flutter/flutter/issues/138906
final engine.EngineFlutterWindow? implicitView = engine.EnginePlatformDispatcher.instance.implicitView;
if (implicitView != null) {
engine.EnginePlatformDispatcher.instance.viewManager.disposeAndUnregisterView(implicitView.viewId);
}
}
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
}

Future<void> testMain() async {
await bootstrapAndRunApp();
await bootstrapAndRunApp(withImplicitView: true);

group('EngineCanvas', () {
late MockEngineCanvas mockCanvas;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/composition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ GloballyPositionedTextEditingStrategy _enableEditingStrategy({
}

Future<void> testMain() async {
await bootstrapAndRunApp();
await bootstrapAndRunApp(withImplicitView: true);

const String fakeComposingText = 'ImComposingText';

Expand Down
11 changes: 6 additions & 5 deletions lib/web_ui/test/engine/history_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:ui/ui_web/src/ui_web.dart';

import '../common/matchers.dart';
import '../common/spy.dart';
import '../common/test_initialization.dart';

EngineFlutterWindow get implicitView =>
EnginePlatformDispatcher.instance.implicitView!;
Expand All @@ -36,8 +37,8 @@ void main() {
}

void testMain() {
setUpAll(() {
ensureImplicitViewInitialized();
setUpAll(() async {
await bootstrapAndRunApp(withImplicitView: true);
});

test('createHistoryForExistingState', () {
Expand Down Expand Up @@ -745,7 +746,7 @@ void testMain() {

Future<void> routeUpdated(String routeName) {
final Completer<void> completer = Completer<void>();
implicitView.sendPlatformMessage(
EnginePlatformDispatcher.instance.sendPlatformMessage(
'flutter/navigation',
codec.encodeMethodCall(MethodCall(
'routeUpdated',
Expand All @@ -758,7 +759,7 @@ Future<void> routeUpdated(String routeName) {

Future<void> routeInformationUpdated(String location, dynamic state) {
final Completer<void> completer = Completer<void>();
implicitView.sendPlatformMessage(
EnginePlatformDispatcher.instance.sendPlatformMessage(
'flutter/navigation',
codec.encodeMethodCall(MethodCall(
'routeInformationUpdated',
Expand All @@ -771,7 +772,7 @@ Future<void> routeInformationUpdated(String location, dynamic state) {

Future<void> systemNavigatorPop() {
final Completer<void> completer = Completer<void>();
implicitView.sendPlatformMessage(
EnginePlatformDispatcher.instance.sendPlatformMessage(
'flutter/platform',
codec.encodeMethodCall(const MethodCall('SystemNavigator.pop')),
(_) => completer.complete(),
Expand Down
77 changes: 49 additions & 28 deletions lib/web_ui/test/engine/navigation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,71 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:typed_data';

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart' as engine;
import 'package:ui/src/engine/window.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;

const engine.MethodCodec codec = engine.JSONMethodCodec();
import '../common/test_initialization.dart';

engine.EngineFlutterWindow get implicitView =>
engine.EnginePlatformDispatcher.instance.implicitView!;
const MethodCodec codec = JSONMethodCodec();

EngineFlutterWindow get implicitView =>
EnginePlatformDispatcher.instance.implicitView!;

void main() {
internalBootstrapBrowserTest(() => testMain);
}

void testMain() {
engine.TestUrlStrategy? strategy;
group('without implicit view', () {
test('Handles navigation gracefully when no implicit view exists', () async {
expect(EnginePlatformDispatcher.instance.implicitView, isNull);

setUpAll(() {
ensureImplicitViewInitialized();
final Completer<ByteData?> completer = Completer<ByteData?>();
ui.PlatformDispatcher.instance.sendPlatformMessage(
'flutter/navigation',
codec.encodeMethodCall(const MethodCall(
'routeUpdated',
<String, dynamic>{'routeName': '/foo'},
)),
(ByteData? response) => completer.complete(response),
);
final ByteData? response = await completer.future;
expect(response, isNull);
});
});

setUp(() async {
strategy = engine.TestUrlStrategy();
await implicitView.debugInitializeHistory(strategy, useSingle: true);
});
group('with implicit view', () {
late TestUrlStrategy strategy;

tearDown(() async {
strategy = null;
await implicitView.resetHistory();
});
setUpAll(() async {
await bootstrapAndRunApp(withImplicitView: true);
});

setUp(() async {
strategy = TestUrlStrategy();
await implicitView.debugInitializeHistory(strategy, useSingle: true);
});

tearDown(() async {
await implicitView.resetHistory();
});

test('Tracks pushed, replaced and popped routes', () async {
final Completer<void> completer = Completer<void>();
ui.PlatformDispatcher.instance.sendPlatformMessage(
'flutter/navigation',
codec.encodeMethodCall(const engine.MethodCall(
'routeUpdated',
<String, dynamic>{'routeName': '/foo'},
)),
(_) => completer.complete(),
);
await completer.future;
expect(strategy!.getPath(), '/foo');
test('Tracks pushed, replaced and popped routes', () async {
final Completer<void> completer = Completer<void>();
ui.PlatformDispatcher.instance.sendPlatformMessage(
'flutter/navigation',
codec.encodeMethodCall(const MethodCall(
'routeUpdated',
<String, dynamic>{'routeName': '/foo'},
)),
(_) => completer.complete(),
);
await completer.future;
expect(strategy.getPath(), '/foo');
});
});
}
1 change: 1 addition & 0 deletions lib/web_ui/test/engine/recording_canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {

void testMain() {
setUpUnitTests(
withImplicitView: true,
setUpTestViewDimensions: false,
);

Expand Down
Loading