Skip to content

Commit 8ca3a89

Browse files
authored
Fix the Puppeteer tests for the Debug Extension (#2152)
1 parent 6fe17fe commit 8ca3a89

File tree

3 files changed

+31
-44
lines changed

3 files changed

+31
-44
lines changed

dwds/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.local-chromium
2+
.local-chrome

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dev_dependencies:
5252
js: ^0.6.4
5353
lints: ^2.0.0
5454
pubspec_parse: ^1.2.0
55-
puppeteer: ^2.19.0
55+
puppeteer: ^3.0.0
5656
stream_channel: ^2.1.0
5757
test: ^1.21.1
5858
test_common:

dwds/test/puppeteer/extension_test.dart

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ void main() async {
104104
await navigateToPage(browser, url: appUrl, isNew: true);
105105
// Verify that we have debug info for the Dart app:
106106
await workerEvalDelay();
107-
final appTabId = await _getTabId(
108-
appUrl,
107+
final appTabId = await _getCurrentTabId(
109108
worker: worker,
110109
backgroundPage: backgroundPage,
111110
);
@@ -133,8 +132,7 @@ void main() async {
133132
await navigateToPage(browser, url: appUrl, isNew: true);
134133
// Verify that we have debug info for the Dart app:
135134
await workerEvalDelay();
136-
final appTabId = await _getTabId(
137-
appUrl,
135+
final appTabId = await _getCurrentTabId(
138136
worker: worker,
139137
backgroundPage: backgroundPage,
140138
);
@@ -186,6 +184,10 @@ void main() async {
186184
// Navigate to the Dart app:
187185
final appTab =
188186
await navigateToPage(browser, url: appUrl, isNew: true);
187+
final appWindowId = await _getCurrentWindowId(
188+
worker: worker,
189+
backgroundPage: backgroundPage,
190+
);
189191
// Click on the Dart Debug Extension icon:
190192
await workerEvalDelay();
191193
await clickOnExtensionIcon(
@@ -197,13 +199,12 @@ void main() async {
197199
(target) => target.url.contains(devToolsUrlFragment),
198200
);
199201
var devToolsTab = await devToolsTabTarget.page;
200-
var devToolsWindowId = await _getWindowId(
201-
devToolsTab.url!,
202-
worker: worker,
203-
backgroundPage: backgroundPage,
202+
// Navigate to the newly opened DevTools tab:
203+
await navigateToPage(
204+
browser,
205+
url: devToolsTabTarget.url,
204206
);
205-
var appWindowId = await _getWindowId(
206-
appUrl,
207+
var devToolsWindowId = await _getCurrentWindowId(
207208
worker: worker,
208209
backgroundPage: backgroundPage,
209210
);
@@ -237,13 +238,12 @@ void main() async {
237238
(target) => target.url.contains(devToolsUrlFragment),
238239
);
239240
devToolsTab = await devToolsTabTarget.page;
240-
devToolsWindowId = await _getWindowId(
241-
devToolsTab.url!,
242-
worker: worker,
243-
backgroundPage: backgroundPage,
241+
// Navigate to the newly opened DevTools tab:
242+
await navigateToPage(
243+
browser,
244+
url: devToolsTabTarget.url,
244245
);
245-
appWindowId = await _getWindowId(
246-
appUrl,
246+
devToolsWindowId = await _getCurrentWindowId(
247247
worker: worker,
248248
backgroundPage: backgroundPage,
249249
);
@@ -488,8 +488,7 @@ void main() async {
488488
await navigateToPage(browser, url: appUrl, isNew: true);
489489
// Verify that we have debug info for the Dart app:
490490
await workerEvalDelay();
491-
final appTabId = await _getTabId(
492-
appUrl,
491+
final appTabId = await _getCurrentTabId(
493492
worker: worker,
494493
backgroundPage: backgroundPage,
495494
);
@@ -588,11 +587,9 @@ void main() async {
588587
test(
589588
'isFlutterApp=$isFlutterApp and isInternalBuild=true are saved in storage',
590589
() async {
591-
final appUrl = context.appUrl;
592590
// Verify that we have debug info for the Dart app:
593591
await workerEvalDelay();
594-
final appTabId = await _getTabId(
595-
appUrl,
592+
final appTabId = await _getCurrentTabId(
596593
worker: worker,
597594
backgroundPage: backgroundPage,
598595
);
@@ -778,8 +775,7 @@ void main() async {
778775
);
779776
// Set the 'data-multiple-dart-apps' attribute on the DOM.
780777
await appTab.evaluate(_setMultipleAppsAttributeJs);
781-
final appTabId = await _getTabId(
782-
context.appUrl,
778+
final appTabId = await _getCurrentTabId(
783779
worker: worker,
784780
backgroundPage: backgroundPage,
785781
);
@@ -880,8 +876,7 @@ void main() async {
880876
await navigateToPage(browser, url: fakeAppUrl, isNew: true);
881877

882878
// Verify that we have debug info for the fake "Dart" app:
883-
final appTabId = await _getTabId(
884-
fakeAppUrl,
879+
final appTabId = await _getCurrentTabId(
885880
worker: worker,
886881
backgroundPage: backgroundPage,
887882
);
@@ -914,8 +909,7 @@ void main() async {
914909
await navigateToPage(browser, url: fakeAppUrl, isNew: true);
915910

916911
// Wait for debug info to be saved:
917-
final appTabId = await _getTabId(
918-
fakeAppUrl,
912+
final appTabId = await _getCurrentTabId(
919913
worker: worker,
920914
backgroundPage: backgroundPage,
921915
);
@@ -1021,27 +1015,23 @@ Future<void> _tabLeft(Page chromeDevToolsPage) async {
10211015
await chromeDevToolsPage.keyboard.up(modifierKey);
10221016
}
10231017

1024-
Future<int> _getTabId(
1025-
String url, {
1018+
Future<int> _getCurrentTabId({
10261019
Worker? worker,
10271020
Page? backgroundPage,
10281021
}) async {
1029-
final jsExpression = _tabIdForTabJs(url);
10301022
return (await evaluate(
1031-
jsExpression,
1023+
_currentTabIdJs,
10321024
worker: worker,
10331025
backgroundPage: backgroundPage,
10341026
)) as int;
10351027
}
10361028

1037-
Future<int?> _getWindowId(
1038-
String url, {
1029+
Future<int?> _getCurrentWindowId({
10391030
Worker? worker,
10401031
Page? backgroundPage,
10411032
}) async {
1042-
final jsExpression = _windowIdForTabJs(url);
10431033
return (await evaluate(
1044-
jsExpression,
1034+
_currentWindowIdJs,
10451035
worker: worker,
10461036
backgroundPage: backgroundPage,
10471037
)) as int?;
@@ -1069,31 +1059,27 @@ Future<T> _fetchStorageObj<T>(
10691059
return serializers.deserialize(jsonDecode(json)) as T;
10701060
}
10711061

1072-
String _tabIdForTabJs(String tabUrl) {
1073-
return '''
1062+
String _currentTabIdJs = '''
10741063
async () => {
10751064
return new Promise((resolve, reject) => {
1076-
chrome.tabs.query({url: "$tabUrl"}, (tabs) => {
1065+
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
10771066
const tab = tabs[0];
10781067
resolve(tab.id);
10791068
});
10801069
});
10811070
}
10821071
''';
1083-
}
10841072

1085-
String _windowIdForTabJs(String tabUrl) {
1086-
return '''
1073+
String _currentWindowIdJs = '''
10871074
async () => {
10881075
return new Promise((resolve, reject) => {
1089-
chrome.tabs.query({url: "$tabUrl"}, (tabs) => {
1076+
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
10901077
const tab = tabs[0];
10911078
resolve(tab.windowId);
10921079
});
10931080
});
10941081
}
10951082
''';
1096-
}
10971083

10981084
String _fetchStorageObjJs(
10991085
String storageKey, {

0 commit comments

Comments
 (0)