2015-11-02 21:05:05 +00:00
|
|
|
// Copyright 2015 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';
|
2016-02-21 06:00:11 +00:00
|
|
|
import 'dart:io';
|
2015-11-02 21:05:05 +00:00
|
|
|
|
2016-01-28 06:38:57 +00:00
|
|
|
import 'package:flutter_tools/src/base/context.dart';
|
2016-02-07 03:19:50 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2015-11-10 21:18:34 +00:00
|
|
|
import 'package:flutter_tools/src/commands/daemon.dart';
|
2016-02-24 18:06:59 +00:00
|
|
|
import 'package:flutter_tools/src/device.dart';
|
2016-02-21 06:00:11 +00:00
|
|
|
import 'package:flutter_tools/src/doctor.dart';
|
2016-02-17 08:59:56 +00:00
|
|
|
import 'package:flutter_tools/src/globals.dart';
|
2016-02-21 06:00:11 +00:00
|
|
|
import 'package:flutter_tools/src/ios/mac.dart';
|
2015-11-02 21:05:05 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2016-02-24 18:06:59 +00:00
|
|
|
import 'src/context.dart';
|
2015-11-02 21:05:05 +00:00
|
|
|
import 'src/mocks.dart';
|
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2016-02-13 20:00:41 +00:00
|
|
|
Daemon daemon;
|
|
|
|
AppContext appContext;
|
|
|
|
NotifyingLogger notifyingLogger;
|
|
|
|
|
|
|
|
void _testUsingContext(String description, dynamic testMethod()) {
|
|
|
|
test(description, () {
|
|
|
|
return appContext.runInZone(testMethod);
|
|
|
|
});
|
|
|
|
}
|
2016-01-28 06:38:57 +00:00
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
group('daemon', () {
|
2016-01-28 06:38:57 +00:00
|
|
|
setUp(() {
|
2016-02-07 03:19:50 +00:00
|
|
|
appContext = new AppContext();
|
|
|
|
notifyingLogger = new NotifyingLogger();
|
2016-11-29 19:22:48 +00:00
|
|
|
appContext.setVariable(Logger, notifyingLogger);
|
|
|
|
appContext.setVariable(Doctor, new Doctor());
|
2016-02-21 06:00:11 +00:00
|
|
|
if (Platform.isMacOS)
|
2016-11-29 19:22:48 +00:00
|
|
|
appContext.setVariable(XCode, new XCode());
|
|
|
|
appContext.setVariable(DeviceManager, new MockDeviceManager());
|
2016-01-28 06:38:57 +00:00
|
|
|
});
|
2015-11-02 21:05:05 +00:00
|
|
|
|
|
|
|
tearDown(() {
|
|
|
|
if (daemon != null)
|
|
|
|
return daemon.shutdown();
|
2016-09-13 18:15:36 +00:00
|
|
|
notifyingLogger.dispose();
|
2015-11-02 21:05:05 +00:00
|
|
|
});
|
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
_testUsingContext('daemon.version', () async {
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
2015-11-02 21:05:05 +00:00
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
2016-01-28 06:38:57 +00:00
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
2016-02-07 03:19:50 +00:00
|
|
|
notifyingLogger: notifyingLogger
|
2015-11-02 21:05:05 +00:00
|
|
|
);
|
2016-03-12 08:32:34 +00:00
|
|
|
commands.add(<String, dynamic>{'id': 0, 'method': 'daemon.version'});
|
|
|
|
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
|
2015-11-02 21:05:05 +00:00
|
|
|
expect(response['id'], 0);
|
|
|
|
expect(response['result'], isNotEmpty);
|
|
|
|
expect(response['result'] is String, true);
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2015-11-02 21:05:05 +00:00
|
|
|
});
|
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
_testUsingContext('daemon.logMessage', () {
|
2016-02-07 03:19:50 +00:00
|
|
|
return appContext.runInZone(() async {
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
2016-01-28 06:38:57 +00:00
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
2016-02-07 03:19:50 +00:00
|
|
|
notifyingLogger: notifyingLogger
|
2016-01-28 06:38:57 +00:00
|
|
|
);
|
|
|
|
printError('daemon.logMessage test');
|
|
|
|
Map<String, dynamic> response = await responses.stream.where((Map<String, dynamic> map) {
|
|
|
|
return map['event'] == 'daemon.logMessage' && map['params']['level'] == 'error';
|
|
|
|
}).first;
|
|
|
|
expect(response['id'], isNull);
|
|
|
|
expect(response['event'], 'daemon.logMessage');
|
|
|
|
Map<String, String> logMessage = response['params'];
|
|
|
|
expect(logMessage['level'], 'error');
|
|
|
|
expect(logMessage['message'], 'daemon.logMessage test');
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2016-02-07 03:19:50 +00:00
|
|
|
});
|
2016-01-25 21:15:01 +00:00
|
|
|
});
|
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
_testUsingContext('daemon.shutdown', () async {
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
2015-11-02 21:05:05 +00:00
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
2016-01-28 06:38:57 +00:00
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
2016-02-07 03:19:50 +00:00
|
|
|
notifyingLogger: notifyingLogger
|
2015-11-02 21:05:05 +00:00
|
|
|
);
|
2016-05-03 16:09:00 +00:00
|
|
|
commands.add(<String, dynamic>{'id': 0, 'method': 'daemon.shutdown'});
|
2015-11-02 21:05:05 +00:00
|
|
|
return daemon.onExit.then((int code) {
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2015-11-02 21:05:05 +00:00
|
|
|
expect(code, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-07 19:13:35 +00:00
|
|
|
_testUsingContext('daemon.start', () async {
|
|
|
|
DaemonCommand command = new DaemonCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
|
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
|
|
|
daemonCommand: command,
|
|
|
|
notifyingLogger: notifyingLogger
|
|
|
|
);
|
|
|
|
|
|
|
|
commands.add(<String, dynamic>{ 'id': 0, 'method': 'app.start' });
|
|
|
|
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
|
|
|
|
expect(response['id'], 0);
|
|
|
|
expect(response['error'], contains('deviceId is required'));
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2016-06-07 19:13:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
_testUsingContext('daemon.restart', () async {
|
|
|
|
DaemonCommand command = new DaemonCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
|
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
|
|
|
daemonCommand: command,
|
|
|
|
notifyingLogger: notifyingLogger
|
|
|
|
);
|
|
|
|
|
|
|
|
commands.add(<String, dynamic>{ 'id': 0, 'method': 'app.restart' });
|
|
|
|
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
|
|
|
|
expect(response['id'], 0);
|
|
|
|
expect(response['error'], contains('appId is required'));
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2016-06-07 19:13:35 +00:00
|
|
|
});
|
|
|
|
|
2016-03-03 21:31:05 +00:00
|
|
|
_testUsingContext('daemon.stop', () async {
|
2015-11-02 21:05:05 +00:00
|
|
|
DaemonCommand command = new DaemonCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
2015-11-02 21:05:05 +00:00
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
2016-01-19 23:14:05 +00:00
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
2016-01-28 06:38:57 +00:00
|
|
|
daemonCommand: command,
|
2016-02-07 03:19:50 +00:00
|
|
|
notifyingLogger: notifyingLogger
|
2015-11-02 21:05:05 +00:00
|
|
|
);
|
|
|
|
|
2016-03-03 21:31:05 +00:00
|
|
|
commands.add(<String, dynamic>{ 'id': 0, 'method': 'app.stop' });
|
2016-03-12 08:32:34 +00:00
|
|
|
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
|
2015-11-02 21:05:05 +00:00
|
|
|
expect(response['id'], 0);
|
2016-06-07 19:13:35 +00:00
|
|
|
expect(response['error'], contains('appId is required'));
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2015-11-02 21:05:05 +00:00
|
|
|
});
|
2016-01-19 23:14:05 +00:00
|
|
|
|
2016-02-13 20:00:41 +00:00
|
|
|
_testUsingContext('device.getDevices', () async {
|
2016-03-12 08:32:34 +00:00
|
|
|
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
|
|
|
|
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
|
2016-01-19 23:14:05 +00:00
|
|
|
daemon = new Daemon(
|
|
|
|
commands.stream,
|
2016-01-28 06:38:57 +00:00
|
|
|
(Map<String, dynamic> result) => responses.add(result),
|
2016-02-07 03:19:50 +00:00
|
|
|
notifyingLogger: notifyingLogger
|
2016-01-19 23:14:05 +00:00
|
|
|
);
|
2016-05-03 16:09:00 +00:00
|
|
|
commands.add(<String, dynamic>{'id': 0, 'method': 'device.getDevices'});
|
2016-03-12 08:32:34 +00:00
|
|
|
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
|
2016-01-19 23:14:05 +00:00
|
|
|
expect(response['id'], 0);
|
|
|
|
expect(response['result'], isList);
|
2016-09-13 18:15:36 +00:00
|
|
|
responses.close();
|
|
|
|
commands.close();
|
2016-01-19 23:14:05 +00:00
|
|
|
});
|
2015-11-02 21:05:05 +00:00
|
|
|
});
|
|
|
|
}
|
2016-01-25 21:15:01 +00:00
|
|
|
|
|
|
|
bool _notEvent(Map<String, dynamic> map) => map['event'] == null;
|