resident_runner_test.dart 80 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7
import 'dart:async';
8

9
import 'package:dds/dds.dart' as dds;
10
import 'package:file/memory.dart';
11
import 'package:file_testing/file_testing.dart';
12
import 'package:flutter_tools/src/application_package.dart';
13
import 'package:flutter_tools/src/artifacts.dart';
14
import 'package:flutter_tools/src/asset.dart';
15
import 'package:flutter_tools/src/base/command_help.dart';
16
import 'package:flutter_tools/src/base/common.dart';
17
import 'package:flutter_tools/src/base/dds.dart';
18
import 'package:flutter_tools/src/base/file_system.dart';
19
import 'package:flutter_tools/src/base/io.dart' as io;
20 21
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
22
import 'package:flutter_tools/src/build_info.dart';
23
import 'package:flutter_tools/src/compile.dart';
24
import 'package:flutter_tools/src/convert.dart';
25
import 'package:flutter_tools/src/devfs.dart';
26
import 'package:flutter_tools/src/device.dart';
27 28
import 'package:flutter_tools/src/device_port_forwarder.dart';
import 'package:flutter_tools/src/features.dart';
29
import 'package:flutter_tools/src/globals.dart' as globals;
30
import 'package:flutter_tools/src/reporting/reporting.dart';
31
import 'package:flutter_tools/src/resident_devtools_handler.dart';
32
import 'package:flutter_tools/src/resident_runner.dart';
33
import 'package:flutter_tools/src/run_cold.dart';
34
import 'package:flutter_tools/src/run_hot.dart';
35
import 'package:flutter_tools/src/version.dart';
36
import 'package:flutter_tools/src/vmservice.dart';
37 38
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
39
import 'package:test/fake.dart';
40
import 'package:vm_service/vm_service.dart' as vm_service;
41

42
import '../src/common.dart';
43
import '../src/context.dart';
44
import '../src/fake_vm_services.dart';
45
import '../src/fakes.dart';
46
import '../src/testbed.dart';
47

48 49 50 51 52 53 54 55
final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate(
  id: '1',
  pauseEvent: vm_service.Event(
    kind: vm_service.EventKind.kResume,
    timestamp: 0
  ),
  breakpoints: <vm_service.Breakpoint>[],
  exceptionPauseMode: null,
56
  extensionRPCs: <String>[],
57 58 59 60 61 62 63
  libraries: <vm_service.LibraryRef>[
    vm_service.LibraryRef(
      id: '1',
      uri: 'file:///hello_world/main.dart',
      name: '',
    ),
  ],
64 65 66 67 68 69
  livePorts: 0,
  name: 'test',
  number: '1',
  pauseOnExit: false,
  runnable: true,
  startTime: 0,
70
  isSystemIsolate: false,
71
  isolateFlags: <vm_service.IsolateFlag>[],
72 73 74 75 76 77 78 79
);

final vm_service.Isolate fakePausedIsolate = vm_service.Isolate(
  id: '1',
  pauseEvent: vm_service.Event(
    kind: vm_service.EventKind.kPauseException,
    timestamp: 0
  ),
80 81 82 83 84 85
  breakpoints: <vm_service.Breakpoint>[
    vm_service.Breakpoint(
      breakpointNumber: 123,
      id: 'test-breakpoint',
      location: vm_service.SourceLocation(
        tokenPos: 0,
86
        script: vm_service.ScriptRef(id: 'test-script', uri: 'foo.dart'),
87
      ),
88
      enabled: true,
89 90 91
      resolved: true,
    ),
  ],
92 93 94 95 96 97 98 99
  exceptionPauseMode: null,
  libraries: <vm_service.LibraryRef>[],
  livePorts: 0,
  name: 'test',
  number: '1',
  pauseOnExit: false,
  runnable: true,
  startTime: 0,
100
  isSystemIsolate: false,
101
  isolateFlags: <vm_service.IsolateFlag>[],
102 103
);

104 105 106 107 108 109 110 111 112 113 114
final vm_service.VM fakeVM = vm_service.VM(
  isolates: <vm_service.IsolateRef>[fakeUnpausedIsolate],
  pid: 1,
  hostCPU: '',
  isolateGroups: <vm_service.IsolateGroupRef>[],
  targetCPU: '',
  startTime: 0,
  name: 'dart',
  architectureBits: 64,
  operatingSystem: '',
  version: '',
115 116
  systemIsolateGroups: <vm_service.IsolateGroupRef>[],
  systemIsolates: <vm_service.IsolateRef>[],
117 118
);

119 120 121 122 123
final FlutterView fakeFlutterView = FlutterView(
  id: 'a',
  uiIsolate: fakeUnpausedIsolate,
);

124 125 126 127 128 129 130 131 132
final FakeVmServiceRequest listViews = FakeVmServiceRequest(
  method: kListViewsMethod,
  jsonResponse: <String, Object>{
    'views': <Object>[
      fakeFlutterView.toJson(),
    ],
  },
);

133 134 135 136 137 138 139 140 141
const FakeVmServiceRequest setAssetBundlePath = FakeVmServiceRequest(
  method: '_flutter.setAssetBundlePath',
  args: <String, Object>{
    'viewId': 'a',
    'assetDirectory': 'build/flutter_assets',
    'isolateId': '1',
  }
);

142 143 144 145 146 147 148 149
const FakeVmServiceRequest evict = FakeVmServiceRequest(
  method: 'ext.flutter.evict',
  args: <String, Object>{
    'value': 'asset',
    'isolateId': '1',
  }
);

150 151
final Uri testUri = Uri.parse('foo://bar');

152
void main() {
153
  Testbed testbed;
154 155
  FakeFlutterDevice flutterDevice;
  FakeDevFS devFS;
156
  ResidentRunner residentRunner;
157
  FakeDevice device;
158
  FakeVmServiceHost fakeVmServiceHost;
159 160 161

  setUp(() {
    testbed = Testbed(setup: () {
162 163
      globals.fs.file('.packages')
        .writeAsStringSync('\n');
164
      globals.fs.file(globals.fs.path.join('build', 'app.dill'))
165 166
        ..createSync(recursive: true)
        ..writeAsStringSync('ABC');
167 168
      residentRunner = HotRunner(
        <FlutterDevice>[
169
          flutterDevice,
170 171 172
        ],
        stayResident: false,
        debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
173
        target: 'main.dart',
174
        devtoolsHandler: createNoOpHandler,
175 176
      );
    });
177 178 179 180 181 182 183
    device = FakeDevice();
    devFS = FakeDevFS();
    flutterDevice = FakeFlutterDevice()
      ..testUri = testUri
      ..vmServiceHost = (() => fakeVmServiceHost)
      ..device = device
      .._devFS = devFS;
184 185
  });

186
  testUsingContext('ResidentRunner can attach to device successfully', () => testbed.run(() async {
187 188 189 190
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
191 192
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
193
    final Future<int> result = residentRunner.attach(
194 195 196
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
197
    );
198
    final Future<DebugConnectionInfo> connectionInfo = futureConnectionInfo.future;
199 200

    expect(await result, 0);
201
    expect(futureConnectionInfo.isCompleted, true);
202
    expect((await connectionInfo).baseUri, 'foo://bar');
203
    expect(futureAppStart.isCompleted, true);
204
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
205
  }));
206

207
  testUsingContext('ResidentRunner suppresses errors for the initial compilation', () => testbed.run(() async {
208 209 210 211 212 213
    globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
      .createSync(recursive: true);
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
214 215
    final FakeResidentCompiler residentCompiler = FakeResidentCompiler()
      ..nextOutput = const CompilerOutput('foo', 0 ,<Uri>[]);
216 217
    residentRunner = HotRunner(
      <FlutterDevice>[
218
        flutterDevice,
219 220 221
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
222
      target: 'main.dart',
223
      devtoolsHandler: createNoOpHandler,
224
    );
225
    flutterDevice.generator = residentCompiler;
226

227
    expect(await residentRunner.run(enableDevTools: true), 0);
228
    expect(residentCompiler.didSuppressErrors, true);
229
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
230
  }));
231

232 233 234 235 236
  // Regression test for https://github.com/flutter/flutter/issues/60613
  testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails', () => testbed.run(() async {
    globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
      .createSync(recursive: true);
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
237 238
    final FakeResidentCompiler residentCompiler = FakeResidentCompiler()
      ..nextOutput = const CompilerOutput('foo', 1 ,<Uri>[]);
239 240
    residentRunner = HotRunner(
      <FlutterDevice>[
241
        flutterDevice,
242 243 244
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
245
      target: 'main.dart',
246
      devtoolsHandler: createNoOpHandler,
247
    );
248
    flutterDevice.generator = residentCompiler;
249 250 251 252 253 254 255 256 257 258 259 260 261

    expect(await residentRunner.run(), 1);
    // Completing this future ensures that the daemon can exit correctly.
    expect(await residentRunner.waitForAppToFinish(), 1);
  }));

  // Regression test for https://github.com/flutter/flutter/issues/60613
  testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails - cold mode', () => testbed.run(() async {
    globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
      .createSync(recursive: true);
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
    residentRunner = ColdRunner(
      <FlutterDevice>[
262
        flutterDevice,
263 264 265
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
266
      target: 'main.dart',
267
      devtoolsHandler: createNoOpHandler,
268
    );
269
    flutterDevice.runColdCode = 1;
270 271 272 273 274 275 276 277 278 279 280 281 282

    expect(await residentRunner.run(), 1);
    // Completing this future ensures that the daemon can exit correctly.
    expect(await residentRunner.waitForAppToFinish(), 1);
  }));

  // Regression test for https://github.com/flutter/flutter/issues/60613
  testUsingContext('ResidentRunner calls appFailedToStart if exception is thrown - cold mode', () => testbed.run(() async {
    globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
      .createSync(recursive: true);
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
    residentRunner = ColdRunner(
      <FlutterDevice>[
283
        flutterDevice,
284 285 286
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
287
      target: 'main.dart',
288
      devtoolsHandler: createNoOpHandler,
289
    );
290 291
    flutterDevice.runColdError = Exception('BAD STUFF');

292 293 294 295 296 297

    expect(await residentRunner.run(), 1);
    // Completing this future ensures that the daemon can exit correctly.
    expect(await residentRunner.waitForAppToFinish(), 1);
  }));

298
  testUsingContext('ResidentRunner does not suppressErrors if running with an applicationBinary', () => testbed.run(() async {
299 300 301 302 303 304
    globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
      .createSync(recursive: true);
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
305 306
    final FakeResidentCompiler residentCompiler = FakeResidentCompiler()
      ..nextOutput = const CompilerOutput('foo', 0 ,<Uri>[]);
307 308
    residentRunner = HotRunner(
      <FlutterDevice>[
309
        flutterDevice,
310 311 312 313
      ],
      applicationBinary: globals.fs.file('app.apk'),
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
314
      target: 'main.dart',
315
      devtoolsHandler: createNoOpHandler,
316
    );
317
    flutterDevice.generator = residentCompiler;
318

319
    expect(await residentRunner.run(enableDevTools: true), 0);
320
    expect(residentCompiler.didSuppressErrors, false);
321
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
322
  }));
323

324
  testUsingContext('ResidentRunner can attach to device successfully with --fast-start', () => testbed.run(() async {
325
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
326 327 328
      listViews,
      listViews,
      listViews,
329 330 331 332 333 334 335 336 337 338 339
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
340
      listViews,
341
      const FakeVmServiceRequest(
342 343 344 345 346
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        }
      ),
347
      FakeVmServiceRequest(
348 349
        method: kRunInViewMethod,
        args: <String, Object>{
350
          'viewId': fakeFlutterView.id,
351
          'mainScript': 'main.dart.dill',
352 353 354 355 356 357 358 359 360 361 362
          'assetDirectory': 'build/flutter_assets',
        }
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        )
      ),
    ]);
