Commit 8782d95c authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Check the type of a hot reload report message (#7249)

See https://github.com/flutter/flutter/issues/7248
parent 3bc6a1bf
......@@ -394,7 +394,11 @@ class HotRunner extends ResidentRunner {
}
/// Returns [true] if the reload was successful.
bool _validateReloadReport(Map<String, dynamic> reloadReport) {
static bool validateReloadReport(Map<String, dynamic> reloadReport) {
if (reloadReport['type'] != 'ReloadReport') {
printError('Hot reload received invalid response: $reloadReport');
return false;
}
if (!reloadReport['success']) {
printError('Hot reload was rejected:');
for (Map<String, dynamic> notice in reloadReport['details']['notices'])
......@@ -479,7 +483,7 @@ class HotRunner extends ResidentRunner {
pause: pause,
rootLibPath: deviceEntryPath,
packagesPath: devicePackagesPath);
if (!_validateReloadReport(reloadReport)) {
if (!validateReloadReport(reloadReport)) {
// Reload failed.
flutterUsage.sendEvent('hot', 'reload-reject');
return new OperationResult(1, 'reload rejected');
......
......@@ -29,6 +29,7 @@ import 'devices_test.dart' as devices_test;
import 'doctor_test.dart' as doctor_test;
import 'drive_test.dart' as drive_test;
import 'format_test.dart' as format_test;
import 'hot_test.dart' as hot_test;
import 'install_test.dart' as install_test;
import 'logs_test.dart' as logs_test;
import 'os_utils_test.dart' as os_utils_test;
......@@ -65,6 +66,7 @@ void main() {
doctor_test.main();
drive_test.main();
format_test.main();
hot_test.main();
install_test.main();
logs_test.main();
os_utils_test.main();
......
// 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:flutter_tools/src/hot.dart';
import 'package:test/test.dart';
import 'src/context.dart';
void main() {
group('validateReloadReport', () {
testUsingContext('invalid', () async {
expect(HotRunner.validateReloadReport(<String, dynamic>{}), false);
expect(HotRunner.validateReloadReport(
<String, dynamic>{'type': 'ReloadReport', 'success': true, 'details': <String, dynamic>{}}),
true);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment