Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ah/exclude-combine
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Nov 14, 2024
2 parents 0d34710 + e4bc445 commit 7e81a97
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 28 deletions.
3 changes: 3 additions & 0 deletions FirebasePerformance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Fix a crash related to registering for notifications when the app is between foreground or background states. (#13174)

# 11.5.0
- [fixed] Replaced usage of the deprecated `UIApplication.keyWindow` property
with `UIWindow.isKeyWindow`; this API is also available on visionOS. Note that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ - (instancetype)init {
} else {
_traceBackgroundState = FPRTraceStateForegroundOnly;
}
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
});
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,27 @@ - (void)testForegroundTracking {

/** Validates if the foreground & background state is captured correctly. */
- (void)testBackgroundTracking {
XCTestExpectation *expectation = [self expectationWithDescription:@"Application state change"];

FPRTraceBackgroundActivityTracker *tracker = [[FPRTraceBackgroundActivityTracker alloc] init];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
XCTAssertEqual(tracker.traceBackgroundState, FPRTraceStateBackgroundAndForeground);
dispatch_async(dispatch_get_main_queue(), ^{
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:5.0
handler:^(NSError *_Nullable error) {
if (error) {
XCTFail(@"Expectation failed with error: %@", error);
} else {
XCTAssertEqual(tracker.traceBackgroundState,
FPRTraceStateBackgroundAndForeground);
}
}];
}

@end
51 changes: 39 additions & 12 deletions FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,28 @@ - (void)testValidTraceWithStageAndMetrics {

/** Validates the value of background state when the app is backgrounded. */
- (void)testValidTraceWithBackgrounding {
XCTestExpectation *expectation = [self expectationWithDescription:@"Application state change"];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
FIRTrace *trace = [[FIRTrace alloc] initWithName:@"Random"];
[trace start];
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
XCTAssertEqual(trace.backgroundTraceState, FPRTraceStateBackgroundAndForeground);
[trace stop];
dispatch_async(dispatch_get_main_queue(), ^{
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:5.0
handler:^(NSError *_Nullable error) {
if (error) {
XCTFail(@"Expectation failed with error: %@", error);
} else {
XCTAssertEqual(trace.backgroundTraceState,
FPRTraceStateBackgroundAndForeground);
[trace stop];
}
}];
}

/** Validates the value of background state when trace is not started. */
Expand All @@ -452,15 +465,29 @@ - (void)testValidTraceWithoutStart {

/** Validates the value of background state is available after trace is stopped. */
- (void)testBackgroundStateAfterTraceStop {
XCTestExpectation *expectation = [self expectationWithDescription:@"Application state change"];

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
FIRTrace *trace = [[FIRTrace alloc] initWithName:@"Random"];
[trace start];
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
[trace stop];
XCTAssertEqual(trace.backgroundTraceState, FPRTraceStateBackgroundAndForeground);
dispatch_async(dispatch_get_main_queue(), ^{
[defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:5.0
handler:^(NSError *_Nullable error) {
if (error) {
XCTFail(@"Expectation failed with error: %@", error);
} else {
[trace stop];
XCTAssertEqual(trace.backgroundTraceState,
FPRTraceStateBackgroundAndForeground);
}
}];
}

/** Validates that stages do not have any valid background state. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function runXcodebuild() {
-workspace 'CocoapodsIntegrationTest.xcworkspace'
-scheme 'CocoapodsIntegrationTest'
-sdk 'iphonesimulator'
-destination 'platform=iOS Simulator,name=iPhone 14'
-destination 'platform=iOS Simulator,name=iPhone 15'
CODE_SIGNING_REQUIRED=NO
clean
build
Expand All @@ -36,7 +36,7 @@ function runXcodebuild() {
parameters=("${buildcache_xcb_flags[@]}" "${parameters[@]}")

echo xcodebuild "${parameters[@]}"
xcodebuild "${parameters[@]}" | xcpretty; result=$?
xcodebuild "${parameters[@]}" | xcbeautify --renderer github-actions; result=$?
}

# Configures bundler environment using Gemfile at the specified path.
Expand Down

0 comments on commit 7e81a97

Please sign in to comment.