use of com.google.firebase.perf.v1.ApplicationProcessState.FOREGROUND_BACKGROUND 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.v1.ApplicationProcessState.FOREGROUND_BACKGROUND 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.v1.ApplicationProcessState.FOREGROUND_BACKGROUND in project firebase-android-sdk by firebase.
the class AppStateMonitorTest method testAppStateCallbackWithNetworkRequestMetricBuilder.
@Test
public void testAppStateCallbackWithNetworkRequestMetricBuilder() {
AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
// registerForAppState() is called by NetworkRequestMetricBuilder's constructor.
NetworkRequestMetricBuilder builder = new NetworkRequestMetricBuilder(mock(TransportManager.class), monitor, mock(GaugeManager.class));
Assert.assertEquals(ApplicationProcessState.BACKGROUND, builder.getAppState());
// activity1 comes to foreground.
currentTime = 1;
monitor.onActivityResumed(activity1);
Assert.assertTrue(monitor.isForeground());
// builder is updated through AppStateCallback.
Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
verify(transportManager, times(0)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
// activity1 goes to background.
currentTime = 2;
monitor.onActivityStopped(activity1);
Assert.assertFalse(monitor.isForeground());
// Foreground session trace.
verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
// builder is updated again.
Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
// unregisterForAppState() is called by NetworkRequestMetricBuilder.build().
builder.build();
Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
}
use of com.google.firebase.perf.v1.ApplicationProcessState.FOREGROUND_BACKGROUND 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));
}
use of com.google.firebase.perf.v1.ApplicationProcessState.FOREGROUND_BACKGROUND in project firebase-android-sdk by firebase.
the class AppStateMonitorTest method testAppStateCallbackWithTrace.
@Test
public void testAppStateCallbackWithTrace() {
AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
Trace trace = new Trace("TRACE_1", transportManager, clock, monitor);
// Trace is not started yet, default state is APPLICATION_PROCESS_STATE_UNKNOWN
Assert.assertEquals(ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN, trace.getAppState());
// activity1 comes to foreground.
currentTime = 1;
// registerForAppState() is called by Trace.start().
trace.start();
// Trace started, get state from AppStateMonitor.
Assert.assertEquals(ApplicationProcessState.BACKGROUND, trace.getAppState());
monitor.onActivityResumed(activity1);
Assert.assertTrue(monitor.isForeground());
Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
verify(transportManager, times(0)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
// activity1 goes to background.
currentTime = 2;
monitor.onActivityStopped(activity1);
Assert.assertFalse(monitor.isForeground());
// Foreground session trace.
verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
// Trace is updated through AppStatCallback.
Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
// unregisterForAppState() is called by Trace.stop()
trace.stop();
// trace has been through FOREGROUND_BACKGROUND
Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
// a TraceMetric is sent for this trace object.
verify(transportManager, times(2)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
TraceMetric metric = argTraceMetric.getValue();
Assert.assertEquals("TRACE_1", metric.getName());
}
Aggregations