Prevent Headless With Pause After Load (#1239)

diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md
index 0cd1278..8bf694c 100644
--- a/pkgs/test/CHANGELOG.md
+++ b/pkgs/test/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.14.4
+
+* Use non-headless Chrome when provided the flag `--pause-after-load`.
+
 ## 1.14.3
 
 * Fix an issue where coverage tests could not run in Chrome headless. 
diff --git a/pkgs/test/lib/src/runner/browser/browser_manager.dart b/pkgs/test/lib/src/runner/browser/browser_manager.dart
index 2339908..0fc3025 100644
--- a/pkgs/test/lib/src/runner/browser/browser_manager.dart
+++ b/pkgs/test/lib/src/runner/browser/browser_manager.dart
@@ -11,6 +11,7 @@
 import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
 import 'package:test_api/src/util/stack_trace_mapper.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/application_exception.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/environment.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/plugin/platform_helpers.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/runner_suite.dart'; // ignore: implementation_imports
@@ -97,10 +98,13 @@
   ///
   /// Returns the browser manager, or throws an [ApplicationException] if a
   /// connection fails to be established.
-  static Future<BrowserManager> start(Runtime runtime, Uri url,
-      Future<WebSocketChannel> future, ExecutableSettings settings,
-      {bool debug = false}) {
-    var browser = _newBrowser(url, runtime, settings, debug: debug);
+  static Future<BrowserManager> start(
+      Runtime runtime,
+      Uri url,
+      Future<WebSocketChannel> future,
+      ExecutableSettings settings,
+      Configuration configuration) {
+    var browser = _newBrowser(url, runtime, settings, configuration);
 
     var completer = Completer<BrowserManager>();
 
@@ -132,14 +136,13 @@
   /// Starts the browser identified by [browser] using [settings] and has it load [url].
   ///
   /// If [debug] is true, starts the browser in debug mode.
-  static Browser _newBrowser(
-      Uri url, Runtime browser, ExecutableSettings settings,
-      {bool debug = false}) {
+  static Browser _newBrowser(Uri url, Runtime browser,
+      ExecutableSettings settings, Configuration configuration) {
     switch (browser.root) {
       case Runtime.chrome:
-        return Chrome(url, settings: settings, debug: debug);
+        return Chrome(url, configuration, settings: settings);
       case Runtime.phantomJS:
-        return PhantomJS(url, settings: settings, debug: debug);
+        return PhantomJS(url, configuration, settings: settings);
       case Runtime.firefox:
         return Firefox(url, settings: settings);
       case Runtime.safari:
diff --git a/pkgs/test/lib/src/runner/browser/chrome.dart b/pkgs/test/lib/src/runner/browser/chrome.dart
index a452f38..a00985e 100644
--- a/pkgs/test/lib/src/runner/browser/chrome.dart
+++ b/pkgs/test/lib/src/runner/browser/chrome.dart
@@ -11,6 +11,7 @@
 import 'package:path/path.dart' as p;
 import 'package:pedantic/pedantic.dart';
 import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
 import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
 import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
 
@@ -37,7 +38,8 @@
 
   /// Starts a new instance of Chrome open to the given [url], which may be a
   /// [Uri] or a [String].
-  factory Chrome(Uri url, {ExecutableSettings settings, bool debug = false}) {
+  factory Chrome(Uri url, Configuration configuration,
+      {ExecutableSettings settings}) {
     settings ??= defaultSettings[Runtime.chrome];
     var remoteDebuggerCompleter = Completer<Uri>.sync();
     var connectionCompleter = Completer<WipConnection>();
@@ -56,11 +58,11 @@
           '--disable-default-apps',
           '--disable-translate',
           '--disable-dev-shm-usage',
-          if (settings.headless) ...[
+          if (settings.headless && !configuration.pauseAfterLoad) ...[
             '--headless',
             '--disable-gpu',
           ],
-          if (!debug)
+          if (!configuration.debug)
             // We don't actually connect to the remote debugger, but Chrome will
             // close as soon as the page is loaded if we don't turn it on.
             '--remote-debugging-port=0',
@@ -91,7 +93,7 @@
         return process;
       };
 
-      if (!debug) return tryPort();
+      if (!configuration.debug) return tryPort();
       return getUnusedPort<Process>(tryPort);
     }, remoteDebuggerCompleter.future, connectionCompleter.future, idToUrl);
   }
diff --git a/pkgs/test/lib/src/runner/browser/phantom_js.dart b/pkgs/test/lib/src/runner/browser/phantom_js.dart
index d2adbcd..7e3536d 100644
--- a/pkgs/test/lib/src/runner/browser/phantom_js.dart
+++ b/pkgs/test/lib/src/runner/browser/phantom_js.dart
@@ -9,6 +9,7 @@
 import 'package:pedantic/pedantic.dart';
 import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/application_exception.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
 import 'package:test_core/src/util/exit_codes.dart' // ignore: implementation_imports
     as exit_codes;
 import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
@@ -46,7 +47,8 @@
   @override
   final Future<Uri> remoteDebuggerUrl;
 
-  factory PhantomJS(url, {ExecutableSettings settings, bool debug = false}) {
+  factory PhantomJS(url, Configuration configuration,
+      {ExecutableSettings settings}) {
     settings ??= defaultSettings[Runtime.phantomJS];
     var remoteDebuggerCompleter = Completer<Uri>.sync();
     return PhantomJS._(() async {
@@ -54,10 +56,10 @@
       var script = p.join(dir, 'script.js');
       File(script).writeAsStringSync(_script);
 
-      var port = debug ? await getUnsafeUnusedPort() : null;
+      var port = configuration.debug ? await getUnsafeUnusedPort() : null;
 
       var args = settings.arguments.toList();
-      if (debug) {
+      if (configuration.debug) {
         args.addAll(
             ['--remote-debugger-port=$port', '--remote-debugger-autorun=yes']);
       }
diff --git a/pkgs/test/lib/src/runner/browser/platform.dart b/pkgs/test/lib/src/runner/browser/platform.dart
index 75c8eb0..89b2402 100644
--- a/pkgs/test/lib/src/runner/browser/platform.dart
+++ b/pkgs/test/lib/src/runner/browser/platform.dart
@@ -13,32 +13,30 @@
 import 'package:pool/pool.dart';
 import 'package:shelf/shelf.dart' as shelf;
 import 'package:shelf/shelf_io.dart' as shelf_io;
+import 'package:shelf_packages_handler/shelf_packages_handler.dart';
 import 'package:shelf_static/shelf_static.dart';
 import 'package:shelf_web_socket/shelf_web_socket.dart';
-import 'package:shelf_packages_handler/shelf_packages_handler.dart';
 import 'package:stream_channel/stream_channel.dart';
-import 'package:web_socket_channel/web_socket_channel.dart';
-import 'package:yaml/yaml.dart';
-
 import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
 import 'package:test_api/src/backend/suite_platform.dart'; // ignore: implementation_imports
 import 'package:test_api/src/util/stack_trace_mapper.dart'; // ignore: implementation_imports
-import 'package:test_core/src/runner/runner_suite.dart'; // ignore: implementation_imports
-import 'package:test_core/src/runner/platform.dart'; // ignore: implementation_imports
 import 'package:test_api/src/utils.dart'; // ignore: implementation_imports
-import 'package:test_core/src/runner/suite.dart'; // ignore: implementation_imports
-
-import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
-import 'package:test_core/src/util/stack_trace_mapper.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/compiler_pool.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/load_exception.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/platform.dart'; // ignore: implementation_imports
 import 'package:test_core/src/runner/plugin/customizable_platform.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/runner_suite.dart'; // ignore: implementation_imports
+import 'package:test_core/src/runner/suite.dart'; // ignore: implementation_imports
+import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
+import 'package:test_core/src/util/stack_trace_mapper.dart'; // ignore: implementation_imports
+import 'package:web_socket_channel/web_socket_channel.dart';
+import 'package:yaml/yaml.dart';
 
-import '../executable_settings.dart';
+import '../../util/one_off_handler.dart';
 import '../../util/package_map.dart';
 import '../../util/path_handler.dart';
-import '../../util/one_off_handler.dart';
+import '../executable_settings.dart';
 import 'browser_manager.dart';
 import 'default_settings.dart';
 
@@ -434,8 +432,7 @@
     });
 
     var future = BrowserManager.start(
-        browser, hostUrl, completer.future, _browserSettings[browser],
-        debug: _config.debug);
+        browser, hostUrl, completer.future, _browserSettings[browser], _config);
 
     // Store null values for browsers that error out so we know not to load them
     // again.
diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml
index 2dc5a92..be7f1fb 100644
--- a/pkgs/test/pubspec.yaml
+++ b/pkgs/test/pubspec.yaml
@@ -1,5 +1,5 @@
 name: test
-version: 1.14.3
+version: 1.14.4
 description: A full featured library for writing and running Dart tests.
 homepage: https://github.com/dart-lang/test/blob/master/pkgs/test
 
diff --git a/pkgs/test/test/runner/browser/chrome_test.dart b/pkgs/test/test/runner/browser/chrome_test.dart
index 1196ffc..a60bdf4 100644
--- a/pkgs/test/test/runner/browser/chrome_test.dart
+++ b/pkgs/test/test/runner/browser/chrome_test.dart
@@ -5,11 +5,11 @@
 @TestOn('vm')
 @Tags(['chrome'])
 
-import 'package:test_descriptor/test_descriptor.dart' as d;
-
-import 'package:test/src/runner/executable_settings.dart';
 import 'package:test/src/runner/browser/chrome.dart';
+import 'package:test/src/runner/executable_settings.dart';
 import 'package:test/test.dart';
+import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
+import 'package:test_descriptor/test_descriptor.dart' as d;
 
 import '../../io.dart';
 import '../../utils.dart';
@@ -27,7 +27,7 @@
 ''');
     var webSocket = server.handleWebSocket();
 
-    var chrome = Chrome(server.url);
+    var chrome = Chrome(server.url, Configuration());
     addTearDown(() => chrome.close());
 
     expect(await (await webSocket).stream.first, equals('loaded!'));
@@ -38,12 +38,12 @@
 
   test("a process can be killed synchronously after it's started", () async {
     var server = await CodeServer.start();
-    var chrome = Chrome(server.url);
+    var chrome = Chrome(server.url, Configuration());
     await chrome.close();
   });
 
   test('reports an error in onExit', () {
-    var chrome = Chrome(Uri.parse('http://dart-lang.org'),
+    var chrome = Chrome(Uri.parse('http://dart-lang.org'), Configuration(),
         settings: ExecutableSettings(
             linuxExecutable: '_does_not_exist',
             macOSExecutable: '_does_not_exist',
diff --git a/pkgs/test/test/runner/browser/phantom_js_test.dart b/pkgs/test/test/runner/browser/phantom_js_test.dart
index 01da9d3..f0c4c10 100644
--- a/pkgs/test/test/runner/browser/phantom_js_test.dart
+++ b/pkgs/test/test/runner/browser/phantom_js_test.dart
@@ -5,11 +5,11 @@
 @TestOn('vm')
 @Tags(['phantomjs'])
 
-import 'package:test_descriptor/test_descriptor.dart' as d;
-
 import 'package:test/src/runner/browser/phantom_js.dart';
 import 'package:test/src/runner/executable_settings.dart';
 import 'package:test/test.dart';
+import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
+import 'package:test_descriptor/test_descriptor.dart' as d;
 
 import '../../io.dart';
 import '../../utils.dart';
@@ -27,7 +27,7 @@
 ''');
     var webSocket = server.handleWebSocket();
 
-    var phantomJS = PhantomJS(server.url);
+    var phantomJS = PhantomJS(server.url, Configuration());
     addTearDown(() => phantomJS.close());
 
     expect(await (await webSocket).stream.first, equals('loaded!'));
@@ -36,12 +36,12 @@
   test("a process can be killed synchronously after it's started", () async {
     var server = await CodeServer.start();
 
-    var phantomJS = PhantomJS(server.url);
+    var phantomJS = PhantomJS(server.url, Configuration());
     await phantomJS.close();
   });
 
   test('reports an error in onExit', () {
-    var phantomJS = PhantomJS('http://dart-lang.org',
+    var phantomJS = PhantomJS('http://dart-lang.org', Configuration(),
         settings: ExecutableSettings(
             linuxExecutable: '_does_not_exist',
             macOSExecutable: '_does_not_exist',