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

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

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

25 26
  setUp(() {
    fileSystem = MemoryFileSystem.test();
27
    fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
28 29 30 31
    platform = FakePlatform(
      operatingSystem: 'macos',
      environment: <String, String>{},
    );
32
    chromeLauncher = ChromiumLauncher(
33 34
      fileSystem: fileSystem,
      platform: platform,
35
      processManager: fakeProcessManager,
36
      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 {
    final ValidationResult result = await webValidator.validate();
48

49
    expect(result.type, ValidationType.installed);
50 51
  });

52
  testWithoutContext('WebValidator Can notice missing macOS executable ', () async {
53
    fakeProcessManager.excludedExecutables.add(kMacOSExecutable);
54 55 56 57 58 59 60

    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 {
61
    fakeProcessManager.excludedExecutables.add(kMacOSExecutable);
62 63 64

    final ValidationResult result = await webValidator.validate();

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