363 364
    residentRunner = HotRunner(
      <FlutterDevice>[
365
        flutterDevice,
366 367
      ],
      stayResident: false,
368 369 370 371 372
      debuggingOptions: DebuggingOptions.enabled(
        BuildInfo.debug,
        fastStart: true,
        startPaused: true,
      ),
373
      target: 'main.dart',
374
      devtoolsHandler: createNoOpHandler,
375
    );
376 377
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
378
    final Future<int> result = residentRunner.attach(
379 380 381
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
382
    );
383
    final Future<DebugConnectionInfo> connectionInfo = futureConnectionInfo.future;
384 385

    expect(await result, 0);
386
    expect(futureConnectionInfo.isCompleted, true);
387
    expect((await connectionInfo).baseUri, 'foo://bar');
388
    expect(futureAppStart.isCompleted, true);
389
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
390
  }));
391

392
  testUsingContext('ResidentRunner can handle an RPC exception from hot reload', () => testbed.run(() async {
393 394 395 396 397
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
    ]);
398 399
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
400
    unawaited(residentRunner.attach(
401 402 403
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
404
    ));
405
    await futureAppStart.future;
406
    flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, '');
407

408
    final OperationResult result = await residentRunner.restart();
409 410
    expect(result.fatal, true);
    expect(result.code, 1);
411
    expect((globals.flutterUsage as TestUsage).events, contains(
412 413 414 415 416
      TestUsageEvent('hot', 'exception', parameters: CustomDimensions(
        hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
        hotEventSdkName: 'Android',
        hotEventEmulator: false,
        hotEventFullRestart: false,
417
        fastReassemble: false,
418
      )),
419
    ));
420
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
421
  }, overrides: <Type, Generator>{
422
    Usage: () => TestUsage(),
423
  }));
424

425 426 427 428 429
  testUsingContext('ResidentRunner fails its operation if the device initialization is not complete', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
430 431
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
432
    unawaited(residentRunner.attach(
433 434
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
435
    ));
436
    await futureAppStart.future;
437
    flutterDevice._devFS = null;
438

439
    final OperationResult result = await residentRunner.restart();
440 441 442 443
    expect(result.fatal, false);
    expect(result.code, 1);
    expect(result.message, contains('Device initialization has not completed.'));
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
444
  }));
445

446 447 448 449 450 451
  testUsingContext('ResidentRunner can handle an reload-barred exception from hot reload', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
    ]);
452 453
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
454
    unawaited(residentRunner.attach(
455 456 457
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
458
    ));
459
    await futureAppStart.future;
460
    flutterDevice.reportError = vm_service.RPCError('something bad happened', kIsolateReloadBarred, '');
461

462
    final OperationResult result = await residentRunner.restart();
463 464 465
    expect(result.fatal, true);
    expect(result.code, kIsolateReloadBarred);
    expect(result.message, contains('Unable to hot reload application due to an unrecoverable error'));
466 467

    expect((globals.flutterUsage as TestUsage).events, contains(
468 469 470 471 472
      TestUsageEvent('hot', 'reload-barred', parameters: CustomDimensions(
        hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
        hotEventSdkName: 'Android',
        hotEventEmulator: false,
        hotEventFullRestart: false,
473
        fastReassemble: false,
474
      )),
475
    ));
476 477
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
  }, overrides: <Type, Generator>{
478
    Usage: () => TestUsage(),
479
  }));
480

481 482 483 484 485 486 487 488
  testUsingContext('ResidentRunner reports hot reload event with null safety analytics', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
    ]);
    residentRunner = HotRunner(
      <FlutterDevice>[
489
        flutterDevice,
490 491
      ],
      stayResident: false,
492
      target: 'main.dart',
493 494 495 496 497
      debuggingOptions: DebuggingOptions.enabled(const BuildInfo(
        BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: <String>[
        '--enable-experiment=non-nullable',
        ],
      )),
498
      devtoolsHandler: createNoOpHandler,
499
    );
500 501
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
502
    unawaited(residentRunner.attach(
503 504 505
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
506
    ));
507
    await futureAppStart.future;
508
    flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, '');
509

510
    final OperationResult result = await residentRunner.restart();
511 512
    expect(result.fatal, true);
    expect(result.code, 1);
513 514

    expect((globals.flutterUsage as TestUsage).events, contains(
515 516 517 518 519
      TestUsageEvent('hot', 'exception', parameters: CustomDimensions(
        hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
        hotEventSdkName: 'Android',
        hotEventEmulator: false,
        hotEventFullRestart: false,
520
        fastReassemble: false,
521
      )),
522
    ));
523 524
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
  }, overrides: <Type, Generator>{
525
    Usage: () => TestUsage(),
526 527
  }));

528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
  testUsingContext('ResidentRunner does not reload sources if no sources changed', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
     listViews,
      listViews,
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': '1',
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'ext.flutter.reassemble',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
      ),
    ]);
    residentRunner = HotRunner(
      <FlutterDevice>[
549
        flutterDevice,
550 551 552
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
553
      target: 'main.dart',
554
      devtoolsHandler: createNoOpHandler,
555
    );
556 557
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
558
    unawaited(residentRunner.attach(
559 560 561
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
562
    ));
563
    await futureAppStart.future;
564
    flutterDevice.report =  UpdateFSReport(success: true);
565

566
    final OperationResult result = await residentRunner.restart();
567 568 569

    expect(result.code, 0);
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
570
  }));
571

