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));
}
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);
}
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));
}
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);
}
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));
}
Aggregations