web_validator_test.dart 2.48 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
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
7
import 'package:flutter_tools/src/base/logger.dart';
8
import 'package:flutter_tools/src/base/platform.dart';
9 10 11 12
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/web/chrome.dart';
import 'package:flutter_tools/src/web/web_validator.dart';
import 'package:mockito/mockito.dart';
13
import 'package:process/process.dart';
14

15
import '../../src/common.dart';
16
import '../../src/fake_process_manager.dart';
17 18

void main() {
19 20
  Platform platform;
  ProcessManager processManager;
21
  ChromiumLauncher chromeLauncher;
22
  FileSystem fileSystem;
23
  ChromiumValidator webValidator;
24

25 26 27 28 29 30 31
  setUp(() {
    fileSystem = MemoryFileSystem.test();
    processManager = MockProcessManager();
    platform = FakePlatform(
      operatingSystem: 'macos',
      environment: <String, String>{},
    );
32
    chromeLauncher = ChromiumLauncher(
33 34 35 36
      fileSystem: fileSystem,
      platform: platform,
      processManager: processManager,
      operatingSystemUtils: null,
37
      browserFinder: findChromeExecutable,
38
      logger: BufferLogger.test(),
39
    );
40
    webValidator = webValidator = ChromeValidator(
41
      platform: platform,
42
      chromiumLauncher: chromeLauncher,
43 44
    );
  });
45

46 47
  testWithoutContext('WebValidator can find executable on macOS', () async {
    when(processManager.canRun(kMacOSExecutable)).thenReturn(true);
48

49
    final ValidationResult result = await webValidator.validate();
50

51
    expect(result.type, ValidationType.installed);
52 53
  });

54 55 56 57 58 59 60 61 62 63 64 65 66
  testWithoutContext('WebValidator Can notice missing macOS executable ', () async {
    when(processManager.canRun(kMacOSExecutable)).thenReturn(false);

    final ValidationResult result = await webValidator.validate();

    expect(result.type, ValidationType.missing);
  });

  testWithoutContext('WebValidator does not warn about CHROME_EXECUTABLE unless it cant find chrome ', () async {
    when(processManager.canRun(kMacOSExecutable)).thenReturn(false);

    final ValidationResult result = await webValidator.validate();

67
    expect(result.messages, const <ValidationMessage>[
68 69 70 71 72
      ValidationMessage.hint(
          'Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.'),
    ]);
    expect(result.type, ValidationType.missing);
  });
73
}
74

75
class MockProcessManager extends Mock implements ProcessManager {}