572 573 574 575 576
  testUsingContext('ResidentRunner reports error with missing entrypoint file', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
577 578 579 580 581 582 583 584 585 586 587 588 589
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{
          'isolates': <Object>[
            fakeUnpausedIsolate.toJson(),
          ],
        }).toJson(),
      ),
      const FakeVmServiceRequest(
        method: 'reloadSources',
        args: <String, Object>{
          'isolateId': '1',
          'pause': false,
590
          'rootLibUri': 'main.dart.incremental.dill'
591 592 593 594 595 596 597 598 599
        },
        jsonResponse: <String, Object>{
          'type': 'ReloadReport',
          'success': true,
          'details': <String, Object>{
            'loadedLibraryCount': 1,
          },
        },
      ),
600 601 602 603 604 605 606 607 608 609 610 611 612 613
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': '1',
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'ext.flutter.reassemble',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
      ),
    ]);
614 615
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
616
    unawaited(residentRunner.attach(
617 618 619
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
620
    ));
621
    await futureAppStart.future;
622
    flutterDevice.report =  UpdateFSReport(success: true, invalidatedSourcesCount: 1);
623

624
    final OperationResult result = await residentRunner.restart();
625 626 627 628 629

    expect(globals.fs.file(globals.fs.path.join('lib', 'main.dart')), isNot(exists));
    expect(testLogger.errorText, contains('The entrypoint file (i.e. the file with main())'));
    expect(result.fatal, false);
    expect(result.code, 0);
630
  }));
631

632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
   testUsingContext('ResidentRunner resets compilation time on reload reject', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{
          'isolates': <Object>[
            fakeUnpausedIsolate.toJson(),
          ],
        }).toJson(),
      ),
      const FakeVmServiceRequest(
        method: 'reloadSources',
        args: <String, Object>{
          'isolateId': '1',
          'pause': false,
650
          'rootLibUri': 'main.dart.incremental.dill'
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
        },
        jsonResponse: <String, Object>{
          'type': 'ReloadReport',
          'success': false,
          'notices': <Object>[
            <String, Object>{
              'message': 'Failed to hot reload'
            }
          ],
          'details': <String, Object>{},
        },
      ),
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': '1',
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'ext.flutter.reassemble',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
      ),
    ]);
678 679
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
680
    unawaited(residentRunner.attach(
681 682 683
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
684
    ));
685
    await futureAppStart.future;
686
    flutterDevice.report =  UpdateFSReport(success: true, invalidatedSourcesCount: 1);
687

688
    final OperationResult result = await residentRunner.restart();
689 690 691 692

    expect(result.fatal, false);
    expect(result.message, contains('Reload rejected: Failed to hot reload')); // contains error message from reload report.
    expect(result.code, 1);
693
    expect(devFS.lastCompiled, null);
694
  }));
695

696
  testUsingContext('ResidentRunner can send target platform to analytics from hot reload', () => testbed.run(() async {
697
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
698 699
      listViews,
      listViews,
700
      listViews,
701 702 703 704 705 706 707 708 709 710 711 712 713
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{
          'isolates': <Object>[
            fakeUnpausedIsolate.toJson(),
          ],
        }).toJson(),
      ),
      const FakeVmServiceRequest(
        method: 'reloadSources',
        args: <String, Object>{
          'isolateId': '1',
          'pause': false,
714
          'rootLibUri': 'main.dart.incremental.dill'
715 716 717 718 719 720 721 722 723
        },
        jsonResponse: <String, Object>{
          'type': 'ReloadReport',
          'success': true,
          'details': <String, Object>{
            'loadedLibraryCount': 1,
          },
        },
      ),
724 725 726 727 728 729 730 731
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': '1',
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
732 733
        method: 'ext.flutter.reassemble',
        args: <String, Object>{
734
          'isolateId': fakeUnpausedIsolate.id,
735 736 737
        },
      ),
    ]);
738 739
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
740
    unawaited(residentRunner.attach(
741 742 743
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
744
    ));
745
    await futureAppStart.future;
746

747
    final OperationResult result = await residentRunner.restart();
748 749
    expect(result.fatal, false);
    expect(result.code, 0);
750 751 752 753

    final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first;
    expect(event.category, 'hot');
    expect(event.parameter, 'reload');
754
    expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm));
755
  }, overrides: <Type, Generator>{
756
    Usage: () => TestUsage(),
757
  }));
758

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
  testUsingContext('ResidentRunner can perform fast reassemble', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: fakeVM.toJson(),
      ),
      listViews,
      listViews,
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: fakeVM.toJson(),
      ),
      const FakeVmServiceRequest(
        method: 'reloadSources',
        args: <String, Object>{
          'isolateId': '1',
          'pause': false,
777
          'rootLibUri': 'main.dart.incremental.dill',
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
        },
        jsonResponse: <String, Object>{
          'type': 'ReloadReport',
          'success': true,
          'details': <String, Object>{
            'loadedLibraryCount': 1,
          },
        },
      ),
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': '1',
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'ext.flutter.fastReassemble',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
798
          'className': 'FOO',
799 800 801
        },
      ),
    ]);
802
    final FakeDelegateFlutterDevice flutterDevice = FakeDelegateFlutterDevice(
803
      device,
804 805
      BuildInfo.debug,
      FakeResidentCompiler(),
806
      devFS,
807 808 809 810 811 812 813
    )..vmService = fakeVmServiceHost.vmService;
    residentRunner = HotRunner(
      <FlutterDevice>[
        flutterDevice,
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
814
      target: 'main.dart',
815
      devtoolsHandler: createNoOpHandler,
816
    );
817
    devFS.nextUpdateReport = UpdateFSReport(
818 819 820 821
      success: true,
      fastReassembleClassName: 'FOO',
      invalidatedSourcesCount: 1,
    );
822

823 824
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
825
    unawaited(residentRunner.attach(
826 827 828
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
829 830
    ));

831
    await futureAppStart.future;
832
    final OperationResult result = await residentRunner.restart();
833 834 835

    expect(result.fatal, false);
    expect(result.code, 0);
836 837 838 839

    final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first;
    expect(event.category, 'hot');
    expect(event.parameter, 'reload');
840
    expect(event.parameters.fastReassemble, true);
841 842
  }, overrides: <Type, Generator>{
    FileSystem: () => MemoryFileSystem.test(),
843
    Platform: () => FakePlatform(),
844
    ProjectFileInvalidator: () => FakeProjectFileInvalidator(),
845
    Usage: () => TestUsage(),
846
    FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true),
847
  }));
848

849
  testUsingContext('ResidentRunner can send target platform to analytics from full restart', () => testbed.run(() async {
850
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
851 852 853
      listViews,
      listViews,
      listViews,
854 855 856 857 858 859 860 861 862 863 864
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
865
      listViews,
866
      const FakeVmServiceRequest(
867 868 869 870 871
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        },
      ),
872
      FakeVmServiceRequest(
873 874
        method: kRunInViewMethod,
        args: <String, Object>{
875
          'viewId': fakeFlutterView.id,
876
          'mainScript': 'main.dart.dill',
877 878 879 880 881 882 883 884 885 886 887
          'assetDirectory': 'build/flutter_assets',
        },
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        )
      )
    ]);
888 889
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
890
    unawaited(residentRunner.attach(
891 892 893
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
894 895 896 897 898
    ));

    final OperationResult result = await residentRunner.restart(fullRestart: true);
    expect(result.fatal, false);
    expect(result.code, 0);
899 900 901 902

    final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first;
    expect(event.category, 'hot');
    expect(event.parameter, 'restart');
903
    expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm));
904
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
905
  }, overrides: <Type, Generator>{
906
    Usage: () => TestUsage(),
907
  }));
908

909
  testUsingContext('ResidentRunner can remove breakpoints and exception-pause-mode from paused isolate during hot restart', () => testbed.run(() async {
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakePausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
925
      const FakeVmServiceRequest(
926
        method: 'setIsolatePauseMode',
927 928
        args: <String, String>{
          'isolateId': '1',
929
          'exceptionPauseMode': 'None',
930 931
        }
      ),
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
      const FakeVmServiceRequest(
        method: 'removeBreakpoint',
        args: <String, String>{
          'isolateId': '1',
          'breakpointId': 'test-breakpoint',
        }
      ),
      const FakeVmServiceRequest(
        method: 'resume',
        args: <String, String>{
          'isolateId': '1',
        }
      ),
      listViews,
      const FakeVmServiceRequest(
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        },
      ),
      FakeVmServiceRequest(
        method: kRunInViewMethod,
        args: <String, Object>{
          'viewId': fakeFlutterView.id,
956
          'mainScript': 'main.dart.dill',
957 958 959 960 961 962 963 964 965 966 967
          'assetDirectory': 'build/flutter_assets',
        },
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        )
      )
    ]);
968 969
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
970
    unawaited(residentRunner.attach(
971 972 973
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
974 975 976 977 978 979
    ));

    final OperationResult result = await residentRunner.restart(fullRestart: true);

    expect(result.isOk, true);
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
980
  }));
