vm_service_web_test.dart 3.67 KB
Newer Older
1 2 3 4 5 6 7 8
// 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';
9
import 'package:flutter_tools/src/vmservice.dart';
10 11 12 13 14 15 16 17 18
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() {
19
  late Directory tempDir;
20
  final BasicProjectWithUnaryMain project = BasicProjectWithUnaryMain();
21
  late FlutterRunTestDriver flutter;
22 23 24 25 26

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

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

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

      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,
50
        additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
51 52 53 54 55 56 57 58 59 60 61

      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),
62 63
        validateFlutterVersion(client2),
      ]);
64
    }, skip: true); // https://github.com/flutter/flutter/issues/99003
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  });

  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,
82
        additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
83 84 85 86 87 88 89 90 91 92 93

      expect(flutter.vmServiceWsUri, isNotNull);

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

Future<void> validateFlutterVersion(VmService client) async {
94
  String? method;
95 96 97 98 99

  final Future<dynamic> registration = expectLater(
    client.onEvent('Service'),
      emitsThrough(predicate((Event e) {
        if (e.kind == EventKind.kServiceRegistered &&
100
            e.service == kFlutterVersionServiceName) {
101 102 103 104 105 106 107 108 109 110 111
          method = e.method;
          return true;
        }
        return false;
      }))
    );

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

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

  await client.dispose();
}