-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathweb_compiler_test.dart
More file actions
98 lines (83 loc) · 3.1 KB
/
web_compiler_test.dart
File metadata and controls
98 lines (83 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2026 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
import 'dart:async';
import 'dart:io';
import 'package:devtools_shared/devtools_test_utils.dart';
import 'package:devtools_test/helpers.dart';
import 'package:devtools_test/integration_test.dart';
import 'package:test/test.dart';
import 'package:webdriver/async_io.dart';
import '../integration_test/test_infra/run/run_test.dart';
void main() {
late Process devtoolsProcess;
late WebDriver driver;
late String devToolsServerAddress;
const serverStartupTimeout = Duration(minutes: 1);
setUpAll(() async {
await ChromeDriver().start(debugLogging: true);
// TODO(https://github.com/flutter/devtools/issues/9197): Launch the
// DevTools server from source.
// For now, this test uses the version of DevTools bundled in the Dart SDK
// because building and running from source is too prohibitive until
// DevTools is moved into the Dart SDK. See issue for details.
devtoolsProcess = await startDevToolsServer();
devToolsServerAddress = await listenForDevToolsAddress(
devtoolsProcess,
timeout: serverStartupTimeout,
);
driver = await createDriver(
uri: Uri.parse('http://127.0.0.1:${ChromeDriver.port}'),
desired: {
...Capabilities.chrome,
Capabilities.chromeOptions: {
'args': ['--headless'],
},
},
);
});
tearDownAll(() async {
await driver.quit();
devtoolsProcess.kill();
});
/// Reads the "flt-renderer" attribute on the body element.
///
/// This can be used to determine whether the render is canvaskit or skwasm:
/// https://github.com/flutter/devtools/pull/9406#pullrequestreview-3142210823
Future<String?> readRendererAttribute() => retryAsync<String?>(
() async {
final body = await driver.findElement(const By.tagName('body'));
return body.attributes['flt-renderer'];
},
condition: (result) => result != null,
onRetry: () => Future.delayed(const Duration(milliseconds: 250)),
);
test(
'compiler query param determines skwasm/canvaskit renderer',
timeout: longTimeout,
() async {
// Open the DevTools URL with ?compiler=wasm.
await driver.get(
_addQueryParam(devToolsServerAddress, param: 'compiler', value: 'wasm'),
);
// Verify we are using the skwasm renderer.
expect(await readRendererAttribute(), equals('skwasm'));
// Open the DevTools URL with ?compiler=js.
await driver.get(
_addQueryParam(devToolsServerAddress, param: 'compiler', value: 'js'),
);
// Verify we are using the canvaskit renderer.
expect(await readRendererAttribute(), equals('canvaskit'));
},
);
}
String _addQueryParam(
String url, {
required String param,
required String value,
}) {
final uri = Uri.parse(url);
final newQueryParameters = Map<String, dynamic>.of(uri.queryParameters);
newQueryParameters[param] = value;
return uri.replace(queryParameters: newQueryParameters).toString();
}