981

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
  testUsingContext('ResidentRunner will alternative the name of the dill file uploaded for a hot restart', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
      listViews,
      const FakeVmServiceRequest(
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        },
      ),
      FakeVmServiceRequest(
        method: kRunInViewMethod,
        args: <String, Object>{
          'viewId': fakeFlutterView.id,
1009
          'mainScript': 'main.dart.dill',
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
          'assetDirectory': 'build/flutter_assets',
        },
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        ),
      ),
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
      listViews,
      const FakeVmServiceRequest(
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        },
      ),
      FakeVmServiceRequest(
        method: kRunInViewMethod,
        args: <String, Object>{
          'viewId': fakeFlutterView.id,
1043
          'mainScript': 'main.dart.swap.dill',
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
          'assetDirectory': 'build/flutter_assets',
        },
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        ),
      ),
      listViews,
      FakeVmServiceRequest(
        method: 'getIsolate',
        args: <String, Object>{
          'isolateId': fakeUnpausedIsolate.id,
        },
        jsonResponse: fakeUnpausedIsolate.toJson(),
      ),
      FakeVmServiceRequest(
        method: 'getVM',
        jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
      ),
      listViews,
      const FakeVmServiceRequest(
        method: 'streamListen',
        args: <String, Object>{
          'streamId': 'Isolate',
        },
      ),
      FakeVmServiceRequest(
        method: kRunInViewMethod,
        args: <String, Object>{
          'viewId': fakeFlutterView.id,
1077
          'mainScript': 'main.dart.dill',
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
          'assetDirectory': 'build/flutter_assets',
        },
      ),
      FakeVmServiceStreamResponse(
        streamId: 'Isolate',
        event: vm_service.Event(
          timestamp: 0,
          kind: vm_service.EventKind.kIsolateRunnable,
        ),
      )
    ]);
1089 1090
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
1091
    unawaited(residentRunner.attach(
1092 1093 1094
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
1095 1096 1097 1098 1099 1100 1101
    ));

    await residentRunner.restart(fullRestart: true);
    await residentRunner.restart(fullRestart: true);
    await residentRunner.restart(fullRestart: true);

    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1102
  }));
1103

1104
  testUsingContext('ResidentRunner Can handle an RPC exception from hot restart', () => testbed.run(() async {
1105 1106 1107 1108
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
1109 1110
    final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
    final Completer<void> futureAppStart = Completer<void>.sync();
1111
    unawaited(residentRunner.attach(
1112 1113 1114
      appStartedCompleter: futureAppStart,
      connectionInfoCompleter: futureConnectionInfo,
      enableDevTools: true,
1115
    ));
1116
    await futureAppStart.future;
1117
    flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, '');
1118 1119 1120 1121

    final OperationResult result = await residentRunner.restart(fullRestart: true);
    expect(result.fatal, true);
    expect(result.code, 1);
1122 1123

    expect((globals.flutterUsage as TestUsage).events, contains(
1124 1125 1126 1127 1128
      TestUsageEvent('hot', 'exception', parameters: CustomDimensions(
        hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
        hotEventSdkName: 'Android',
        hotEventEmulator: false,
        hotEventFullRestart: true,
1129
        fastReassemble: false,
1130
      )),
1131
    ));
1132
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1133
  }, overrides: <Type, Generator>{
1134
    Usage: () => TestUsage(),
1135
  }));
1136

1137
  testUsingContext('ResidentRunner uses temp directory when there is no output dill path', () => testbed.run(() {
1138
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1139
    expect(residentRunner.artifactDirectory.path, contains('flutter_tool.'));
1140 1141 1142

    final ResidentRunner otherRunner = HotRunner(
      <FlutterDevice>[
1143
        flutterDevice,
1144 1145 1146
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
1147
      dillOutputPath: globals.fs.path.join('foobar', 'app.dill'),
1148
      target: 'main.dart',
1149
      devtoolsHandler: createNoOpHandler,
1150 1151 1152 1153
    );
    expect(otherRunner.artifactDirectory.path, contains('foobar'));
  }));

1154
  testUsingContext('ResidentRunner deletes artifact directory on preExit', () => testbed.run(() async {
1155
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1156
    residentRunner.artifactDirectory.childFile('app.dill').createSync();
1157 1158
    await residentRunner.preExit();

1159
    expect(residentRunner.artifactDirectory, isNot(exists));
1160 1161
  }));

1162
  testUsingContext('ResidentRunner can run source generation', () => testbed.run(() async {
1163 1164
    final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb'))
      ..createSync(recursive: true);
1165 1166
    arbFile.writeAsStringSync('''
{
1167 1168 1169 1170 1171
  "helloWorld": "Hello, World!",
  "@helloWorld": {
    "description": "Sample description"
  }
}''');
1172
    globals.fs.file('l10n.yaml').createSync();
1173
    globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n  generate: true\n');
1174

1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
    // Create necessary files for [DartPluginRegistrantTarget]
    final File packageConfig = globals.fs.directory('.dart_tool')
        .childFile('package_config.json');
    packageConfig.createSync(recursive: true);
    packageConfig.writeAsStringSync('''
{
  "configVersion": 2,
  "packages": [
    {
      "name": "path_provider_linux",
      "rootUri": "../../../path_provider_linux",
      "packageUri": "lib/",
      "languageVersion": "2.12"
    }
  ]
}
''');
1192 1193
    // Start from an empty dart_plugin_registrant.dart file.
    globals.fs.directory('.dart_tool').childDirectory('flutter_build').childFile('dart_plugin_registrant.dart').createSync(recursive: true);
1194

1195 1196 1197
    await residentRunner.runSourceGenerators();

    expect(testLogger.errorText, isEmpty);
1198
    expect(testLogger.statusText, isEmpty);
1199 1200
  }));

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
  testUsingContext('generated main uses correct target', () => testbed.run(() async {
    final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb'))
      ..createSync(recursive: true);
    arbFile.writeAsStringSync('''
{
  "helloWorld": "Hello, World!",
  "@helloWorld": {
    "description": "Sample description"
  }
}''');
    globals.fs.file('l10n.yaml').createSync();
    globals.fs.file('pubspec.yaml').writeAsStringSync('''
flutter:
  generate: true

dependencies:
  flutter:
    sdk: flutter
  path_provider_linux: 1.0.0
''');

    // Create necessary files for [DartPluginRegistrantTarget], including a
    // plugin that will trigger generation.
    final File packageConfig = globals.fs.directory('.dart_tool')
        .childFile('package_config.json');
    packageConfig.createSync(recursive: true);
    packageConfig.writeAsStringSync('''
{
  "configVersion": 2,
  "packages": [
    {
      "name": "path_provider_linux",
      "rootUri": "../path_provider_linux",
      "packageUri": "lib/",
      "languageVersion": "2.12"
    }
  ]
}
''');
    globals.fs.file('.packages').writeAsStringSync('''
path_provider_linux:/path_provider_linux/lib/
''');
    final Directory fakePluginDir = globals.fs.directory('path_provider_linux');
    final File pluginPubspec = fakePluginDir.childFile('pubspec.yaml');
    pluginPubspec.createSync(recursive: true);
    pluginPubspec.writeAsStringSync('''
name: path_provider_linux

flutter:
  plugin:
    implements: path_provider
    platforms:
      linux:
        dartPluginClass: PathProviderLinux
''');

    residentRunner = HotRunner(
        <FlutterDevice>[
          flutterDevice,
        ],
        stayResident: false,
        debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
        target: 'custom_main.dart',
        devtoolsHandler: createNoOpHandler,
      );
    await residentRunner.runSourceGenerators();

    final File generatedMain = globals.fs.directory('.dart_tool')
        .childDirectory('flutter_build')
1270
        .childFile('dart_plugin_registrant.dart');
1271

1272
    expect(generatedMain.existsSync(), isTrue);
1273 1274 1275 1276
    expect(testLogger.errorText, isEmpty);
    expect(testLogger.statusText, isEmpty);
  }));

1277
  testUsingContext('ResidentRunner can run source generation - generation fails', () => testbed.run(() async {
1278 1279 1280 1281
    // Intentionally define arb file with wrong name. generate_localizations defaults
    // to app_en.arb.
    final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'foo.arb'))
      ..createSync(recursive: true);
1282 1283
    arbFile.writeAsStringSync('''
{
1284 1285 1286 1287 1288
  "helloWorld": "Hello, World!",
  "@helloWorld": {
    "description": "Sample description"
  }
}''');
1289
    globals.fs.file('l10n.yaml').createSync();
1290
    globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n  generate: true\n');
1291 1292 1293

    await residentRunner.runSourceGenerators();

1294 1295
    expect(testLogger.errorText, allOf(contains('Exception')));
    expect(testLogger.statusText, isEmpty);
1296 1297
  }));

