move CI tests into the main repo (#5758)
This commit is contained in:
190
dev/devicelab/test/adb_test.dart
Normal file
190
dev/devicelab/test/adb_test.dart
Normal file
@@ -0,0 +1,190 @@
|
||||
// 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:collection/collection.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
|
||||
void main() {
|
||||
group('adb', () {
|
||||
Adb device;
|
||||
|
||||
setUp(() {
|
||||
FakeAdb.resetLog();
|
||||
adb = null;
|
||||
device = new FakeAdb();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
adb = realAdbGetter;
|
||||
});
|
||||
|
||||
group('isAwake/isAsleep', () {
|
||||
test('reads Awake', () async {
|
||||
FakeAdb.pretendAwake();
|
||||
expect(await device.isAwake(), isTrue);
|
||||
expect(await device.isAsleep(), isFalse);
|
||||
});
|
||||
|
||||
test('reads Asleep', () async {
|
||||
FakeAdb.pretendAsleep();
|
||||
expect(await device.isAwake(), isFalse);
|
||||
expect(await device.isAsleep(), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('togglePower', () {
|
||||
test('sends power event', () async {
|
||||
await device.togglePower();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'input', arguments: <String>['keyevent', '26']),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
group('wakeUp', () {
|
||||
test('when awake', () async {
|
||||
FakeAdb.pretendAwake();
|
||||
await device.wakeUp();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'dumpsys', arguments: <String>['power']),
|
||||
]);
|
||||
});
|
||||
|
||||
test('when asleep', () async {
|
||||
FakeAdb.pretendAsleep();
|
||||
await device.wakeUp();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'dumpsys', arguments: <String>['power']),
|
||||
cmd(command: 'input', arguments: <String>['keyevent', '26']),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
group('sendToSleep', () {
|
||||
test('when asleep', () async {
|
||||
FakeAdb.pretendAsleep();
|
||||
await device.sendToSleep();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'dumpsys', arguments: <String>['power']),
|
||||
]);
|
||||
});
|
||||
|
||||
test('when awake', () async {
|
||||
FakeAdb.pretendAwake();
|
||||
await device.sendToSleep();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'dumpsys', arguments: <String>['power']),
|
||||
cmd(command: 'input', arguments: <String>['keyevent', '26']),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
group('unlock', () {
|
||||
test('sends unlock event', () async {
|
||||
FakeAdb.pretendAwake();
|
||||
await device.unlock();
|
||||
expectLog(<CommandArgs>[
|
||||
cmd(command: 'dumpsys', arguments: <String>['power']),
|
||||
cmd(command: 'input', arguments: <String>['keyevent', '82']),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void expectLog(List<CommandArgs> log) {
|
||||
expect(FakeAdb.commandLog, log);
|
||||
}
|
||||
|
||||
CommandArgs cmd({ String command, List<String> arguments, Map<String, String> env }) => new CommandArgs(
|
||||
command: command,
|
||||
arguments: arguments,
|
||||
env: env
|
||||
);
|
||||
|
||||
typedef dynamic ExitErrorFactory();
|
||||
|
||||
class CommandArgs {
|
||||
CommandArgs({ this.command, this.arguments, this.env });
|
||||
|
||||
final String command;
|
||||
final List<String> arguments;
|
||||
final Map<String, String> env;
|
||||
|
||||
@override
|
||||
String toString() => 'CommandArgs(command: $command, arguments: $arguments, env: $env)';
|
||||
|
||||
@override
|
||||
bool operator==(Object other) {
|
||||
if (other.runtimeType != CommandArgs)
|
||||
return false;
|
||||
|
||||
CommandArgs otherCmd = other;
|
||||
return otherCmd.command == this.command &&
|
||||
const ListEquality<String>().equals(otherCmd.arguments, this.arguments) &&
|
||||
const MapEquality<String, String>().equals(otherCmd.env, this.env);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => 17 * (17 * command.hashCode + _hashArguments) + _hashEnv;
|
||||
|
||||
int get _hashArguments => arguments != null
|
||||
? const ListEquality<String>().hash(arguments)
|
||||
: null.hashCode;
|
||||
|
||||
int get _hashEnv => env != null
|
||||
? const MapEquality<String, String>().hash(env)
|
||||
: null.hashCode;
|
||||
}
|
||||
|
||||
class FakeAdb extends Adb {
|
||||
FakeAdb({ String deviceId: null }) : super(deviceId: deviceId);
|
||||
|
||||
static String output = '';
|
||||
static ExitErrorFactory exitErrorFactory = () => null;
|
||||
|
||||
static List<CommandArgs> commandLog = <CommandArgs>[];
|
||||
|
||||
static void resetLog() {
|
||||
commandLog.clear();
|
||||
}
|
||||
|
||||
static void pretendAwake() {
|
||||
output = '''
|
||||
mWakefulness=Awake
|
||||
''';
|
||||
}
|
||||
|
||||
static void pretendAsleep() {
|
||||
output = '''
|
||||
mWakefulness=Asleep
|
||||
''';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> shellEval(String command, List<String> arguments, {Map<String, String> env}) async {
|
||||
commandLog.add(new CommandArgs(
|
||||
command: command,
|
||||
arguments: arguments,
|
||||
env: env
|
||||
));
|
||||
return output;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> shellExec(String command, List<String> arguments, {Map<String, String> env}) async {
|
||||
commandLog.add(new CommandArgs(
|
||||
command: command,
|
||||
arguments: arguments,
|
||||
env: env
|
||||
));
|
||||
dynamic exitError = exitErrorFactory();
|
||||
if (exitError != null)
|
||||
throw exitError;
|
||||
}
|
||||
}
|
||||
13
dev/devicelab/test/all.dart
Normal file
13
dev/devicelab/test/all.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// 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 'adb_test.dart' as adb_test;
|
||||
import 'manifest_test.dart' as manifest_test;
|
||||
import 'run_test.dart' as run_test;
|
||||
|
||||
void main() {
|
||||
adb_test.main();
|
||||
manifest_test.main();
|
||||
run_test.main();
|
||||
}
|
||||
143
dev/devicelab/test/manifest_test.dart
Normal file
143
dev/devicelab/test/manifest_test.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
// 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 'package:test/test.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/manifest.dart';
|
||||
|
||||
void main() {
|
||||
group('production manifest', () {
|
||||
test('must be valid', () {
|
||||
Manifest manifest = loadTaskManifest();
|
||||
expect(manifest.tasks, isNotEmpty);
|
||||
|
||||
ManifestTask task = manifest.tasks.firstWhere((ManifestTask task) => task.name == 'flutter_gallery__start_up');
|
||||
expect(task.description, 'Measures the startup time of the Flutter Gallery app on Android.\n');
|
||||
expect(task.stage, 'devicelab');
|
||||
expect(task.requiredAgentCapabilities, <String>['has-android-device']);
|
||||
});
|
||||
});
|
||||
|
||||
group('manifest parser', () {
|
||||
void testManifestError(
|
||||
String testDescription,
|
||||
String errorMessage,
|
||||
String yaml,
|
||||
) {
|
||||
test(testDescription, () {
|
||||
try {
|
||||
loadTaskManifest(yaml);
|
||||
} on ManifestError catch(error) {
|
||||
expect(error.message, errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
testManifestError(
|
||||
'invalid top-level type',
|
||||
'Manifest must be a dictionary but was YamlScalar: null',
|
||||
'',
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid top-level key',
|
||||
'Unrecognized property "bad" in manifest. Allowed properties: tasks',
|
||||
'''
|
||||
bad:
|
||||
key: yes
|
||||
''',
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid tasks list type',
|
||||
'Value of "tasks" must be a dictionary but was YamlList: [a, b]',
|
||||
'''
|
||||
tasks:
|
||||
- a
|
||||
- b
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid task name type',
|
||||
'Task name must be a string but was int: 1',
|
||||
'''
|
||||
tasks:
|
||||
1: 2
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid task type',
|
||||
'Value of task "foo" must be a dictionary but was int: 2',
|
||||
'''
|
||||
tasks:
|
||||
foo: 2
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid task property',
|
||||
'Unrecognized property "bar" in Value of task "foo". Allowed properties: description, stage, required_agent_capabilities',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
bar: 2
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid required_agent_capabilities type',
|
||||
'required_agent_capabilities must be a list but was int: 1',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
required_agent_capabilities: 1
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'invalid required_agent_capabilities element type',
|
||||
'required_agent_capabilities[0] must be a string but was int: 1',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
required_agent_capabilities: [1]
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'missing description',
|
||||
'Task description must not be empty in task "foo".',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
required_agent_capabilities: ["a"]
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'missing stage',
|
||||
'Task stage must not be empty in task "foo".',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
description: b
|
||||
required_agent_capabilities: ["a"]
|
||||
'''
|
||||
);
|
||||
|
||||
testManifestError(
|
||||
'missing stage',
|
||||
'requiredAgentCapabilities must not be empty in task "foo".',
|
||||
'''
|
||||
tasks:
|
||||
foo:
|
||||
description: b
|
||||
stage: c
|
||||
required_agent_capabilities: []
|
||||
'''
|
||||
);
|
||||
});
|
||||
}
|
||||
50
dev/devicelab/test/run_test.dart
Normal file
50
dev/devicelab/test/run_test.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('run.dart script', () {
|
||||
Future<int> runScript(List<String> testNames) async {
|
||||
List<String> options = <String>['bin/run.dart'];
|
||||
for (String testName in testNames) {
|
||||
options..addAll(<String>['-t', testName]);
|
||||
}
|
||||
Process scriptProcess = await Process.start(
|
||||
'../../bin/cache/dart-sdk/bin/dart',
|
||||
options,
|
||||
);
|
||||
return scriptProcess.exitCode;
|
||||
}
|
||||
|
||||
test('Exits with code 0 when succeeds', () async {
|
||||
expect(await runScript(<String>['smoke_test_success']), 0);
|
||||
});
|
||||
|
||||
test('Exits with code 1 when task throws', () async {
|
||||
expect(await runScript(<String>['smoke_test_throws']), 1);
|
||||
});
|
||||
|
||||
test('Exits with code 1 when fails', () async {
|
||||
expect(await runScript(<String>['smoke_test_failure']), 1);
|
||||
});
|
||||
|
||||
test('Exits with code 1 when fails to connect', () async {
|
||||
expect(await runScript(<String>['smoke_test_setup_failure']), 1);
|
||||
});
|
||||
|
||||
test('Exits with code 1 when results are mixed', () async {
|
||||
expect(
|
||||
await runScript(<String>[
|
||||
'smoke_test_failure',
|
||||
'smoke_test_success',
|
||||
]),
|
||||
1,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
18
dev/devicelab/test/utils_test.dart
Normal file
18
dev/devicelab/test/utils_test.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 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 'package:test/test.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
|
||||
void main() {
|
||||
group('grep', () {
|
||||
test('greps lines', () {
|
||||
expect(grep('b', from: 'ab\ncd\nba'), <String>['ab', 'ba']);
|
||||
});
|
||||
|
||||
test('understands RegExp', () {
|
||||
expect(grep(new RegExp('^b'), from: 'ab\nba'), <String>['ba']);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user