@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/base/user_messages.dart';
18
18
import 'package:flutter_tools/src/cache.dart' ;
19
19
import 'package:flutter_tools/src/globals.dart' as globals;
20
20
import 'package:flutter_tools/src/reporting/crash_reporting.dart' ;
21
- import 'package:flutter_tools/src/reporting/reporting.dart' ;
22
21
import 'package:flutter_tools/src/runner/flutter_command.dart' ;
23
22
import 'package:test/fake.dart' ;
24
23
import 'package:unified_analytics/unified_analytics.dart' ;
@@ -99,8 +98,6 @@ void main() {
99
98
// exception on the first attempt, the second attempt tries to report the
100
99
// *original* crash, and not the crash from the first crash report
101
100
// attempt.
102
- final CrashingUsage crashingUsage = globals.flutterUsage as CrashingUsage ;
103
- expect (crashingUsage.sentException.toString (), 'Exception: an exception % --' );
104
101
expect (fakeAnalytics.sentEvents, contains (Event .exception (exception: '_Exception' )));
105
102
}, overrides: < Type , Generator > {
106
103
Platform : () => FakePlatform (environment: < String , String > {
@@ -109,7 +106,6 @@ void main() {
109
106
}),
110
107
FileSystem : () => fileSystem,
111
108
ProcessManager : () => FakeProcessManager .any (),
112
- Usage : () => CrashingUsage (),
113
109
Artifacts : () => Artifacts .test (),
114
110
HttpClientFactory : () => () => FakeHttpClient .any (),
115
111
Analytics : () => fakeAnalytics,
@@ -411,21 +407,23 @@ void main() {
411
407
shutdownHooks: ShutdownHooks (),
412
408
);
413
409
414
- expect ((globals.flutterUsage as TestUsage ).printedWelcome, false );
410
+ expect (
411
+ (globals.logger as BufferLogger ).traceText,
412
+ isNot (contains ('Showed analytics consent message.' )),
413
+ );
415
414
},
416
415
overrides: < Type , Generator > {
416
+ Logger : () => BufferLogger .test (),
417
417
FileSystem : () => MemoryFileSystem .test (),
418
418
ProcessManager : () => FakeProcessManager .any (),
419
419
BotDetector : () => const FakeBotDetector (true ),
420
- Usage : () => TestUsage (),
421
420
},
422
421
);
423
422
});
424
423
425
424
group ('unified_analytics' , () {
426
425
late FakeAnalytics fakeAnalytics;
427
426
late MemoryFileSystem fs;
428
- late TestUsage testUsage;
429
427
430
428
setUp (() {
431
429
fs = MemoryFileSystem .test ();
@@ -434,7 +432,6 @@ void main() {
434
432
fs: fs,
435
433
fakeFlutterVersion: FakeFlutterVersion (),
436
434
);
437
- testUsage = TestUsage ();
438
435
});
439
436
440
437
testUsingContext (
@@ -461,85 +458,6 @@ void main() {
461
458
},
462
459
);
463
460
464
- testUsingContext (
465
- 'runner sends mismatch event to ga3 if user opted in to ga3 but out of ga4 analytics' ,
466
- () async {
467
- io.setExitFunctionForTests ((int exitCode) {});
468
-
469
- // Begin by opting out of telemetry for package:unified_analytics
470
- // and leaving legacy analytics opted in
471
- await fakeAnalytics.setTelemetry (false );
472
- expect (fakeAnalytics.telemetryEnabled, false );
473
- expect (testUsage.enabled, true );
474
-
475
- await runner.run (
476
- < String > [],
477
- () => < FlutterCommand > [],
478
- // This flutterVersion disables crash reporting.
479
- flutterVersion: '[user-branch]/' ,
480
- shutdownHooks: ShutdownHooks (),
481
- );
482
-
483
- expect (
484
- testUsage.events,
485
- contains (const TestUsageEvent (
486
- 'ga4_and_ga3_status_mismatch' ,
487
- 'opted_out_of_ga4' ,
488
- )),
489
- );
490
- expect (fakeAnalytics.telemetryEnabled, false );
491
- expect (testUsage.enabled, true );
492
- expect (fakeAnalytics.sentEvents, isEmpty);
493
-
494
- },
495
- overrides: < Type , Generator > {
496
- Analytics : () => fakeAnalytics,
497
- FileSystem : () => MemoryFileSystem .test (),
498
- ProcessManager : () => FakeProcessManager .any (),
499
- Usage : () => testUsage,
500
- },
501
- );
502
-
503
- testUsingContext (
504
- 'runner does not send mismatch event to ga3 if user opted out of ga3 & ga4 analytics' ,
505
- () async {
506
- io.setExitFunctionForTests ((int exitCode) {});
507
-
508
- // Begin by opting out of telemetry for package:unified_analytics
509
- // and legacy analytics
510
- await fakeAnalytics.setTelemetry (false );
511
- testUsage.enabled = false ;
512
- expect (fakeAnalytics.telemetryEnabled, false );
513
- expect (testUsage.enabled, false );
514
-
515
- await runner.run (
516
- < String > [],
517
- () => < FlutterCommand > [],
518
- // This flutterVersion disables crash reporting.
519
- flutterVersion: '[user-branch]/' ,
520
- shutdownHooks: ShutdownHooks (),
521
- );
522
-
523
- expect (
524
- testUsage.events,
525
- isNot (contains (const TestUsageEvent (
526
- 'ga4_and_ga3_status_mismatch' ,
527
- 'opted_out_of_ga4' ,
528
- ))),
529
- );
530
- expect (fakeAnalytics.telemetryEnabled, false );
531
- expect (testUsage.enabled, false );
532
- expect (fakeAnalytics.sentEvents, isEmpty);
533
-
534
- },
535
- overrides: < Type , Generator > {
536
- Analytics : () => fakeAnalytics,
537
- FileSystem : () => MemoryFileSystem .test (),
538
- ProcessManager : () => FakeProcessManager .any (),
539
- Usage : () => testUsage,
540
- },
541
- );
542
-
543
461
testUsingContext (
544
462
'--enable-analytics and --disable-analytics enables/disables telemetry' ,
545
463
() async {
@@ -721,85 +639,6 @@ class _GitNotFoundFlutterCommand extends FlutterCommand {
721
639
}
722
640
}
723
641
724
- class CrashingUsage implements Usage {
725
- CrashingUsage () : _impl = Usage (
726
- versionOverride: '[user-branch]' ,
727
- runningOnBot: true ,
728
- );
729
-
730
- final Usage _impl;
731
-
732
- dynamic get sentException => _sentException;
733
- dynamic _sentException;
734
-
735
- bool _firstAttempt = true ;
736
-
737
- // Crash while crashing.
738
- @override
739
- void sendException (dynamic exception) {
740
- if (_firstAttempt) {
741
- _firstAttempt = false ;
742
- throw Exception ('CrashingUsage.sendException' );
743
- }
744
- _sentException = exception;
745
- }
746
-
747
- @override
748
- bool get suppressAnalytics => _impl.suppressAnalytics;
749
-
750
- @override
751
- set suppressAnalytics (bool value) {
752
- _impl.suppressAnalytics = value;
753
- }
754
-
755
- @override
756
- bool get enabled => _impl.enabled;
757
-
758
- @override
759
- set enabled (bool value) {
760
- _impl.enabled = value;
761
- }
762
-
763
- @override
764
- String get clientId => _impl.clientId;
765
-
766
- @override
767
- void sendCommand (String command, {CustomDimensions ? parameters}) =>
768
- _impl.sendCommand (command, parameters: parameters);
769
-
770
- @override
771
- void sendEvent (
772
- String category,
773
- String parameter, {
774
- String ? label,
775
- int ? value,
776
- CustomDimensions ? parameters,
777
- }) => _impl.sendEvent (
778
- category,
779
- parameter,
780
- label: label,
781
- value: value,
782
- parameters: parameters,
783
- );
784
-
785
- @override
786
- void sendTiming (
787
- String category,
788
- String variableName,
789
- Duration duration, {
790
- String ? label,
791
- }) => _impl.sendTiming (category, variableName, duration, label: label);
792
-
793
- @override
794
- Stream <Map <String , dynamic >> get onSend => _impl.onSend;
795
-
796
- @override
797
- Future <void > ensureAnalyticsSent () => _impl.ensureAnalyticsSent ();
798
-
799
- @override
800
- void printWelcome () => _impl.printWelcome ();
801
- }
802
-
803
642
class CustomBugInstructions extends UserMessages {
804
643
@override
805
644
String get flutterToolBugInstructions => kCustomBugInstructions;
0 commit comments