1298
  testUsingContext('ResidentRunner printHelpDetails hot runner', () => testbed.run(() {
1299
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1300 1301 1302

    residentRunner.printHelp(details: true);

1303 1304
    final CommandHelp commandHelp = residentRunner.commandHelp;

1305 1306 1307 1308
    // supports service protocol
    expect(residentRunner.supportsServiceProtocol, true);
    // isRunningDebug
    expect(residentRunner.isRunningDebug, true);
1309 1310
    // does support SkSL
    expect(residentRunner.supportsWriteSkSL, true);
1311 1312 1313 1314
    // commands
    expect(testLogger.statusText, equals(
        <dynamic>[
          'Flutter run key commands.',
1315 1316
          commandHelp.r,
          commandHelp.R,
1317
          commandHelp.v,
1318 1319 1320 1321 1322 1323 1324 1325
          commandHelp.s,
          commandHelp.w,
          commandHelp.t,
          commandHelp.L,
          commandHelp.S,
          commandHelp.U,
          commandHelp.i,
          commandHelp.p,
1326
          commandHelp.I,
1327
          commandHelp.o,
1328
          commandHelp.b,
1329 1330
          commandHelp.P,
          commandHelp.a,
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
          commandHelp.M,
          commandHelp.g,
          commandHelp.hWithDetails,
          commandHelp.c,
          commandHelp.q,
          '',
          '💪 Running with sound null safety 💪',
          '',
          'An Observatory debugger and profiler on FakeDevice is available at: null',
          '',
        ].join('\n')
    ));
  }));

  testUsingContext('ResidentRunner printHelp hot runner', () => testbed.run(() {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);

    residentRunner.printHelp(details: false);

    final CommandHelp commandHelp = residentRunner.commandHelp;

    // supports service protocol
    expect(residentRunner.supportsServiceProtocol, true);
    // isRunningDebug
    expect(residentRunner.isRunningDebug, true);
    // does support SkSL
    expect(residentRunner.supportsWriteSkSL, true);
    // commands
    expect(testLogger.statusText, equals(
        <dynamic>[
          'Flutter run key commands.',
          commandHelp.r,
          commandHelp.R,
          commandHelp.hWithoutDetails,
          commandHelp.c,
          commandHelp.q,
1367 1368 1369
          '',
          '💪 Running with sound null safety 💪',
          '',
1370
          'An Observatory debugger and profiler on FakeDevice is available at: null',
1371
          '',
1372 1373
        ].join('\n')
    ));
1374 1375
  }));

1376 1377 1378 1379
  testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() {
    fakeVmServiceHost = null;
    residentRunner = ColdRunner(
      <FlutterDevice>[
1380
        flutterDevice,
1381 1382 1383
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
1384
      target: 'main.dart',
1385
      devtoolsHandler: createNoOpHandler,
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
    );
    residentRunner.printHelp(details: true);

    final CommandHelp commandHelp = residentRunner.commandHelp;

    // does not supports service protocol
    expect(residentRunner.supportsServiceProtocol, false);
    // isRunningDebug
    expect(residentRunner.isRunningDebug, false);
    // does support SkSL
    expect(residentRunner.supportsWriteSkSL, false);
    // commands
    expect(testLogger.statusText, equals(
        <dynamic>[
          'Flutter run key commands.',
1401
          commandHelp.v,
1402
          commandHelp.s,
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
          commandHelp.hWithDetails,
          commandHelp.c,
          commandHelp.q,
          ''
        ].join('\n')
    ));
  }));

  testUsingContext('ResidentRunner printHelp cold runner', () => testbed.run(() {
    fakeVmServiceHost = null;
    residentRunner = ColdRunner(
      <FlutterDevice>[
1415
        flutterDevice,
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
      target: 'main.dart',
      devtoolsHandler: createNoOpHandler,
    );
    residentRunner.printHelp(details: false);

    final CommandHelp commandHelp = residentRunner.commandHelp;

    // does not supports service protocol
    expect(residentRunner.supportsServiceProtocol, false);
    // isRunningDebug
    expect(residentRunner.isRunningDebug, false);
    // does support SkSL
    expect(residentRunner.supportsWriteSkSL, false);
    // commands
    expect(testLogger.statusText, equals(
        <dynamic>[
          'Flutter run key commands.',
          commandHelp.hWithoutDetails,
1437 1438 1439 1440 1441 1442 1443
          commandHelp.c,
          commandHelp.q,
          ''
        ].join('\n')
    ));
  }));

1444
  testUsingContext('ResidentRunner handles writeSkSL returning no data', () => testbed.run(() async {
1445
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
1446 1447
      listViews,
      FakeVmServiceRequest(
1448 1449
        method: kGetSkSLsMethod,
        args: <String, Object>{
1450
          'viewId': fakeFlutterView.id,
1451 1452 1453 1454
        },
        jsonResponse: <String, Object>{
          'SkSLs': <String, Object>{}
        }
1455
      ),
1456
    ]);
1457 1458
    await residentRunner.writeSkSL();

1459
    expect(testLogger.statusText, contains('No data was received'));
1460
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1461 1462
  }));

1463
  testUsingContext('ResidentRunner can write SkSL data to a unique file with engine revision, platform, and device name', () => testbed.run(() async {
1464
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
1465
      listViews,
1466
      FakeVmServiceRequest(
1467 1468
        method: kGetSkSLsMethod,
        args: <String, Object>{
1469
          'viewId': fakeFlutterView.id,
1470 1471 1472 1473 1474 1475 1476 1477
        },
        jsonResponse: <String, Object>{
          'SkSLs': <String, Object>{
            'A': 'B',
          }
        }
      )
    ]);
1478 1479
    await residentRunner.writeSkSL();

1480 1481 1482
    expect(testLogger.statusText, contains('flutter_01.sksl.json'));
    expect(globals.fs.file('flutter_01.sksl.json'), exists);
    expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), <String, Object>{
1483
      'platform': 'android',
1484
      'name': 'FakeDevice',
1485
      'engineRevision': 'abcdefg',
1486 1487
      'data': <String, Object>{'A': 'B'}
    });
1488
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1489 1490 1491 1492
  }, overrides: <Type, Generator>{
    FileSystemUtils: () => FileSystemUtils(
      fileSystem: globals.fs,
      platform: globals.platform,
1493 1494
    ),
    FlutterVersion: () => FakeFlutterVersion(engineRevision: 'abcdefg')
1495 1496
  }));

1497 1498 1499 1500 1501 1502 1503
  testUsingContext('ResidentRunner ignores DevtoolsLauncher when attaching with enableDevTools: false - cold mode', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
    residentRunner = ColdRunner(
      <FlutterDevice>[
1504
        flutterDevice,
1505 1506 1507 1508
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
      target: 'main.dart',
1509
      devtoolsHandler: createNoOpHandler,
1510 1511
    );

1512
    final Future<int> result = residentRunner.attach();
1513
    expect(await result, 0);
1514
  }));
1515

1516
  testUsingContext('FlutterDevice can exit from a release mode isolate with no VmService', () => testbed.run(() async {
1517
    final TestFlutterDevice flutterDevice = TestFlutterDevice(
1518
      device,
1519 1520 1521 1522
    );

    await flutterDevice.exitApps();

1523
    expect(device.appStopped, true);
1524 1525
  }));

1526 1527
  testUsingContext('FlutterDevice will exit an un-paused isolate using stopApp', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1528
    final TestFlutterDevice flutterDevice = TestFlutterDevice(
1529
      device,
1530
    );
1531
    flutterDevice.vmService = fakeVmServiceHost.vmService;
1532

1533 1534 1535
    final Future<void> exitFuture = flutterDevice.exitApps();

    await expectLater(exitFuture, completes);
1536
    expect(device.appStopped, true);
1537
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1538
  }));
1539

1540
  testUsingContext('HotRunner writes vm service file when providing debugging option', () => testbed.run(() async {
1541 1542 1543
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1544
    ], wsAddress: testUri);
1545
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
1546 1547
    residentRunner = HotRunner(
      <FlutterDevice>[
1548
        flutterDevice,
1549 1550 1551
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
1552
      target: 'main.dart',
1553
      devtoolsHandler: createNoOpHandler,
1554
    );
1555

1556
    await residentRunner.run(enableDevTools: true);
1557

1558
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1559
    expect(await globals.fs.file('foo').readAsString(), testUri.toString());
1560
  }));
1561

