vm_service_web_test.dart 3.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';

import '../integration.shard/test_data/basic_project.dart';
import '../integration.shard/test_driver.dart';
import '../integration.shard/test_utils.dart';
import '../src/common.dart';

void main() {
18
  late Directory tempDir;
19
  final BasicProjectWithUnaryMain project = BasicProjectWithUnaryMain();
20
  late FlutterRunTestDriver flutter;
21 22 23 24 25

  group('Clients of flutter run on web with DDS enabled', () {
    setUp(() async {
      tempDir = createResolvedTempDirectorySync('run_test.');
      await project.setUpIn(tempDir);
26
      flutter = FlutterRunTestDriver(tempDir);
27 28 29 30 31 32 33 34 35 36
    });

    tearDown(() async {
      await flutter.stop();
      tryToDelete(tempDir);
    });

    testWithoutContext('can validate flutter version', () async {
      await flutter.run(
        withDebugger: true, chrome: true,
37
        additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
38 39 40 41 42 43 44 45 46 47 48

      expect(flutter.vmServiceWsUri, isNotNull);

      final VmService client =
        await vmServiceConnectUri('${flutter.vmServiceWsUri}');
      await validateFlutterVersion(client);
    });

    testWithoutContext('can validate flutter version in parallel', () async {
      await flutter.run(
        withDebugger: true, chrome: true,
49
        additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
50 51 52 53 54 55 56 57 58 59 60

      expect(flutter.vmServiceWsUri, isNotNull);

      final VmService client1 =
        await vmServiceConnectUri('${flutter.vmServiceWsUri}');

      final VmService client2 =
        await vmServiceConnectUri('${flutter.vmServiceWsUri}');

      await Future.wait(<Future<void>>[
        validateFlutterVersion(client1),
61 62
        validateFlutterVersion(client2),
      ]);
63
    }, skip: true); // https://github.com/flutter/flutter/issues/99003
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  });

  group('Clients of flutter run on web with DDS disabled', () {
    setUp(() async {
      tempDir = createResolvedTempDirectorySync('run_test.');
      await project.setUpIn(tempDir);
      flutter = FlutterRunTestDriver(tempDir, spawnDdsInstance: false);
    });

    tearDown(() async {
      await flutter.stop();
      tryToDelete(tempDir);
    });

    testWithoutContext('can validate flutter version', () async {
      await flutter.run(
        withDebugger: true, chrome: true,
81
        additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
82 83 84 85 86 87 88 89 90 91 92

      expect(flutter.vmServiceWsUri, isNotNull);

      final VmService client =
        await vmServiceConnectUri('${flutter.vmServiceWsUri}');
      await validateFlutterVersion(client);
    });
  });
}

Future<void> validateFlutterVersion(VmService client) async {
93
  String? method;
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

  final Future<dynamic> registration = expectLater(
    client.onEvent('Service'),
      emitsThrough(predicate((Event e) {
        if (e.kind == EventKind.kServiceRegistered &&
            e.service == 'flutterVersion') {
          method = e.method;
          return true;
        }
        return false;
      }))
    );

  await client.streamListen('Service');
  await registration;
  await client.streamCancel('Service');

111
  final dynamic version1 = await client.callServiceExtension(method!);
112 113
  expect(version1, const TypeMatcher<Success>()
    .having((Success r) => r.type, 'type', 'Success')
114
    .having((Success r) => r.json!['frameworkVersion'], 'frameworkVersion', isNotNull));
115 116 117

  await client.dispose();
}