Commit 5e2d3e95 authored by Yegor's avatar Yegor Committed by GitHub

Clean up crash reporting code (#8602)

parent 24eeddc0
...@@ -37,19 +37,20 @@ String _kStackTraceFileField = 'DartError'; ...@@ -37,19 +37,20 @@ String _kStackTraceFileField = 'DartError';
/// it must be supplied in the request. /// it must be supplied in the request.
String _kStackTraceFilename = 'stacktrace_file'; String _kStackTraceFilename = 'stacktrace_file';
/// We only send crash reports in testing mode.
///
/// See [enterTestingMode] and [exitTestingMode].
bool _testing = false; bool _testing = false;
/// Sends crash reports to Google. /// Sends crash reports to Google.
class CrashReportSender { class CrashReportSender {
static final Uri _defaultBaseUri = new Uri( static final Uri _baseUri = new Uri(
scheme: 'https', scheme: 'https',
host: _kCrashServerHost, host: _kCrashServerHost,
port: 443, port: 443,
path: _kCrashEndpointPath, path: _kCrashEndpointPath,
); );
static Uri _baseUri = _defaultBaseUri;
static CrashReportSender _instance; static CrashReportSender _instance;
CrashReportSender._(this._client); CrashReportSender._(this._client);
...@@ -128,19 +129,15 @@ class CrashReportSender { ...@@ -128,19 +129,15 @@ class CrashReportSender {
} }
} }
/// Overrides [CrashReportSender._baseUri] for testing and enables testing /// Enables testing mode.
/// mode.
@visibleForTesting @visibleForTesting
void overrideBaseCrashUrlForTesting(Uri uri) { void enterTestingMode() {
CrashReportSender._baseUri = uri;
_testing = true; _testing = true;
} }
/// Resets [CrashReportSender._baseUri] back to the original value and disables /// Disables testing mode.
/// test mode.
@visibleForTesting @visibleForTesting
void resetBaseCrashUrlForTesting() { void exitTestingMode() {
CrashReportSender._baseUri = CrashReportSender._defaultBaseUri;
_testing = false; _testing = false;
} }
......
...@@ -15,26 +15,22 @@ import 'package:flutter_tools/executable.dart' as tools; ...@@ -15,26 +15,22 @@ import 'package:flutter_tools/executable.dart' as tools;
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart' as os;
import 'package:flutter_tools/src/crash_reporting.dart'; import 'package:flutter_tools/src/crash_reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'src/context.dart'; import 'src/context.dart';
void main() { void main() {
group('crash reporting', () { group('crash reporting', () {
int testPort;
setUp(() async { setUp(() async {
tools.crashFileSystem = new MemoryFileSystem(); tools.crashFileSystem = new MemoryFileSystem();
setExitFunctionForTests((_) { }); setExitFunctionForTests((_) { });
testPort = await os.findAvailablePort(); enterTestingMode();
overrideBaseCrashUrlForTesting(Uri.parse('http://localhost:$testPort/test-path'));
}); });
tearDown(() { tearDown(() {
tools.crashFileSystem = new LocalFileSystem(); tools.crashFileSystem = new LocalFileSystem();
restoreExitFunction(); restoreExitFunction();
resetBaseCrashUrlForTesting(); exitTestingMode();
}); });
testUsingContext('should send crash reports', () async { testUsingContext('should send crash reports', () async {
...@@ -62,10 +58,10 @@ void main() { ...@@ -62,10 +58,10 @@ void main() {
// Verify that we sent the crash report. // Verify that we sent the crash report.
expect(method, 'POST'); expect(method, 'POST');
expect(uri, new Uri( expect(uri, new Uri(
scheme: 'http', scheme: 'https',
host: 'localhost', host: 'clients2.google.com',
port: testPort, port: 443,
path: '/test-path', path: '/cr/staging_report',
queryParameters: <String, String>{ queryParameters: <String, String>{
'product': 'Flutter_Tools', 'product': 'Flutter_Tools',
'version' : 'test-version', 'version' : 'test-version',
......
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