1562
  testUsingContext('HotRunner copies compiled app.dill to cache during startup', () => testbed.run(() async {
1563 1564 1565
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1566
    ], wsAddress: testUri);
1567 1568 1569
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
    residentRunner = HotRunner(
      <FlutterDevice>[
1570
        flutterDevice,
1571 1572 1573
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
1574
      target: 'main.dart',
1575
      devtoolsHandler: createNoOpHandler,
1576 1577
    );
    residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1578

1579
    await residentRunner.run(enableDevTools: true);
1580 1581

    expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill')).readAsString(), 'ABC');
1582
  }));
1583

1584 1585 1586 1587
  testUsingContext('HotRunner copies compiled app.dill to cache during startup with dart defines', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1588
    ], wsAddress: testUri);
1589 1590 1591
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
    residentRunner = HotRunner(
      <FlutterDevice>[
1592
        flutterDevice,
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(
        const BuildInfo(
          BuildMode.debug,
          '',
          treeShakeIcons: false,
          dartDefines: <String>['a', 'b'],
        )
      ),
1603
      target: 'main.dart',
1604
      devtoolsHandler: createNoOpHandler,
1605 1606
    );
    residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1607

1608
    await residentRunner.run(enableDevTools: true);
1609 1610 1611

    expect(await globals.fs.file(globals.fs.path.join(
      'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC');
1612
  }));
1613

1614 1615 1616 1617
  testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1618
    ], wsAddress: testUri);
1619 1620 1621
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
    residentRunner = HotRunner(
      <FlutterDevice>[
1622
        flutterDevice,
1623 1624 1625 1626 1627 1628 1629
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(
        const BuildInfo(
          BuildMode.debug,
          '',
          treeShakeIcons: false,
1630
          extraFrontEndOptions: <String>['--enable-experiment=non-nullable']
1631 1632
        )
      ),
1633
      target: 'main.dart',
1634
      devtoolsHandler: createNoOpHandler,
1635 1636
    );
    residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1637

1638
    await residentRunner.run(enableDevTools: true);
1639 1640

    expect(await globals.fs.file(globals.fs.path.join(
1641
      'build', 'cache.dill')).readAsString(), 'ABC');
1642
  }));
1643

1644
  testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async {
1645 1646 1647
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1648
    ], wsAddress: testUri);
1649 1650 1651
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
    residentRunner = HotRunner(
      <FlutterDevice>[
1652
        flutterDevice,
1653 1654 1655 1656
      ],
      stayResident: false,
      dillOutputPath: 'test',
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
1657
      target: 'main.dart',
1658
      devtoolsHandler: createNoOpHandler,
1659 1660
    );
    residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1661

1662
    await residentRunner.run(enableDevTools: true);
1663 1664

    expect(globals.fs.file(globals.fs.path.join('build', 'cache.dill')), isNot(exists));
1665
  }));
1666

1667
  testUsingContext('HotRunner copies compiled app.dill to cache during startup with --track-widget-creation', () => testbed.run(() async {
1668 1669 1670
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1671
    ], wsAddress: testUri);
1672 1673 1674
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
    residentRunner = HotRunner(
      <FlutterDevice>[
1675
        flutterDevice,
1676 1677 1678 1679 1680 1681 1682 1683
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        trackWidgetCreation: true,
      )),
1684
      target: 'main.dart',
1685
      devtoolsHandler: createNoOpHandler,
1686 1687
    );
    residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1688

1689
    await residentRunner.run(enableDevTools: true);
1690 1691

    expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC');
1692
  }));
1693

1694
  testUsingContext('HotRunner calls device dispose', () => testbed.run(() async {
1695 1696 1697
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
1698
    ], wsAddress: testUri);
1699
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
1700 1701
    residentRunner = HotRunner(
      <FlutterDevice>[
1702
        flutterDevice,
1703 1704 1705
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
1706
      target: 'main.dart',
1707
      devtoolsHandler: createNoOpHandler,
1708 1709 1710
    );

    await residentRunner.run();
1711
    expect(device.disposed, true);
1712
  }));
1713

1714
  testUsingContext('HotRunner handles failure to write vmservice file', () => testbed.run(() async {
1715 1716 1717 1718
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      listViews,
    ]);
1719
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
1720 1721
    residentRunner = HotRunner(
      <FlutterDevice>[
1722
        flutterDevice,
1723 1724 1725
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
1726
      target: 'main.dart',
1727
      devtoolsHandler: createNoOpHandler,
1728
    );
1729

1730
    await residentRunner.run(enableDevTools: true);
1731

1732
    expect(testLogger.errorText, contains('Failed to write vmservice-out-file at foo'));
1733
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1734
  }, overrides: <Type, Generator>{
1735
    FileSystem: () => ThrowingForwardingFileSystem(MemoryFileSystem.test()),
1736
  }));
1737

1738
  testUsingContext('ColdRunner writes vm service file when providing debugging option', () => testbed.run(() async {
1739 1740
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
1741
    ], wsAddress: testUri);
1742
    globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
1743 1744
    residentRunner = ColdRunner(
      <FlutterDevice>[
1745
        flutterDevice,
1746 1747 1748
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
1749
      target: 'main.dart',
1750
      devtoolsHandler: createNoOpHandler,
1751
    );
1752

1753
    await residentRunner.run(enableDevTools: true);
1754

1755
    expect(await globals.fs.file('foo').readAsString(), testUri.toString());
1756
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
1757
  }));
1758

1759
  testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async {
1760
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1761
    final FakeDevice device = FakeDevice(targetPlatform: TargetPlatform.web_javascript);
1762
    final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
1763
      device,
1764 1765 1766 1767 1768 1769
      buildInfo: const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        nullSafetyMode: NullSafetyMode.unsound,
      ),
1770
      target: null,
1771
      platform: FakePlatform(),
1772
    )).generator as DefaultResidentCompiler;
1773

1774
    expect(residentCompiler.initializeFromDill,
1775
      globals.fs.path.join(getBuildDirectory(), 'fbbe6a61fb7a1de317d381f8df4814e5.cache.dill'));
1776
    expect(residentCompiler.librariesSpec,
1777
      globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson))
1778
        .uri.toString());
1779 1780
    expect(residentCompiler.targetModel, TargetModel.dartdevc);
    expect(residentCompiler.sdkRoot,
1781
      '${globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path}/');
1782
    expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformKernelDill');
1783 1784 1785 1786 1787 1788 1789 1790
  }, overrides: <Type, Generator>{
    Artifacts: () => Artifacts.test(),
    FileSystem: () => MemoryFileSystem.test(),
    ProcessManager: () => FakeProcessManager.any(),
  });

  testUsingContext('FlutterDevice uses dartdevc configuration when targeting web with null-safety autodetected', () async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1791
    final FakeDevice device = FakeDevice(targetPlatform: TargetPlatform.web_javascript);
1792 1793

    final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
1794
      device,
1795 1796 1797 1798 1799 1800 1801
      buildInfo: const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        extraFrontEndOptions: <String>['--enable-experiment=non-nullable'],
      ),
      target: null,
1802
      platform: FakePlatform(),
1803 1804 1805
    )).generator as DefaultResidentCompiler;

    expect(residentCompiler.initializeFromDill,
1806
      globals.fs.path.join(getBuildDirectory(), '80b1a4cf4e7b90e1ab5f72022a0bc624.cache.dill'));
1807
    expect(residentCompiler.librariesSpec,
1808
      globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson))
1809 1810 1811
        .uri.toString());
    expect(residentCompiler.targetModel, TargetModel.dartdevc);
    expect(residentCompiler.sdkRoot,
1812
      '${globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path}/');
1813
    expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformSoundKernelDill');
1814 1815 1816 1817
  }, overrides: <Type, Generator>{
    Artifacts: () => Artifacts.test(),
    FileSystem: () => MemoryFileSystem.test(),
    ProcessManager: () => FakeProcessManager.any(),
1818
  });
1819

1820 1821
  testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1822
    final FakeDevice device = FakeDevice();
1823 1824

    final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
1825
      device,
1826 1827 1828 1829 1830 1831
      buildInfo: const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        extraFrontEndOptions: <String>[],
      ),
1832
      target: null, platform: null,
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
    )).generator as DefaultResidentCompiler;

    expect(residentCompiler.extraFrontEndOptions,
      contains('--flutter-widget-cache'));
  }, overrides: <Type, Generator>{
    Artifacts: () => Artifacts.test(),
    FileSystem: () => MemoryFileSystem.test(),
    ProcessManager: () => FakeProcessManager.any(),
    FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true)
  });

1844
   testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag', () async {
1845
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1846
    final FakeDevice device = FakeDevice();
1847

1848 1849

    final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
1850
      device,
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
      buildInfo: const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        extraFrontEndOptions: <String>[],
      ),
      target: null, platform: null,
    )).generator as DefaultResidentCompiler;

    expect(residentCompiler.extraFrontEndOptions,
      contains('--enable-experiment=alternative-invalidation-strategy'));
  }, overrides: <Type, Generator>{
    Artifacts: () => Artifacts.test(),
    FileSystem: () => MemoryFileSystem.test(),
    ProcessManager: () => FakeProcessManager.any(),
  });

