Skip to content

Commit

Permalink
Fix perfetto integration test goldens (#7836)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored May 28, 2024
1 parent 926c5be commit d8b931b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class _PerfettoViewController extends DisposableController
/// 'onLoad' stream.
late final Completer<void> _perfettoIFrameReady;

/// Whether the perfetto iFrame has been unloaded after loading.
///
/// This is stored to prevent race conditions where the iFrame's content
/// window has become null. This is set to true when the perfetto iFrame has
/// received the first event on the 'unload' stream.
bool _perfettoIFrameUnloaded = false;

/// Completes when the Perfetto postMessage handler is ready, which is
/// signaled by receiving a [_perfettoPong] event in response to sending a
/// [_perfettoPing] event.
Expand Down Expand Up @@ -132,13 +139,25 @@ class _PerfettoViewController extends DisposableController
_perfettoIFrameReady = Completer<void>();
_perfettoHandlerReady = Completer<void>();
_devtoolsThemeHandlerReady = Completer<void>();
_perfettoIFrameUnloaded = false;

unawaited(
perfettoController.perfettoIFrame.onLoad.first.then((_) {
_perfettoIFrameReady.complete();
}),
);

// TODO(kenz): uncomment once https://github.com/dart-lang/web/pull/246 is
// landed and package:web 0.6.0 is published.
// unawaited(
// perfettoController.perfettoIFrame.onUnload.first.then((_) {
// if (_perfettoIFrameReady.isCompleted) {
// // Only set to true if this occurs after the iFrame has been loaded.
// _perfettoIFrameUnloaded = true;
// }
// }),
// );

window.addEventListener(
'message',
_handleMessageListener = _handleMessage.toJS,
Expand Down Expand Up @@ -242,6 +261,7 @@ class _PerfettoViewController extends DisposableController

void _postMessage(Object message) async {
await _perfettoIFrameReady.future;
if (_perfettoIFrameUnloaded) return;
assert(
perfettoController.perfettoIFrame.contentWindow != null,
'Something went wrong. The iFrame\'s contentWindow is null after the'
Expand Down Expand Up @@ -323,7 +343,9 @@ class _PerfettoViewController extends DisposableController
window.removeEventListener('message', _handleMessageListener);
_handleMessageListener = null;
_pollForPerfettoHandlerReady?.cancel();
_pollForPerfettoHandlerReady = null;
_pollForThemeHandlerReady?.cancel();
_pollForThemeHandlerReady = null;
super.dispose();
}
}

0 comments on commit d8b931b

Please sign in to comment.