22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import 'dart:js_util' as js_util;
6+
57import 'package:test/bootstrap/browser.dart' ;
68import 'package:test/test.dart' ;
79import 'package:ui/src/engine.dart' ;
@@ -141,20 +143,23 @@ void testMain() {
141143 // Emulate WebGL context loss.
142144 final DomCanvasElement canvas =
143145 surface.htmlElement.children.single as DomCanvasElement ;
144- final dynamic ctx = canvas.getContext ('webgl2' );
145- expect (ctx, isNotNull);
146- final dynamic loseContextExtension =
147- ctx.getExtension ('WEBGL_lose_context' );
148- loseContextExtension.loseContext ();
146+ final Object ctx = canvas.getContext ('webgl2' )! ;
147+ final Object loseContextExtension = js_util.callMethod (
148+ ctx,
149+ 'getExtension' ,
150+ < String > ['WEBGL_lose_context' ],
151+ );
152+ js_util.callMethod (loseContextExtension, 'loseContext' , const < void > []);
149153
150154 // Pump a timer to allow the "lose context" event to propagate.
151155 await Future <void >.delayed (Duration .zero);
152156 // We don't create a new GL context until the context is restored.
153157 expect (surface.debugContextLost, isTrue);
154- expect (ctx.isContextLost (), isTrue);
158+ final bool isContextLost = js_util.callMethod <bool >(ctx, 'isContextLost' , const < void > []);
159+ expect (isContextLost, isTrue);
155160
156161 // Emulate WebGL context restoration.
157- loseContextExtension. restoreContext ( );
162+ js_util. callMethod (loseContextExtension, 'restoreContext' , const < void > [] );
158163
159164 // Pump a timer to allow the "restore context" event to propagate.
160165 await Future <void >.delayed (Duration .zero);
@@ -165,9 +170,8 @@ void testMain() {
165170 // A new context is created.
166171 expect (afterContextLost, isNot (same (before)));
167172 },
168- // Firefox and Safari don't have the WEBGL_lose_context extension.
169- // TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
170- skip: true ,
173+ // Firefox can't create a WebGL2 context in headless mode.
174+ skip: isFirefox,
171175 );
172176
173177 // Regression test for https://github.com/flutter/flutter/issues/75286
0 commit comments