2525import android .os .Bundle ;
2626import androidx .test .core .app .ApplicationProvider ;
2727import com .google .android .datatransport .TransportFactory ;
28+ import com .google .firebase .messaging .testing .AnalyticsValidator ;
29+ import com .google .firebase .messaging .testing .AnalyticsValidator .LoggedEvent ;
2830import com .google .firebase .FirebaseApp ;
2931import com .google .firebase .FirebaseOptions ;
3032import com .google .firebase .analytics .connector .AnalyticsConnector ;
33+ import com .google .firebase .messaging .testing .FakeConnectorComponent ;
3134import com .google .firebase .components .ComponentDiscoveryService ;
3235import com .google .firebase .messaging .AnalyticsTestHelper .Analytics ;
3336import com .google .firebase .messaging .Constants .AnalyticsKeys ;
3437import com .google .firebase .messaging .Constants .FirelogAnalytics ;
3538import com .google .firebase .messaging .Constants .MessageNotificationKeys ;
3639import com .google .firebase .messaging .Constants .MessagePayloadKeys ;
3740import 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 ;
4141import com .google .firebase .messaging .testing .MessagingTestHelper ;
4242import java .util .List ;
4343import org .junit .Before ;
4444import org .junit .Test ;
4545import org .junit .runner .RunWith ;
4646import org .robolectric .RobolectricTestRunner ;
4747
48+
4849/** Messaging Analytics tests */
4950@ RunWith (RobolectricTestRunner .class )
5051public class MessagingAnalyticsRoboTest {
@@ -117,7 +118,7 @@ public void testNoCrashIfAnalyticsIsMissingAtRuntime() throws Exception {
117118 Intent intent = new Intent ();
118119 intent .putExtra (ANALYTICS_COMPOSER_ID , "composer_key" );
119120
120- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
121+ MessagingAnalytics .logNotificationReceived (intent );
121122 MessagingAnalytics .logNotificationOpen (intent );
122123 MessagingAnalytics .logNotificationDismiss (intent );
123124 // No Exception is thrown = no crash, yeah
@@ -373,8 +374,9 @@ private Bundle editManifestApplicationMetadata() throws Exception {
373374 public void testComposerUiPopulatesParamMessageId () {
374375 Intent intent = new Intent ();
375376 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
377+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
376378
377- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
379+ MessagingAnalytics .logNotificationReceived (intent );
378380
379381 List <LoggedEvent > events = analyticsValidator .getLoggedEvents ();
380382 assertThat (events ).hasSize (1 );
@@ -393,8 +395,9 @@ public void testComposerUiPopulatesParamMessageId() {
393395 public void testTopicsApiPopulatesParamTopic_straightFromHttpTopicApi () {
394396 Intent intent = new Intent ();
395397 intent .putExtra (MessagePayloadKeys .FROM , "/topics/test_topic" );
398+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
396399
397- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
400+ MessagingAnalytics .logNotificationReceived (intent );
398401
399402 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
400403 assertThat (events ).hasSize (1 );
@@ -417,8 +420,9 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiUsingTopic() {
417420 Intent intent = new Intent ();
418421 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
419422 intent .putExtra (MessagePayloadKeys .FROM , "/topics/test_topic" );
423+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
420424
421- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
425+ MessagingAnalytics .logNotificationReceived (intent );
422426
423427 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
424428 assertThat (events ).hasSize (1 );
@@ -436,10 +440,12 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiUsingTopic() {
436440 @ Test
437441 public void testTopicsApiPopulatesParamTopic_fromComposerUiWithFromNotATopic () {
438442 Intent intent = new Intent ();
443+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
444+
439445 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
440446 intent .putExtra (MessagePayloadKeys .FROM , "not_a_topic_name" );
441447
442- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
448+ MessagingAnalytics .logNotificationReceived (intent );
443449
444450 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
445451 assertThat (events ).hasSize (1 );
@@ -455,11 +461,13 @@ public void testTopicsApiPopulatesParamTopic_fromComposerUiWithFromNotATopic() {
455461 @ Test
456462 public void analyticsMessageTimestamp () {
457463 Intent intent = new Intent ();
464+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
465+
458466 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
459467 intent .putExtra (ANALYTICS_MESSAGE_TIMESTAMP , "1234" );
460468
461469 // Notification with a valid timestamp
462- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
470+ MessagingAnalytics .logNotificationReceived (intent );
463471
464472 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
465473 assertThat (events ).hasSize (1 );
@@ -473,11 +481,13 @@ public void analyticsMessageTimestamp() {
473481 @ Test
474482 public void analyticsMessageTimestamp_invalid () {
475483 Intent intent = new Intent ();
484+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
485+
476486 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
477487 // Notification with a corrupted timestamp
478488 intent .putExtra (ANALYTICS_MESSAGE_TIMESTAMP , "1234_garbage" );
479489
480- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
490+ MessagingAnalytics .logNotificationReceived (intent );
481491
482492 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
483493 assertThat (events ).hasSize (1 );
@@ -491,9 +501,11 @@ public void analyticsMessageTimestamp_invalid() {
491501 public void analyticsComposerLabel_missing () {
492502 Intent intent = new Intent ();
493503 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
504+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
505+
494506 // ANALYTICS_COMPOSER_LABEL not set
495507
496- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
508+ MessagingAnalytics .logNotificationReceived (intent );
497509
498510 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
499511 assertThat (events ).hasSize (1 );
@@ -508,8 +520,9 @@ public void analyticsComposerLabel() {
508520 Intent intent = new Intent ();
509521 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
510522 intent .putExtra (ANALYTICS_COMPOSER_LABEL , "human composer label" );
523+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
511524
512- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
525+ MessagingAnalytics .logNotificationReceived (intent );
513526
514527 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
515528 assertThat (events ).hasSize (1 );
@@ -523,7 +536,9 @@ public void analyticsComposerLabel() {
523536 @ Test
524537 public void analyticsMessageLabel_missing () {
525538 Intent intent = new Intent ();
526- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
539+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
540+
541+ MessagingAnalytics .logNotificationReceived (intent );
527542
528543 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
529544 assertThat (events ).hasSize (1 );
@@ -537,7 +552,9 @@ public void analyticsMessageLabel_missing() {
537552 public void analyticsMessageLabel_present () {
538553 Intent intent = new Intent ();
539554 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 );
541558
542559 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
543560 assertThat (events ).hasSize (1 );
@@ -551,8 +568,9 @@ public void analyticsMessageLabel_present() {
551568 @ Test
552569 public void notificationLifecycle_eventReceived_dataMessage () {
553570 Intent intent = new Intent ();
571+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
554572
555- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
573+ MessagingAnalytics .logNotificationReceived (intent );
556574
557575 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
558576 assertThat (events ).hasSize (1 );
@@ -565,11 +583,13 @@ public void notificationLifecycle_eventReceived_dataMessage() {
565583 @ Test
566584 public void notificationLifecycle_eventReceived_notification () {
567585 Intent intent = new Intent ();
586+ intent .putExtra (Constants .AnalyticsKeys .ENABLED , "1" );
587+
568588 intent .putExtra (ANALYTICS_COMPOSER_ID , "campaign_id" );
569589 // Set as notification.
570590 intent .putExtra ("gcm.n.e" , "1" );
571591
572- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
592+ MessagingAnalytics .logNotificationReceived (intent );
573593
574594 List <AnalyticsValidator .LoggedEvent > events = analyticsValidator .getLoggedEvents ();
575595 assertThat (events ).hasSize (1 );
@@ -645,7 +665,7 @@ public void trackConversions_enabled_eventReceived() {
645665 intent .putExtra (ANALYTICS_TRACK_CONVERSIONS , "1" );
646666
647667 // Notification received: NO user-property and NO Event.FIREBASE_CAMPAIGN is logged
648- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
668+ MessagingAnalytics .logNotificationReceived (intent );
649669
650670 assertThat (analyticsValidator .getLoggedEventNames ())
651671 .doesNotContain (ScionAnalytics .EVENT_FIREBASE_CAMPAIGN );
@@ -726,7 +746,7 @@ public void trackConversions_disabled_eventReceived() {
726746 // Extra: ANALYTICS_TRACK_CONVERSIONS="1" NOT set
727747
728748 // Notification received: NO user-property and NO Event.FIREBASE_CAMPAIGN is logged
729- MessagingAnalytics .logNotificationReceived (intent , /*transport= */ null );
749+ MessagingAnalytics .logNotificationReceived (intent );
730750
731751 assertThat (analyticsValidator .getLoggedEventNames ())
732752 .doesNotContain (ScionAnalytics .EVENT_FIREBASE_CAMPAIGN );
@@ -844,4 +864,4 @@ public void testGetMessageTypeForFirelog_dataMessage() {
844864 assertThat (MessagingAnalytics .getMessageTypeForFirelog (intent ))
845865 .isEqualTo (FirelogAnalytics .MessageType .DISPLAY_NOTIFICATION );
846866 }
847- }
867+ }
0 commit comments