Skip to content

Commit ec84a09

Browse files
committed
add more tests
1 parent 0a6a5bc commit ec84a09

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Tests/SentryTests/Helper/SentryExtensionDetectorTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ final class SentryExtensionDetectorTests: XCTestCase {
7878
XCTAssertEqual(identifier, "com.apple.ui-services")
7979
}
8080

81+
func testGetExtensionPointIdentifier_shareExtension() {
82+
// Arrange
83+
infoPlistWrapper.mockGetAppValueDictionaryReturnValue(
84+
forKey: SentryInfoPlistKey.extension.rawValue,
85+
value: ["NSExtensionPointIdentifier": "com.apple.share-services"]
86+
)
87+
88+
// Act
89+
let identifier = sut.getExtensionPointIdentifier()
90+
91+
// Assert
92+
XCTAssertEqual(identifier, "com.apple.share-services")
93+
}
94+
8195
// MARK: - App Hang Tracking Disable Detection
8296

8397
func testShouldDisableAppHangTracking_notAnExtension() {
@@ -130,6 +144,20 @@ final class SentryExtensionDetectorTests: XCTestCase {
130144
XCTAssertTrue(shouldDisable, "Action extension should disable app hang tracking")
131145
}
132146

147+
func testShouldDisableAppHangTracking_shareExtension() {
148+
// Arrange
149+
infoPlistWrapper.mockGetAppValueDictionaryReturnValue(
150+
forKey: SentryInfoPlistKey.extension.rawValue,
151+
value: ["NSExtensionPointIdentifier": "com.apple.share-services"]
152+
)
153+
154+
// Act
155+
let shouldDisable = sut.shouldDisableAppHangTracking()
156+
157+
// Assert
158+
XCTAssertTrue(shouldDisable, "Share extension should disable app hang tracking")
159+
}
160+
133161
func testShouldDisableAppHangTracking_unknownExtension() {
134162
// Arrange - extension with unknown identifier
135163
infoPlistWrapper.mockGetAppValueDictionaryReturnValue(

Tests/SentryTests/Helper/SentryExtensionTypeTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ final class SentryExtensionTypeTests: XCTestCase {
1313
func testAction_shouldReturnExpectedIdentifier() {
1414
XCTAssertEqual(SentryExtensionType.action.identifier, "com.apple.ui-services")
1515
}
16+
17+
func testShare_shouldReturnExpectedIdentifier() {
18+
XCTAssertEqual(SentryExtensionType.share.identifier, "com.apple.share-services")
19+
}
1620
}

Tests/SentryTests/Integrations/ANR/SentryANRTrackingIntegrationTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,31 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
822822
XCTAssertNil(Dynamic(sut).tracker.asAnyObject, "Tracker should not be initialized")
823823
}
824824

825+
func testInstall_runningInShareExtension_shouldNotInstall() {
826+
// Arrange
827+
let mockInfoPlist = TestInfoPlistWrapper()
828+
mockInfoPlist.mockGetAppValueDictionaryReturnValue(
829+
forKey: SentryInfoPlistKey.extension.rawValue,
830+
value: ["NSExtensionPointIdentifier": "com.apple.share-services"]
831+
)
832+
Dependencies.extensionDetector = SentryExtensionDetector(infoPlistWrapper: mockInfoPlist)
833+
834+
let options = Options()
835+
options.dsn = SentryANRTrackingIntegrationTests.dsn
836+
options.enableAppHangTracking = true
837+
options.appHangTimeoutInterval = 2.0
838+
839+
crashWrapper.internalIsBeingTraced = false
840+
sut = SentryANRTrackingIntegration()
841+
842+
// Act
843+
let result = sut.install(with: options)
844+
845+
// Assert
846+
XCTAssertFalse(result, "Should not install when running in a Share extension")
847+
XCTAssertNil(Dynamic(sut).tracker.asAnyObject, "Tracker should not be initialized")
848+
}
849+
825850
func testInstall_runningInUnknownExtension_shouldInstall() {
826851
// Arrange
827852
let mockInfoPlist = TestInfoPlistWrapper()

0 commit comments

Comments
 (0)