Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Prev Previous commit
Next Next commit
Add test for view.resize method.
  • Loading branch information
ditman committed Feb 14, 2024
commit a015985eedb9f9cd9c74b679aa8d7859b1aadcbe
24 changes: 23 additions & 1 deletion lib/web_ui/test/engine/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ Future<void> testMain() async {
expect(view.physicalSize, const ui.Size(25.0, 25.0));
expect(metricsChangedCount, 0);

// Resize the host to 20x20.
// Simulate the browser resizing the host to 20x20.
host.style
..width = '20px'
..height = '20px';
Expand All @@ -632,5 +632,27 @@ Future<void> testMain() async {
// The view should maintain the debugPhysicalSizeOverride.
expect(view.physicalSize, const ui.Size(100.0, 100.0));
});

test('can resize host', () async {
// Reset host style, so it tightly wraps the rootElement of the view.
// This style change will trigger a "onResize" event when all the DOM
// operations settle that we must await before taking measurements.
host.style
..display = 'inline-block'
..width = 'auto'
..height = 'auto';

// Resize the host to 20x20 (physical pixels).
view.resize(const ui.Size.square(50));

await view.onResize.first;

// The host tightly wraps the rootElement:
expect(view.physicalSize, const ui.Size(50.0, 50.0));

// Inspect the rootElement directly:
expect(view.dom.rootElement.clientWidth, 50 / 2.5);
expect(view.dom.rootElement.clientHeight, 50 / 2.5);
});
});
}