Swap crash reporting with unified analytics (#148525)

Fixes: https://github.com/flutter/flutter/issues/147260

(this is a remake of https://github.com/flutter/flutter/pull/147296; in hindsight I could have force-pushed there instead but 🤷)
This commit is contained in:
Andrew Kolos
2024-05-17 18:30:13 -07:00
committed by GitHub
parent 4c35ab5879
commit ac6409b311
3 changed files with 27 additions and 23 deletions

View File

@@ -13,26 +13,30 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/crash_reporting.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:http/http.dart';
import 'package:http/testing.dart';
import 'package:test/fake.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../src/common.dart';
import '../src/fake_process_manager.dart';
import '../src/fakes.dart';
void main() {
late BufferLogger logger;
late FileSystem fs;
late TestUsage testUsage;
late MemoryFileSystem fs;
late Platform platform;
late OperatingSystemUtils operatingSystemUtils;
late StackTrace stackTrace;
late FakeAnalytics fakeAnalytics;
setUp(() async {
logger = BufferLogger.test();
fs = MemoryFileSystem.test();
testUsage = TestUsage();
fakeAnalytics = getInitializedFakeAnalyticsInstance(
fs: fs,
fakeFlutterVersion: FakeFlutterVersion(),
);
platform = FakePlatform(environment: <String, String>{});
operatingSystemUtils = OperatingSystemUtils(
@@ -63,7 +67,7 @@ void main() {
'version': 'test-version',
},
));
expect(crashInfo.fields?['uuid'], testUsage.clientId);
expect(crashInfo.fields?['uuid'], fakeAnalytics.clientId);
expect(crashInfo.fields?['product'], 'Flutter_Tools');
expect(crashInfo.fields?['version'], 'test-version');
expect(crashInfo.fields?['osName'], 'linux');
@@ -104,14 +108,14 @@ void main() {
});
testWithoutContext('suppress analytics', () async {
testUsage.suppressAnalytics = true;
fakeAnalytics.suppressTelemetry();
final CrashReportSender crashReportSender = CrashReportSender(
client: CrashingCrashReportSender(const SocketException('no internets')),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -126,7 +130,7 @@ void main() {
group('allow analytics', () {
setUp(() async {
testUsage.suppressAnalytics = false;
await fakeAnalytics.setTelemetry(true);
});
testWithoutContext('should send crash reports', () async {
@@ -134,10 +138,10 @@ void main() {
final CrashReportSender crashReportSender = CrashReportSender(
client: MockCrashReportSender(requestInfo),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -153,10 +157,10 @@ void main() {
testWithoutContext('should print an explanatory message when there is a SocketException', () async {
final CrashReportSender crashReportSender = CrashReportSender(
client: CrashingCrashReportSender(const SocketException('no internets')),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -172,10 +176,10 @@ void main() {
testWithoutContext('should print an explanatory message when there is an HttpException', () async {
final CrashReportSender crashReportSender = CrashReportSender(
client: CrashingCrashReportSender(const HttpException('no internets')),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -191,10 +195,10 @@ void main() {
testWithoutContext('should print an explanatory message when there is a ClientException', () async {
final CrashReportSender crashReportSender = CrashReportSender(
client: CrashingCrashReportSender(const HttpException('no internets')),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -212,10 +216,10 @@ void main() {
final CrashReportSender crashReportSender = CrashReportSender(
client: MockCrashReportSender(requestInfo),
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -266,10 +270,10 @@ void main() {
final CrashReportSender crashReportSender = CrashReportSender(
client: mockClient,
usage: testUsage,
platform: platform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(
@@ -303,10 +307,10 @@ void main() {
final CrashReportSender crashReportSender = CrashReportSender(
client: mockClient,
usage: testUsage,
platform: environmentPlatform,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
analytics: fakeAnalytics,
);
await crashReportSender.sendReport(