Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all 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
24 changes: 14 additions & 10 deletions lib/web_ui/test/canvaskit/surface_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:js_util' as js_util;

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
Expand Down Expand Up @@ -141,20 +143,23 @@ void testMain() {
// Emulate WebGL context loss.
final DomCanvasElement canvas =
surface.htmlElement.children.single as DomCanvasElement;
final dynamic ctx = canvas.getContext('webgl2');
expect(ctx, isNotNull);
final dynamic loseContextExtension =
ctx.getExtension('WEBGL_lose_context');
loseContextExtension.loseContext();
final Object ctx = canvas.getContext('webgl2')!;
final Object loseContextExtension = js_util.callMethod(
ctx,
'getExtension',
<String>['WEBGL_lose_context'],
);
js_util.callMethod(loseContextExtension, 'loseContext', const <void>[]);

// Pump a timer to allow the "lose context" event to propagate.
await Future<void>.delayed(Duration.zero);
// We don't create a new GL context until the context is restored.
expect(surface.debugContextLost, isTrue);
expect(ctx.isContextLost(), isTrue);
final bool isContextLost = js_util.callMethod<bool>(ctx, 'isContextLost', const <void>[]);
expect(isContextLost, isTrue);

// Emulate WebGL context restoration.
loseContextExtension.restoreContext();
js_util.callMethod(loseContextExtension, 'restoreContext', const <void>[]);

// Pump a timer to allow the "restore context" event to propagate.
await Future<void>.delayed(Duration.zero);
Expand All @@ -165,9 +170,8 @@ void testMain() {
// A new context is created.
expect(afterContextLost, isNot(same(before)));
},
// Firefox and Safari don't have the WEBGL_lose_context extension.
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
skip: true,
// Firefox can't create a WebGL2 context in headless mode.
skip: isFirefox,
);

// Regression test for https://github.com/flutter/flutter/issues/75286
Expand Down