FPRTraceBackgroundActivityTrackerTest.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <XCTest/XCTest.h>
  15. #import "FirebasePerformance/Sources/AppActivity/FPRTraceBackgroundActivityTracker.h"
  16. @interface FPRTraceBackgroundActivityTrackerTest : XCTestCase
  17. @end
  18. @implementation FPRTraceBackgroundActivityTrackerTest
  19. /** Validate instance creation. */
  20. - (void)testInstanceCreation {
  21. XCTAssertNotNil([[FPRTraceBackgroundActivityTracker alloc] init]);
  22. }
  23. /** Validates if the foreground state is captured correctly. */
  24. - (void)testForegroundTracking {
  25. FPRTraceBackgroundActivityTracker *tracker = [[FPRTraceBackgroundActivityTracker alloc] init];
  26. NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
  27. [defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
  28. object:[UIApplication sharedApplication]];
  29. XCTAssertEqual(tracker.traceBackgroundState, FPRTraceStateForegroundOnly);
  30. }
  31. /** Validates if the foreground & backgound state is captured correctly. */
  32. - (void)testBackgroundTracking {
  33. FPRTraceBackgroundActivityTracker *tracker = [[FPRTraceBackgroundActivityTracker alloc] init];
  34. NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
  35. [defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
  36. object:[UIApplication sharedApplication]];
  37. [defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
  38. object:[UIApplication sharedApplication]];
  39. XCTAssertEqual(tracker.traceBackgroundState, FPRTraceStateBackgroundAndForeground);
  40. }
  41. @end