2016-03-04 23:01:26 +00:00
|
|
|
// Copyright 2016 The Chromium 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:test/test.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_tools/src/service_protocol.dart';
|
|
|
|
|
|
|
|
import 'src/mocks.dart';
|
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2016-03-04 23:01:26 +00:00
|
|
|
group('service_protocol', () {
|
|
|
|
test('Discovery Heartbeat', () async {
|
|
|
|
MockDeviceLogReader logReader = new MockDeviceLogReader();
|
|
|
|
ServiceProtocolDiscovery discoverer =
|
|
|
|
new ServiceProtocolDiscovery(logReader);
|
|
|
|
// Get next port future.
|
2016-03-12 08:32:34 +00:00
|
|
|
Future<int> nextPort = discoverer.nextPort();
|
2016-03-04 23:01:26 +00:00
|
|
|
expect(nextPort, isNotNull);
|
|
|
|
// Inject some lines.
|
|
|
|
logReader.addLine('HELLO WORLD');
|
|
|
|
logReader.addLine(
|
|
|
|
'Observatory listening on http://127.0.0.1:9999');
|
|
|
|
// Await the port.
|
|
|
|
expect(await nextPort, 9999);
|
|
|
|
// Get next port future.
|
|
|
|
nextPort = discoverer.nextPort();
|
|
|
|
logReader.addLine(
|
|
|
|
'Observatory listening on http://127.0.0.1:3333');
|
|
|
|
expect(await nextPort, 3333);
|
|
|
|
// Get next port future.
|
|
|
|
nextPort = discoverer.nextPort();
|
|
|
|
// Inject some bad lines.
|
|
|
|
logReader.addLine('Observatory listening on http://127.0.0.1');
|
|
|
|
logReader.addLine('Observatory listening on http://127.0.0.1:');
|
|
|
|
logReader.addLine(
|
|
|
|
'Observatory listening on http://127.0.0.1:apple');
|
|
|
|
int port = await nextPort.timeout(
|
|
|
|
const Duration(milliseconds: 100), onTimeout: () => 77);
|
|
|
|
// Expect the timeout port.
|
|
|
|
expect(port, 77);
|
2016-03-15 17:00:08 +00:00
|
|
|
// Get next port future.
|
|
|
|
nextPort = discoverer.nextPort();
|
|
|
|
logReader.addLine(
|
|
|
|
'I/flutter : Observatory listening on http://127.0.0.1:52584');
|
|
|
|
expect(await nextPort, 52584);
|
2016-03-04 23:01:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|