1868 1869
   testUsingContext('FlutterDevice passes initializeFromDill parameter if specified', () async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1870
    final FakeDevice device = FakeDevice();
1871 1872

    final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
1873
      device,
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
      buildInfo: const BuildInfo(
        BuildMode.debug,
        '',
        treeShakeIcons: false,
        extraFrontEndOptions: <String>[],
        initializeFromDill: '/foo/bar.dill',
      ),
      target: null, platform: null,
    )).generator as DefaultResidentCompiler;

    expect(residentCompiler.initializeFromDill, '/foo/bar.dill');
  }, overrides: <Type, Generator>{
    Artifacts: () => Artifacts.test(),
    FileSystem: () => MemoryFileSystem.test(),
    ProcessManager: () => FakeProcessManager.any(),
  });

1891 1892
  testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1893
    final FakeDevice device = FakeDevice()
1894
      ..dds = DartDevelopmentService();
1895
    ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) {
1896 1897 1898 1899
      expect(uri, Uri(scheme: 'foo', host: 'bar'));
      expect(enableAuthCodes, isTrue);
      expect(ipv6, isFalse);
      expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
1900 1901 1902 1903 1904
      throw FakeDartDevelopmentServiceException(message:
        'Existing VM service clients prevent DDS from taking control.',
      );
    };
    final TestFlutterDevice flutterDevice = TestFlutterDevice(
1905
      device,
1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
      observatoryUris: Stream<Uri>.value(testUri),
    );
    bool caught = false;
    final Completer<void>done = Completer<void>();
    runZonedGuarded(() {
      flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete());
    }, (Object e, StackTrace st) {
      expect(e is ToolExit, true);
      expect((e as ToolExit).message,
        contains('Existing VM service clients prevent DDS from taking control.',
      ));
      done.complete();
      caught = true;
    });
    await done.future;
    if (!caught) {
      fail('Expected ToolExit to be thrown.');
    }
1924 1925 1926 1927 1928 1929 1930 1931 1932
  }, overrides: <Type, Generator>{
    VMServiceConnector: () => (Uri httpUri, {
      ReloadSources reloadSources,
      Restart restart,
      CompileExpression compileExpression,
      GetSkSLMethod getSkSLMethod,
      PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
      io.CompressionOptions compression,
      Device device,
1933
      Logger logger,
1934
    }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
1935 1936
  }));

1937 1938 1939 1940 1941
  testUsingContext('Host VM service ipv6 defaults', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
    final FakeDevice device = FakeDevice()
      ..dds = DartDevelopmentService();
    final Completer<void>done = Completer<void>();
1942
    ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) async {
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968
      expect(uri, Uri(scheme: 'foo', host: 'bar'));
      expect(enableAuthCodes, isFalse);
      expect(ipv6, isTrue);
      expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0));
      done.complete();
      return null;
    };
    final TestFlutterDevice flutterDevice = TestFlutterDevice(
      device,
      observatoryUris: Stream<Uri>.value(testUri),
    );
    await flutterDevice.connect(allowExistingDdsInstance: true, ipv6: true, disableServiceAuthCodes: true);
    await done.future;
  }, overrides: <Type, Generator>{
    VMServiceConnector: () => (Uri httpUri, {
      ReloadSources reloadSources,
      Restart restart,
      CompileExpression compileExpression,
      GetSkSLMethod getSkSLMethod,
      PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
      io.CompressionOptions compression,
      Device device,
      Logger logger,
    }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
  }));

1969 1970
  testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async {
    // See https://github.com/flutter/flutter/issues/72385 for context.
1971
    final FakeDevice device = FakeDevice()
1972
      ..dds = DartDevelopmentService();
1973
    ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) {
1974 1975 1976 1977
      expect(uri, Uri(scheme: 'foo', host: 'bar'));
      expect(enableAuthCodes, isTrue);
      expect(ipv6, isFalse);
      expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
1978 1979 1980
      throw FakeDartDevelopmentServiceException(message: 'No URI');
    };
    final TestFlutterDevice flutterDevice = TestFlutterDevice(
1981
      device,
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
      observatoryUris: Stream<Uri>.value(testUri),
    );
    bool caught = false;
    final Completer<void>done = Completer<void>();
    runZonedGuarded(() {
      flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete());
    }, (Object e, StackTrace st) {
      expect(e is StateError, true);
      expect((e as StateError).message, contains('No URI'));
      expect(testLogger.errorText, contains(
        'DDS has failed to start and there is not an existing DDS instance',
      ));
      done.complete();
      caught = true;
    });
    await done.future;
    if (!caught) {
      fail('Expected a StateError to be thrown.');
    }
2001 2002 2003 2004 2005 2006 2007 2008 2009
  }, overrides: <Type, Generator>{
    VMServiceConnector: () => (Uri httpUri, {
      ReloadSources reloadSources,
      Restart restart,
      CompileExpression compileExpression,
      GetSkSLMethod getSkSLMethod,
      PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
      io.CompressionOptions compression,
      Device device,
2010
      Logger logger,
2011
    }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
2012
  }));
2013

2014
  testUsingContext('nextPlatform moves through expected platforms', () {
2015 2016 2017 2018 2019
    expect(nextPlatform('android'), 'iOS');
    expect(nextPlatform('iOS'), 'fuchsia');
    expect(nextPlatform('fuchsia'), 'macOS');
    expect(nextPlatform('macOS'), 'android');
    expect(() => nextPlatform('unknown'), throwsAssertionError);
2020
  });
2021 2022 2023 2024

  testUsingContext('cleanupAtFinish shuts down resident devtools handler', () => testbed.run(() async {
    residentRunner = HotRunner(
      <FlutterDevice>[
2025
        flutterDevice,
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
      target: 'main.dart',
      devtoolsHandler: createNoOpHandler,
    );
    await residentRunner.cleanupAtFinish();

    expect((residentRunner.residentDevtoolsHandler as NoOpDevtoolsHandler).wasShutdown, true);
  }));
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101

  testUsingContext('HotRunner sets asset directory when first evict assets', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      setAssetBundlePath,
      evict,
    ]);
    residentRunner = HotRunner(
      <FlutterDevice>[
        flutterDevice,
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
      target: 'main.dart',
      devtoolsHandler: createNoOpHandler,
    );

    (flutterDevice.devFS as FakeDevFS).assetPathsToEvict = <String>{'asset'};

    expect(flutterDevice.devFS.hasSetAssetDirectory, false);
    await (residentRunner as HotRunner).evictDirtyAssets();
    expect(flutterDevice.devFS.hasSetAssetDirectory, true);
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
  }));

  testUsingContext('HotRunner does not sets asset directory when no assets to evict', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
    ]);
    residentRunner = HotRunner(
      <FlutterDevice>[
        flutterDevice,
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
      target: 'main.dart',
      devtoolsHandler: createNoOpHandler,
    );

    expect(flutterDevice.devFS.hasSetAssetDirectory, false);
    await (residentRunner as HotRunner).evictDirtyAssets();
    expect(flutterDevice.devFS.hasSetAssetDirectory, false);
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
  }));

  testUsingContext('HotRunner does not set asset directory if it has been set before', () => testbed.run(() async {
    fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
      listViews,
      evict,
    ]);
    residentRunner = HotRunner(
      <FlutterDevice>[
        flutterDevice,
      ],
      stayResident: false,
      debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
      target: 'main.dart',
      devtoolsHandler: createNoOpHandler,
    );

    (flutterDevice.devFS as FakeDevFS).assetPathsToEvict = <String>{'asset'};
    flutterDevice.devFS.hasSetAssetDirectory = true;

    await (residentRunner as HotRunner).evictDirtyAssets();
    expect(flutterDevice.devFS.hasSetAssetDirectory, true);
    expect(fakeVmServiceHost.hasRemainingExpectations, false);
  }));
2102 2103
}

2104
class FakeDartDevelopmentServiceException implements dds.DartDevelopmentServiceException {
2105 2106
  FakeDartDevelopmentServiceException({this.message = defaultMessage});

2107 2108 2109 2110
  @override
  final int errorCode = dds.DartDevelopmentServiceException.existingDdsInstanceError;

  @override
2111 2112
  final String message;
  static const String defaultMessage = 'A DDS instance is already connected at http://localhost:8181';
2113 2114
}

2115
class TestFlutterDevice extends FlutterDevice {
2116
  TestFlutterDevice(Device device, { Stream<Uri> observatoryUris })
2117
    : super(device, buildInfo: BuildInfo.debug) {
2118 2119
    _observatoryUris = observatoryUris;
  }
2120

2121
  @override
2122 2123
  Stream<Uri> get observatoryUris => _observatoryUris;
  Stream<Uri> _observatoryUris;
2124 2125
}

