flutter/packages/flutter_tools/test
Andrew Kolos d88e692895
fix test chrome.close can recover if getTab throws a StateError (#154889)
Fixes https://github.com/flutter/flutter/issues/154857.

Does so by:
* adding `await chromiumLauncher.connect(chrome, false);` before the `close` call to make sure we enter[ the block ](9cd2fc90af/packages/flutter_tools/lib/src/web/chrome.dart (L521-L535))that actually tries to close chromium
* adding an `onGetTab` callback to `FakeChromeConnectionWithTab`, which the test now uses to throw a StateError upon `getTab` getting called.

## How I verified this change

1. Change `Chromium.close` from using the safer `getChromeTabGuarded` function to using the previous method of calling `ChromeConnection.getTab` directly. Do so by applying this diff:

```diff
diff --git a/packages/flutter_tools/lib/src/web/chrome.dart b/packages/flutter_tools/lib/src/web/chrome.dart
index c9a5fdab81..81bc246ff9 100644
--- a/packages/flutter_tools/lib/src/web/chrome.dart
+++ b/packages/flutter_tools/lib/src/web/chrome.dart
@@ -520,7 +520,7 @@ class Chromium {
     Duration sigtermDelay = Duration.zero;
     if (_hasValidChromeConnection) {
       try {
-        final ChromeTab? tab = await getChromeTabGuarded(chromeConnection,
+        final ChromeTab? tab = await chromeConnection.getTab(
             (_) => true, retryFor: const Duration(seconds: 1));
         if (tab != null) {
           final WipConnection wipConnection = await tab.connect();
```

2. Then, run the test, which should correctly fail:
```
dart test test/web.shard/chrome_test.dart --name="chrome.close can recover if getTab throws a StateError"`
```
3. Revert the change from step 1 and run again. The test should now pass.
2024-09-10 17:23:56 +00:00
..
android_java11_integration.shard Reland "Update template/test compileSdk, targetSdk, ndk versions" (#153795) 2024-08-21 18:27:00 +00:00
android_preview_integration.shard Reland "Upgrade template Gradle, App AGP, Module AGP, and Kotlin versions, and tests"... but no longer upgrade module AGP version (#151433) 2024-07-10 21:37:26 +00:00
commands.shard Improve 'flutter downgrade' error message (#154434) 2024-09-04 22:06:31 +00:00
data make asset_test.dart tests not dependent on context (#141331) 2024-01-11 18:08:07 +00:00
general.shard Handle ProcessExceptions due to git missing on the host (#154445) 2024-09-09 20:47:05 +00:00
host_cross_arch.shard macOS: Copy macOS framwork dSYM into build outputs (#153975) 2024-08-24 00:14:15 +00:00
integration.shard [native assets] Rewrite install names for relocated native libraries (#153054) 2024-08-29 14:51:23 +00:00
src Launch DDS using DartDevelopmentServiceLauncher (#154015) 2024-08-29 16:16:27 -04:00
web.shard fix test chrome.close can recover if getTab throws a StateError (#154889) 2024-09-10 17:23:56 +00:00