From 92f2314ea58cb74d667c63438aabb39c0f855942 Mon Sep 17 00:00:00 2001 From: Harry Terkelsen Date: Fri, 2 Dec 2022 16:33:58 -0800 Subject: [PATCH] [canvaskit] Fix Surface test (flutter/engine#37636) --- .../web_ui/test/canvaskit/surface_test.dart | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/surface_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/surface_test.dart index 178fd5f762..f3d7e26ddb 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/surface_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/surface_test.dart @@ -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'; @@ -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', + ['WEBGL_lose_context'], + ); + js_util.callMethod(loseContextExtension, 'loseContext', const []); // Pump a timer to allow the "lose context" event to propagate. await Future.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(ctx, 'isContextLost', const []); + expect(isContextLost, isTrue); // Emulate WebGL context restoration. - loseContextExtension.restoreContext(); + js_util.callMethod(loseContextExtension, 'restoreContext', const []); // Pump a timer to allow the "restore context" event to propagate. await Future.delayed(Duration.zero); @@ -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