Search in sources :

Example 51 with ImmutableBundle

use of com.google.firebase.perf.util.ImmutableBundle in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method foregroundTrace_perfMonDeactivated_traceCreated.

@Test
public void foregroundTrace_perfMonDeactivated_traceCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // Firebase Performance is deactivated at build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    // activity1 comes to foreground.
    currentTime = 1;
    monitor.onActivityResumed(activity1);
    // activity1 goes to background.
    currentTime = 2;
    monitor.onActivityStopped(activity1);
    assertThat(monitor.isForeground()).isFalse();
    // Foreground trace is not created because Performance Monitoring is deactivated at build time.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // Developer enabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(true);
    // activity1 comes to foreground.
    currentTime = 3;
    monitor.onActivityResumed(activity1);
    // activity1 goes to background.
    currentTime = 4;
    monitor.onActivityStopped(activity1);
    assertThat(monitor.isForeground()).isFalse();
    // Foreground trace is not created because deactivation takes higher priority.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 52 with ImmutableBundle

use of com.google.firebase.perf.util.ImmutableBundle in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method screenTrace_perfMonEnabledSwitchAtRuntime_traceCreationDependsOnRuntime.

@Test
public void screenTrace_perfMonEnabledSwitchAtRuntime_traceCreationDependsOnRuntime() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Activity activityWithNonHardwareAcceleratedView = createFakeActivity(/* isHardwareAccelerated =*/
    true);
    // Developer disables Performance Monitoring during build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_enabled", false);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    // Case #1: developer has enabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(true);
    // Assert that screen trace has been created.
    currentTime = 100;
    monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).hasSize(1);
    currentTime = 200;
    monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
    // Case #2: developer has disabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(false);
    // Assert that screen trace has not been created.
    monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
    // Confirm that this doesn't throw an exception.
    monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Activity(android.app.Activity) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 53 with ImmutableBundle

use of com.google.firebase.perf.util.ImmutableBundle in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method backgroundTrace_perfMonDeactivated_traceCreated.

@Test
public void backgroundTrace_perfMonDeactivated_traceCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // Firebase Performance is deactivated at build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    // activity1 comes to background.
    currentTime = 1;
    monitor.onActivityResumed(activity1);
    monitor.onActivityStopped(activity1);
    // activity1 goes to foreground.
    currentTime = 2;
    monitor.onActivityResumed(activity1);
    assertThat(monitor.isForeground()).isTrue();
    // Background trace is not created because Performance Monitoring is deactivated at build time.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // Developer enabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(true);
    // activity1 comes to background.
    currentTime = 3;
    monitor.onActivityStopped(activity1);
    // activity1 goes to foreground.
    currentTime = 4;
    monitor.onActivityResumed(activity1);
    assertThat(monitor.isForeground()).isTrue();
    // Background trace is not created because deactivation takes higher priority.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 54 with ImmutableBundle

use of com.google.firebase.perf.util.ImmutableBundle in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method screenTrace_perfMonDisabledAtBuildTime_traceNotCreated.

@Test
public void screenTrace_perfMonDisabledAtBuildTime_traceNotCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Activity activityWithNonHardwareAcceleratedView = createFakeActivity(/* isHardwareAccelerated =*/
    true);
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_enabled", false);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
    // Confirm that this doesn't throw an exception.
    monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Activity(android.app.Activity) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 55 with ImmutableBundle

use of com.google.firebase.perf.util.ImmutableBundle in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method backgroundTrace_perfMonEnabledAtRuntime_traceCreated.

@Test
public void backgroundTrace_perfMonEnabledAtRuntime_traceCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // Firebase Performance is disabled at build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_enabled", false);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    // activity1 comes to background.
    currentTime = 1;
    monitor.onActivityResumed(activity1);
    monitor.onActivityStopped(activity1);
    // activity1 goes to foreground.
    currentTime = 2;
    monitor.onActivityResumed(activity1);
    assertThat(monitor.isForeground()).isTrue();
    // Background trace is not created because Performance Monitoring is disabled at build time.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // Developer enabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(true);
    // activity1 comes to background.
    currentTime = 3;
    monitor.onActivityStopped(activity1);
    // Foreground trace is created because Performance Monitoring is enabled.
    verify(transportManager, times(1)).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // activity1 goes to foreground.
    currentTime = 4;
    monitor.onActivityResumed(activity1);
    assertThat(monitor.isForeground()).isTrue();
    // Background trace is created because Performance Monitoring is enabled.
    verify(transportManager, times(2)).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Aggregations

Bundle (android.os.Bundle)63 ImmutableBundle (com.google.firebase.perf.util.ImmutableBundle)63 Test (org.junit.Test)60 TraceMetric (com.google.firebase.perf.v1.TraceMetric)5 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)4 Activity (android.app.Activity)3 ApplicationInfo (android.content.pm.ApplicationInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)1 FakeDirectExecutorService (com.google.testing.timing.FakeDirectExecutorService)1