Skip to content

Commit 2bcb01b

Browse files
authored
Add flt-renderer and flt-build-mode debug attributes to <body> (flutter#23430)
* add flt-renderer and flt-build-mode debug attributes to <body> * explicitly specify renderer in tests
1 parent 40f385f commit 2bcb01b

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

lib/web_ui/dev/test_runner.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,13 @@ class TestCommand extends Command<bool> with ArgUtils {
618618
'--enable-asserts',
619619
'--enable-experiment=non-nullable',
620620
'--no-sound-null-safety',
621-
if (input.forCanvasKit) '-DFLUTTER_WEB_USE_SKIA=true',
622-
if (!input.forCanvasKit) '-DFLUTTER_WEB_AUTO_DETECT=false',
623-
if (!input.forCanvasKit) '-DFLUTTER_WEB_USE_SKIA=false',
621+
622+
// We do not want to auto-select a renderer in tests. As of today, tests
623+
// are designed to run in one specific mode. So instead, we specify the
624+
// renderer explicitly.
625+
'-DFLUTTER_WEB_AUTO_DETECT=false',
626+
'-DFLUTTER_WEB_USE_SKIA=${input.forCanvasKit}',
627+
624628
'-O2',
625629
'-o',
626630
targetFileName, // target path.

lib/web_ui/lib/src/engine.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ part 'engine/vector_math.dart';
147147
part 'engine/web_experiments.dart';
148148
part 'engine/window.dart';
149149

150+
// The mode the app is running in.
151+
// Keep these in sync with the same constants on the framework-side under foundation/constants.dart.
152+
const bool kReleaseMode = bool.fromEnvironment('dart.vm.product', defaultValue: false);
153+
const bool kProfileMode = bool.fromEnvironment('dart.vm.profile', defaultValue: false);
154+
const bool kDebugMode = !kReleaseMode && !kProfileMode;
155+
String get buildMode => kReleaseMode
156+
? 'release'
157+
: kProfileMode
158+
? 'profile'
159+
: 'debug';
160+
150161
/// A benchmark metric that includes frame-related computations prior to
151162
/// submitting layer and picture operations to the underlying renderer, such as
152163
/// HTML and CanvasKit. During this phase we compute transforms, clips, and

lib/web_ui/lib/src/engine/dom_renderer.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ flt-glass-pane * {
330330
}
331331

332332
final html.BodyElement bodyElement = html.document.body!;
333+
334+
setElementAttribute(
335+
bodyElement,
336+
'flt-renderer',
337+
'${useCanvasKit ? 'canvaskit' : 'html'} (${_autoDetect ? 'auto-selected' : 'requested explicitly'})',
338+
);
339+
setElementAttribute(bodyElement, 'flt-build-mode', buildMode);
340+
333341
setElementStyle(bodyElement, 'position', 'fixed');
334342
setElementStyle(bodyElement, 'top', '0');
335343
setElementStyle(bodyElement, 'right', '0');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// @dart = 2.12
6+
import 'dart:html' as html;
7+
8+
import 'package:test/bootstrap/browser.dart';
9+
import 'package:test/test.dart';
10+
import 'package:ui/src/engine.dart';
11+
12+
import 'common.dart';
13+
14+
void main() {
15+
internalBootstrapBrowserTest(() => testMain);
16+
}
17+
18+
void testMain() {
19+
group('CanvasKit', () {
20+
setUpCanvasKitTest();
21+
22+
test('populates flt-renderer and flt-build-mode', () {
23+
DomRenderer();
24+
expect(html.document.body!.attributes['flt-renderer'], 'canvaskit (requested explicitly)');
25+
expect(html.document.body!.attributes['flt-build-mode'], 'debug');
26+
});
27+
// TODO: https://github.com/flutter/flutter/issues/60040
28+
}, skip: isIosSafari);
29+
}

lib/web_ui/test/dom_renderer_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ void main() {
1414
}
1515

1616
void testMain() {
17+
test('populates flt-renderer and flt-build-mode', () {
18+
DomRenderer();
19+
expect(html.document.body.attributes['flt-renderer'], 'html (requested explicitly)');
20+
expect(html.document.body.attributes['flt-build-mode'], 'debug');
21+
});
1722
test('creating elements works', () {
1823
final DomRenderer renderer = DomRenderer();
1924
final html.Element element = renderer.createElement('div');

0 commit comments

Comments
 (0)