25
25
import android .os .Bundle ;
26
26
import androidx .test .core .app .ApplicationProvider ;
27
27
import com .google .android .datatransport .TransportFactory ;
28
+ import com .google .firebase .messaging .testing .AnalyticsValidator ;
29
+ import com .google .firebase .messaging .testing .AnalyticsValidator .LoggedEvent ;
28
30
import com .google .firebase .FirebaseApp ;
29
31
import com .google .firebase .FirebaseOptions ;
30
32
import com .google .firebase .analytics .connector .AnalyticsConnector ;
33
+ import com .google .firebase .messaging .testing .FakeConnectorComponent ;
31
34
import com .google .firebase .components .ComponentDiscoveryService ;
32
35
import com .google .firebase .messaging .AnalyticsTestHelper .Analytics ;
33
36
import com .google .firebase .messaging .Constants .AnalyticsKeys ;
34
37
import com .google .firebase .messaging .Constants .FirelogAnalytics ;
35
38
import com .google .firebase .messaging .Constants .MessageNotificationKeys ;
36
39
import com .google .firebase .messaging .Constants .MessagePayloadKeys ;
37
40
import com .google .firebase .messaging .Constants .ScionAnalytics ;
38
- import com .google .firebase .messaging .testing .AnalyticsValidator ;
39
- import com .google .firebase .messaging .testing .AnalyticsValidator .LoggedEvent ;
40
- import com .google .firebase .messaging .testing .FakeConnectorComponent ;
41
41
import com .google .firebase .messaging .testing .MessagingTestHelper ;
42
42
import java .util .List ;
43
43
import org .junit .Before ;
44
44
import org .junit .Test ;
45
45
import org .junit .runner .RunWith ;
46
46
import org .robolectric .RobolectricTestRunner ;
47
47
48
+
48
49
/** Messaging Analytics tests */
49
50
@ RunWith (RobolectricTestRunner .class )
50
51
public class MessagingAnalyticsRoboTest {
@@ -117,7 +118,7 @@ public void testNoCrashIfAnalyticsIsMissingAtRuntime() throws Exception {
117
118
Intent intent = new Intent ();
118
119
intent .putExtra (ANALYTICS_COMPOSER_ID , "composer_key" );
119
120
120
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
121
+ MessagingAnalytics .logNotificationReceived (intent );
121
122
MessagingAnalytics .logNotificationOpen (intent );
122
123
MessagingAnalytics .logNotificationDismiss (intent );
123
124
// No Exception is thrown = no crash, yeah
@@ -373,8 +374,9 @@ private Bundle editManifestApplicationMetadata() throws Exception {
373
374
public void testComposerUiPopulatesParamMessageId () {
374
375
Intent intent = new Intent ();
375
376
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
377
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
376
378
377
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
379
+ MessagingAnalytics .logNotificationReceived (intent );
378
380
379
381
List <LoggedEvent > events = analyticsValidator .getLoggedEvents ();
380
382
assertThat (events ).hasSize (1 );
@@ -393,8 +395,9 @@ public void testComposerUiPopulatesParamMessageId() {
393
395
public void testTopicsApiPopulatesParamTopic_straightFromHttpTopicApi () {
394
396
Intent intent = new Intent ();
395
397
intent .putExtra (MessagePayloadKeys .FROM , "/topics/test_topic" );
398
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
396
399
397
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
400
+ MessagingAnalytics .logNotificationReceived (intent );
398
401
399
402
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
400
403
assertThat (events ).hasSize (1 );
@@ -417,8 +420,9 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiUsingTopic() {
417
420
Intent intent = new Intent ();
418
421
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
419
422
intent .putExtra (MessagePayloadKeys .FROM , "/topics/test_topic" );
423
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
420
424
421
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
425
+ MessagingAnalytics .logNotificationReceived (intent );
422
426
423
427
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
424
428
assertThat (events ).hasSize (1 );
@@ -436,10 +440,12 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiUsingTopic() {
436
440
@ Test
437
441
public void testTopicsApiPopulatesParamTopic_fromComposerUiWithFromNotATopic () {
438
442
Intent intent = new Intent ();
443
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
444
+
439
445
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
440
446
intent .putExtra (MessagePayloadKeys .FROM , "not_a_topic_name" );
441
447
442
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
448
+ MessagingAnalytics .logNotificationReceived (intent );
443
449
444
450
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
445
451
assertThat (events ).hasSize (1 );
@@ -455,11 +461,13 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiWithFromNotATopic() {
455
461
@ Test
456
462
public void analyticsMessageTimestamp () {
457
463
Intent intent = new Intent ();
464
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
465
+
458
466
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
459
467
intent .putExtra (ANALYTICS_MESSAGE_TIMESTAMP , "1234" );
460
468
461
469
// Notification with a valid timestamp
462
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
470
+ MessagingAnalytics .logNotificationReceived (intent );
463
471
464
472
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
465
473
assertThat (events ).hasSize (1 );
@@ -473,11 +481,13 @@ public void analyticsMessageTimestamp() {
473
481
@ Test
474
482
public void analyticsMessageTimestamp_invalid () {
475
483
Intent intent = new Intent ();
484
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
485
+
476
486
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
477
487
// Notification with a corrupted timestamp
478
488
intent .putExtra (ANALYTICS_MESSAGE_TIMESTAMP , "1234_garbage" );
479
489
480
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
490
+ MessagingAnalytics .logNotificationReceived (intent );
481
491
482
492
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
483
493
assertThat (events ).hasSize (1 );
@@ -491,9 +501,11 @@ public void analyticsMessageTimestamp_invalid() {
491
501
public void analyticsComposerLabel_missing () {
492
502
Intent intent = new Intent ();
493
503
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
504
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
505
+
494
506
// ANALYTICS_COMPOSER_LABEL not set
495
507
496
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
508
+ MessagingAnalytics .logNotificationReceived (intent );
497
509
498
510
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
499
511
assertThat (events ).hasSize (1 );
@@ -508,8 +520,9 @@ public void analyticsComposerLabel() {
508
520
Intent intent = new Intent ();
509
521
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
510
522
intent .putExtra (ANALYTICS_COMPOSER_LABEL , "human composer label" );
523
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
511
524
512
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
525
+ MessagingAnalytics .logNotificationReceived (intent );
513
526
514
527
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
515
528
assertThat (events ).hasSize (1 );
@@ -523,7 +536,9 @@ public void analyticsComposerLabel() {
523
536
@ Test
524
537
public void analyticsMessageLabel_missing () {
525
538
Intent intent = new Intent ();
526
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
539
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
540
+
541
+ MessagingAnalytics .logNotificationReceived (intent );
527
542
528
543
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
529
544
assertThat (events ).hasSize (1 );
@@ -537,7 +552,9 @@ public void analyticsMessageLabel_missing() {
537
552
public void analyticsMessageLabel_present () {
538
553
Intent intent = new Intent ();
539
554
intent .putExtra (ANALYTICS_MESSAGE_LABEL , "developer-provided-label" );
540
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
555
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
556
+
557
+ MessagingAnalytics .logNotificationReceived (intent );
541
558
542
559
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
543
560
assertThat (events ).hasSize (1 );
@@ -551,8 +568,9 @@ public void analyticsMessageLabel_present() {
551
568
@ Test
552
569
public void notificationLifecycle_eventReceived_dataMessage () {
553
570
Intent intent = new Intent ();
571
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
554
572
555
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
573
+ MessagingAnalytics .logNotificationReceived (intent );
556
574
557
575
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
558
576
assertThat (events ).hasSize (1 );
@@ -565,11 +583,13 @@ public void notificationLifecycle_eventReceived_dataMessage() {
565
583
@ Test
566
584
public void notificationLifecycle_eventReceived_notification () {
567
585
Intent intent = new Intent ();
586
+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
587
+
568
588
intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
569
589
// Set as notification.
570
590
intent .putExtra ("gcm.n.e" , "1" );
571
591
572
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
592
+ MessagingAnalytics .logNotificationReceived (intent );
573
593
574
594
List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
575
595
assertThat (events ).hasSize (1 );
@@ -645,7 +665,7 @@ public void trackConversions_enabled_eventReceived() {
645
665
intent .putExtra (ANALYTICS_TRACK_CONVERSIONS , "1" );
646
666
647
667
// Notification received: NO user-property and NO Event.FIREBASE_CAMPAIGN is logged
648
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
668
+ MessagingAnalytics .logNotificationReceived (intent );
649
669
650
670
assertThat (analyticsValidator .getLoggedEventNames ())
651
671
.doesNotContain (ScionAnalytics .EVENT_FIREBASE_CAMPAIGN );
@@ -726,7 +746,7 @@ public void trackConversions_disabled_eventReceived() {
726
746
// Extra: ANALYTICS_TRACK_CONVERSIONS="1" NOT set
727
747
728
748
// Notification received: NO user-property and NO Event.FIREBASE_CAMPAIGN is logged
729
- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
749
+ MessagingAnalytics .logNotificationReceived (intent );
730
750
731
751
assertThat (analyticsValidator .getLoggedEventNames ())
732
752
.doesNotContain (ScionAnalytics .EVENT_FIREBASE_CAMPAIGN );
@@ -844,4 +864,4 @@ public void testGetMessageTypeForFirelog_dataMessage() {
844
864
assertThat (MessagingAnalytics .getMessageTypeForFirelog (intent ))
845
865
.isEqualTo (FirelogAnalytics .MessageType .DISPLAY_NOTIFICATION );
846
866
}
847
- }
867
+ }
0 commit comments