2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
class ThrowingForwardingFileSystem extends ForwardingFileSystem {
  ThrowingForwardingFileSystem(FileSystem delegate) : super(delegate);

  @override
  File file(dynamic path) {
    if (path == 'foo') {
      throw const FileSystemException();
    }
    return delegate.file(path);
  }
}
2137

2138 2139 2140 2141 2142 2143 2144
class FakeFlutterDevice extends Fake implements FlutterDevice {
  FakeVmServiceHost Function() vmServiceHost;
  Uri testUri;
  UpdateFSReport report = UpdateFSReport(
    success: true,
    invalidatedSourcesCount: 1,
  );
2145 2146
  Exception reportError;
  Exception runColdError;
2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235
  int runHotCode = 0;
  int runColdCode = 0;

  @override
  ResidentCompiler generator;

  @override
  Stream<Uri> get observatoryUris => Stream<Uri>.value(testUri);

  @override
  FlutterVmService get vmService => vmServiceHost?.call()?.vmService;

  DevFS _devFS;

  @override
  DevFS get devFS => _devFS;

  @override
  set devFS(DevFS value) { }

  @override
  Device device;

  @override
  Future<void> stopEchoingDeviceLog() async { }

  @override
  Future<void> initLogReader() async { }

  @override
  Future<Uri> setupDevFS(String fsName, Directory rootDirectory) async {
    return testUri;
  }

  @override
  Future<int> runHot({HotRunner hotRunner, String route}) async {
    return runHotCode;
  }

  @override
  Future<int> runCold({ColdRunner coldRunner, String route}) async {
    if (runColdError != null) {
      throw runColdError;
    }
    return runColdCode;
  }

  @override
  Future<void> connect({
    ReloadSources reloadSources,
    Restart restart,
    CompileExpression compileExpression,
    GetSkSLMethod getSkSLMethod,
    PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
    int hostVmServicePort,
    int ddsPort,
    bool disableServiceAuthCodes = false,
    bool enableDds = true,
    @required bool allowExistingDdsInstance,
    bool ipv6 = false,
  }) async { }

  @override
  Future<UpdateFSReport> updateDevFS({
    Uri mainUri,
    String target,
    AssetBundle bundle,
    DateTime firstBuildTime,
    bool bundleFirstUpload = false,
    bool bundleDirty = false,
    bool fullRestart = false,
    String projectRootPath,
    String pathToReload,
    String dillOutputPath,
    List<Uri> invalidatedFiles,
    PackageConfig packageConfig,
  }) async {
    if (reportError != null) {
      throw reportError;
    }
    return report;
  }

  @override
  Future<void> updateReloadStatus(bool wasReloadSuccessful) async { }
}

class FakeDelegateFlutterDevice extends FlutterDevice {
  FakeDelegateFlutterDevice(
2236 2237 2238 2239
    Device device,
    BuildInfo buildInfo,
    ResidentCompiler residentCompiler,
    this.fakeDevFS,
2240
  ) : super(device, buildInfo: buildInfo, generator: residentCompiler);
2241 2242 2243 2244 2245

  @override
  Future<void> connect({
    ReloadSources reloadSources,
    Restart restart,
2246
    bool enableDds = true,
2247
    bool disableServiceAuthCodes = false,
2248
    bool ipv6 = false,
2249 2250
    CompileExpression compileExpression,
    GetSkSLMethod getSkSLMethod,
2251 2252
    int hostVmServicePort,
    int ddsPort,
2253
    PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
2254
    bool allowExistingDdsInstance = false,
2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267
  }) async { }


  final DevFS fakeDevFS;

  @override
  DevFS get devFS => fakeDevFS;

  @override
  set devFS(DevFS value) {}
}

class FakeResidentCompiler extends Fake implements ResidentCompiler {
2268 2269 2270
  CompilerOutput nextOutput;
  bool didSuppressErrors = false;

2271 2272 2273 2274 2275 2276
  @override
  Future<CompilerOutput> recompile(
    Uri mainUri,
    List<Uri> invalidatedFiles, {
    @required String outputPath,
    @required PackageConfig packageConfig,
2277 2278
    @required String projectRootPath,
    @required FileSystem fs,
2279
    bool suppressErrors = false,
2280
    bool checkDartPluginRegistry = false,
2281
  }) async {
2282 2283
    didSuppressErrors = suppressErrors;
    return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
  }

  @override
  void accept() { }

  @override
  void reset() { }
}

class FakeProjectFileInvalidator extends Fake implements ProjectFileInvalidator {
  @override
  Future<InvalidationResult> findInvalidated({
    @required DateTime lastCompiled,
    @required List<Uri> urisToMonitor,
    @required String packagesPath,
    @required PackageConfig packageConfig,
    bool asyncScanning = false,
  }) async {
    return InvalidationResult(
      packageConfig: packageConfig ?? PackageConfig.empty,
      uris: <Uri>[Uri.parse('file:///hello_world/main.dart'),
    ]);
  }
}
2308

2309 2310 2311
// Unfortunately Device, despite not being immutable, has an `operator ==`.
// Until we fix that, we have to also ignore related lints here.
// ignore: avoid_implementing_value_types
2312 2313 2314 2315 2316 2317
class FakeDevice extends Fake implements Device {
  FakeDevice({
    String sdkNameAndVersion = 'Android',
    TargetPlatform targetPlatform = TargetPlatform.android_arm,
    bool isLocalEmulator = false,
    this.supportsHotRestart = true,
2318 2319
    this.supportsScreenshot = true,
    this.supportsFlutterExit = true,
2320 2321 2322 2323 2324 2325 2326 2327
  }) : _isLocalEmulator = isLocalEmulator,
       _targetPlatform = targetPlatform,
       _sdkNameAndVersion = sdkNameAndVersion;

  final bool _isLocalEmulator;
  final TargetPlatform _targetPlatform;
  final String _sdkNameAndVersion;

2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340
  bool disposed = false;
  bool appStopped = false;
  bool failScreenshot = false;

  @override
  bool supportsHotRestart;

  @override
  bool supportsScreenshot;

  @override
  bool supportsFlutterExit;

2341
  @override
2342 2343 2344
  PlatformType get platformType => _targetPlatform == TargetPlatform.web_javascript
    ? PlatformType.web
    : PlatformType.android;
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358

  @override
  Future<String> get sdkNameAndVersion async => _sdkNameAndVersion;

  @override
  Future<TargetPlatform> get targetPlatform async => _targetPlatform;

  @override
  Future<bool> get isLocalEmulator async => _isLocalEmulator;

  @override
  String get name => 'FakeDevice';

  @override
2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387
  DartDevelopmentService dds;

  @override
  Future<void> dispose() async {
    disposed = true;
  }

  @override
  Future<bool> stopApp(covariant ApplicationPackage app, {String userIdentifier}) async {
    appStopped = true;
    return true;
  }

  @override
  Future<void> takeScreenshot(File outputFile) async {
    if (failScreenshot) {
      throw Exception();
    }
    outputFile.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
  }

  @override
  FutureOr<DeviceLogReader> getLogReader({
    covariant ApplicationPackage app,
    bool includePastLogs = false,
  }) => NoOpDeviceLogReader(name);

  @override
  DevicePortForwarder portForwarder = const NoOpDevicePortForwarder();
2388
}
2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410

class FakeDevFS extends Fake implements DevFS {
  @override
  DateTime lastCompiled = DateTime(2000);

  @override
  PackageConfig lastPackageConfig = PackageConfig.empty;

  @override
  List<Uri> sources = <Uri>[];

  @override
  Uri baseUri = Uri();

  @override
  Future<void> destroy() async { }

  @override
  Set<String> assetPathsToEvict = <String>{};

  UpdateFSReport nextUpdateReport = UpdateFSReport(success: true);

2411 2412 2413
  @override
  bool hasSetAssetDirectory = false;

2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443
  @override
  Future<Uri> create() async {
    return Uri();
  }

  @override
  void resetLastCompiled() {
    lastCompiled = null;
  }

  @override
  Future<UpdateFSReport> update({
    @required Uri mainUri,
    @required ResidentCompiler generator,
    @required bool trackWidgetCreation,
    @required String pathToReload,
    @required List<Uri> invalidatedFiles,
    @required PackageConfig packageConfig,
    @required String dillOutputPath,
    DevFSWriter devFSWriter,
    String target,
    AssetBundle bundle,
    DateTime firstBuildTime,
    bool bundleFirstUpload = false,
    bool fullRestart = false,
    String projectRootPath,
  }) async {
    return nextUpdateReport;
  }
}