@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import Bugsee;
|
|
3
|
+
@import BugseeRNSupport;
|
|
4
|
+
|
|
5
|
+
#import "BGSRNFakeReport.h"
|
|
6
|
+
|
|
7
|
+
/// A deadline the test fires by hand; records cancellation.
|
|
8
|
+
@interface BGSRNManualTask : NSObject
|
|
9
|
+
@property (nonatomic, copy) dispatch_block_t block;
|
|
10
|
+
@property (nonatomic) int64_t delayMs;
|
|
11
|
+
@property (nonatomic) BOOL cancelled;
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@implementation BGSRNManualTask
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
/// The one property everything here protects: the SDK's completion runs
|
|
18
|
+
/// exactly once for every dispatch, whichever of JS, the deadline, a detach or
|
|
19
|
+
/// a failure gets there first. Running it twice advances the SDK's chain
|
|
20
|
+
/// twice; never running it stalls the report until the SDK's own timeout.
|
|
21
|
+
///
|
|
22
|
+
/// Mirrors Android's `ReportHandlerBridgeTest` by name, except where iOS
|
|
23
|
+
/// differs on purpose: a recovered (off-main) report reaches JS here.
|
|
24
|
+
@interface BGSRNReportHandlerBridgeTests : XCTestCase
|
|
25
|
+
@end
|
|
26
|
+
|
|
27
|
+
@implementation BGSRNReportHandlerBridgeTests {
|
|
28
|
+
NSMutableArray<BGSRNManualTask *> *_tasks;
|
|
29
|
+
NSMutableArray<NSString *> *_lines;
|
|
30
|
+
NSMutableArray<NSDictionary *> *_requests;
|
|
31
|
+
BGSRNReportHandlerBridge *_bridge;
|
|
32
|
+
BGSRNFakeReport *_report;
|
|
33
|
+
NSObject *_sink;
|
|
34
|
+
NSInteger _completions;
|
|
35
|
+
BGSCallback _completion;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)setUp {
|
|
39
|
+
[super setUp];
|
|
40
|
+
NSMutableArray<BGSRNManualTask *> *tasks = [NSMutableArray array];
|
|
41
|
+
NSMutableArray<NSString *> *lines = [NSMutableArray array];
|
|
42
|
+
_tasks = tasks;
|
|
43
|
+
_lines = lines;
|
|
44
|
+
_requests = [NSMutableArray array];
|
|
45
|
+
_bridge = [[BGSRNReportHandlerBridge alloc]
|
|
46
|
+
initWithScheduler:^id(dispatch_block_t task, int64_t delayMs) {
|
|
47
|
+
BGSRNManualTask *t = [BGSRNManualTask new];
|
|
48
|
+
t.block = task;
|
|
49
|
+
t.delayMs = delayMs;
|
|
50
|
+
[tasks addObject:t];
|
|
51
|
+
return t;
|
|
52
|
+
}
|
|
53
|
+
cancel:^(id token) {
|
|
54
|
+
((BGSRNManualTask *)token).cancelled = YES;
|
|
55
|
+
}
|
|
56
|
+
log:^(NSString *line) {
|
|
57
|
+
[lines addObject:line];
|
|
58
|
+
}];
|
|
59
|
+
_report = [BGSRNFakeReport new];
|
|
60
|
+
_sink = [NSObject new];
|
|
61
|
+
_completions = 0;
|
|
62
|
+
__weak __typeof(self) weakSelf = self;
|
|
63
|
+
_completion = ^{
|
|
64
|
+
__strong __typeof(weakSelf) strongSelf = weakSelf;
|
|
65
|
+
strongSelf->_completions += 1;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
- (void)attachRecorder:(id)sink into:(NSMutableArray<NSDictionary *> *)requests {
|
|
70
|
+
[_bridge attach:sink block:^BOOL(NSDictionary *request) {
|
|
71
|
+
[requests addObject:request];
|
|
72
|
+
return YES;
|
|
73
|
+
}];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
- (void)attachWithBothPhases {
|
|
77
|
+
[self attachRecorder:_sink into:_requests];
|
|
78
|
+
[_bridge setPhasesBefore:YES after:YES];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (void)dispatchLive:(BGSRNReportPhase)phase terminating:(BOOL)terminating {
|
|
82
|
+
[_bridge dispatchPhase:phase report:_report isTerminating:terminating onMainThread:YES completion:_completion];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (void)fireDue {
|
|
86
|
+
for (BGSRNManualTask *t in [_tasks copy]) {
|
|
87
|
+
if (!t.cancelled) {
|
|
88
|
+
t.block();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// The real race: the deadline has already started when `cancel` arrives, so
|
|
94
|
+
/// cancelling does not stop it.
|
|
95
|
+
- (void)fireEvenIfCancelled {
|
|
96
|
+
for (BGSRNManualTask *t in [_tasks copy]) {
|
|
97
|
+
t.block();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// iOS never passes YES today, but the contract allows it: the process dies
|
|
102
|
+
/// when the callback returns, and nothing asynchronous survives it.
|
|
103
|
+
- (void)testTerminatingCompletesSynchronouslyAndNeverReachesJs {
|
|
104
|
+
[self attachWithBothPhases];
|
|
105
|
+
|
|
106
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:YES];
|
|
107
|
+
|
|
108
|
+
XCTAssertEqual(_completions, 1);
|
|
109
|
+
XCTAssertEqual(_requests.count, 0u);
|
|
110
|
+
XCTAssertEqual(_tasks.count, 0u);
|
|
111
|
+
XCTAssertEqualObjects(_lines, (@[ @"BugseeRN report handler - completed by=terminating phase=before report=report-1" ]));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// Start-up, or after a reload tore the bridge down.
|
|
115
|
+
- (void)testNoSinkCompletesImmediately {
|
|
116
|
+
[_bridge setPhasesBefore:YES after:YES];
|
|
117
|
+
|
|
118
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
119
|
+
|
|
120
|
+
XCTAssertEqual(_completions, 1);
|
|
121
|
+
XCTAssertEqual(_tasks.count, 0u);
|
|
122
|
+
XCTAssertEqualObjects(_lines, (@[ @"BugseeRN report handler - completed by=no-handler phase=after report=report-1" ]));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// JS registered only one phase; the other must not cost a round trip.
|
|
126
|
+
- (void)testUnregisteredPhaseCompletesImmediately {
|
|
127
|
+
[self attachRecorder:_sink into:_requests];
|
|
128
|
+
[_bridge setPhasesBefore:NO after:YES];
|
|
129
|
+
|
|
130
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
131
|
+
|
|
132
|
+
XCTAssertEqual(_completions, 1);
|
|
133
|
+
XCTAssertEqual(_requests.count, 0u);
|
|
134
|
+
|
|
135
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
136
|
+
XCTAssertEqual(_requests.count, 1u);
|
|
137
|
+
XCTAssertEqual(_completions, 1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// `onAfter` can be delivered more than once for one report.
|
|
141
|
+
- (void)testEachDeliveryGetsAFreshHandle {
|
|
142
|
+
[self attachWithBothPhases];
|
|
143
|
+
|
|
144
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
145
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
146
|
+
|
|
147
|
+
NSString *first = _requests[0][@"handleId"];
|
|
148
|
+
NSString *second = _requests[1][@"handleId"];
|
|
149
|
+
XCTAssertNotEqualObjects(first, second);
|
|
150
|
+
XCTAssertTrue([first hasPrefix:@"rh-"]);
|
|
151
|
+
XCTAssertEqual([_bridge reportFor:first], _report);
|
|
152
|
+
XCTAssertEqual([_bridge reportFor:second], _report);
|
|
153
|
+
|
|
154
|
+
XCTAssertTrue([_bridge complete:first]);
|
|
155
|
+
XCTAssertNil([_bridge reportFor:first]);
|
|
156
|
+
XCTAssertEqual([_bridge reportFor:second], _report);
|
|
157
|
+
XCTAssertEqual(_completions, 1);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// JS completes twice (the dispatcher's own guarantee is once, but a native
|
|
161
|
+
/// no-op is the contract), a detach sweeps outstanding handles, and the
|
|
162
|
+
/// deadline was already running when it was cancelled. One completion.
|
|
163
|
+
- (void)testCompleteRunsTheSdkCompletionExactlyOnce {
|
|
164
|
+
[self attachWithBothPhases];
|
|
165
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
166
|
+
NSString *handleId = _requests.lastObject[@"handleId"];
|
|
167
|
+
|
|
168
|
+
XCTAssertTrue([_bridge complete:handleId]);
|
|
169
|
+
XCTAssertFalse([_bridge complete:handleId]);
|
|
170
|
+
[_bridge detach:_sink];
|
|
171
|
+
[self fireEvenIfCancelled];
|
|
172
|
+
|
|
173
|
+
XCTAssertEqual(_completions, 1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
- (void)testDeadlineCompletesAndKillsTheHandle {
|
|
177
|
+
[self attachWithBothPhases];
|
|
178
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
179
|
+
NSString *handleId = _requests.lastObject[@"handleId"];
|
|
180
|
+
XCTAssertEqual(_tasks[0].delayMs, BGSRNLiveDeadlineMs);
|
|
181
|
+
|
|
182
|
+
[self fireDue];
|
|
183
|
+
|
|
184
|
+
XCTAssertEqual(_completions, 1);
|
|
185
|
+
XCTAssertNil([_bridge reportFor:handleId]);
|
|
186
|
+
XCTAssertFalse([_bridge complete:handleId]);
|
|
187
|
+
XCTAssertEqual(_completions, 1);
|
|
188
|
+
XCTAssertEqualObjects(_lines.lastObject,
|
|
189
|
+
([NSString stringWithFormat:@"BugseeRN report handler %@ completed by=deadline", handleId]));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
- (void)testCompletingBeforeTheDeadlineCancelsTheTimer {
|
|
193
|
+
[self attachWithBothPhases];
|
|
194
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
195
|
+
|
|
196
|
+
[_bridge complete:_requests.lastObject[@"handleId"]];
|
|
197
|
+
|
|
198
|
+
XCTAssertTrue(_tasks[0].cancelled);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// A reload: nothing in the new JS runtime knows the old handles, so they are
|
|
202
|
+
/// completed now rather than left for the deadline, and the phases the old
|
|
203
|
+
/// runtime asked for no longer describe anyone.
|
|
204
|
+
- (void)testDetachCompletesEverythingOutstanding {
|
|
205
|
+
[self attachWithBothPhases];
|
|
206
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
207
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
208
|
+
NSString *first = _requests[0][@"handleId"];
|
|
209
|
+
|
|
210
|
+
[_bridge detach:_sink];
|
|
211
|
+
|
|
212
|
+
XCTAssertEqual(_completions, 2);
|
|
213
|
+
XCTAssertNil([_bridge reportFor:first]);
|
|
214
|
+
XCTAssertTrue(_tasks[0].cancelled);
|
|
215
|
+
XCTAssertTrue(_tasks[1].cancelled);
|
|
216
|
+
XCTAssertEqualObjects(_lines.lastObject,
|
|
217
|
+
([NSString stringWithFormat:@"BugseeRN report handler %@ completed by=detach",
|
|
218
|
+
_requests[1][@"handleId"]]));
|
|
219
|
+
|
|
220
|
+
// Phases are cleared: a sink attached later gets nothing until its own
|
|
221
|
+
// runtime registers.
|
|
222
|
+
NSMutableArray<NSDictionary *> *next = [NSMutableArray array];
|
|
223
|
+
NSObject *nextSink = [NSObject new];
|
|
224
|
+
[self attachRecorder:nextSink into:next];
|
|
225
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
226
|
+
XCTAssertEqual(next.count, 0u);
|
|
227
|
+
XCTAssertEqual(_completions, 3);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// A fast reload attaches the new module before the old one is invalidated.
|
|
231
|
+
/// The old detach must not silence the new bridge -- but the handles it was
|
|
232
|
+
/// given die with it.
|
|
233
|
+
- (void)testDetachingAStaleSinkLeavesTheCurrentOne {
|
|
234
|
+
[self attachWithBothPhases];
|
|
235
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
236
|
+
NSString *staleHandle = _requests.lastObject[@"handleId"];
|
|
237
|
+
|
|
238
|
+
NSMutableArray<NSDictionary *> *current = [NSMutableArray array];
|
|
239
|
+
NSObject *currentSink = [NSObject new];
|
|
240
|
+
[self attachRecorder:currentSink into:current];
|
|
241
|
+
[_bridge setPhasesBefore:YES after:YES];
|
|
242
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
243
|
+
NSString *currentHandle = current.lastObject[@"handleId"];
|
|
244
|
+
|
|
245
|
+
[_bridge detach:_sink];
|
|
246
|
+
|
|
247
|
+
XCTAssertEqual(_completions, 1);
|
|
248
|
+
XCTAssertNil([_bridge reportFor:staleHandle]);
|
|
249
|
+
XCTAssertNotNil([_bridge reportFor:currentHandle]);
|
|
250
|
+
|
|
251
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
252
|
+
XCTAssertEqual(current.count, 2u);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// A new sink is a new JS runtime, which has registered nothing yet. Until it
|
|
256
|
+
/// does, a dispatch must not wait on a listener that does not exist.
|
|
257
|
+
- (void)testAttachingANewSinkClearsPhases {
|
|
258
|
+
[self attachWithBothPhases];
|
|
259
|
+
|
|
260
|
+
[self attachRecorder:[NSObject new] into:[NSMutableArray array]];
|
|
261
|
+
[self dispatchLive:BGSRNReportPhaseAfter terminating:NO];
|
|
262
|
+
|
|
263
|
+
XCTAssertEqual(_completions, 1);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// A dead bridge (module gone, emitter unset) reports the emit as not
|
|
267
|
+
/// delivered, on the SDK's thread (main, on the live path). JS will never
|
|
268
|
+
/// answer, so the bridge answers for it now -- by branching on the result,
|
|
269
|
+
/// not by catching: nothing may unwind through this non-exception-safe ARC
|
|
270
|
+
/// file.
|
|
271
|
+
- (void)testASinkThatCannotDeliverStillCompletes {
|
|
272
|
+
[_bridge attach:_sink block:^BOOL(NSDictionary *request) {
|
|
273
|
+
return NO;
|
|
274
|
+
}];
|
|
275
|
+
[_bridge setPhasesBefore:YES after:YES];
|
|
276
|
+
|
|
277
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
278
|
+
|
|
279
|
+
XCTAssertEqual(_completions, 1);
|
|
280
|
+
XCTAssertTrue(_tasks[0].cancelled);
|
|
281
|
+
XCTAssertTrue([_lines.lastObject hasSuffix:@"completed by=no-handler"], @"%@", _lines.lastObject);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// ...and a sink that delivered leaves the handle waiting for JS.
|
|
285
|
+
- (void)testASinkThatDeliveredLeavesTheHandleOpen {
|
|
286
|
+
[self attachWithBothPhases];
|
|
287
|
+
|
|
288
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
289
|
+
|
|
290
|
+
XCTAssertEqual(_completions, 0);
|
|
291
|
+
XCTAssertFalse(_tasks[0].cancelled);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/// A cancelled `dispatch_block` keeps its captures until its fire time, and
|
|
295
|
+
/// the deadline task captures the handle -- so a finished handle must drop
|
|
296
|
+
/// the report and the SDK's completion itself, or it pins both for up to
|
|
297
|
+
/// 25 s. The manual scheduler's cancelled task keeps its block the same way.
|
|
298
|
+
- (void)testAFinishedHandleNoLongerPinsTheReportOrTheCompletion {
|
|
299
|
+
[self attachWithBothPhases];
|
|
300
|
+
__weak BGSRNFakeReport *weakReport = nil;
|
|
301
|
+
__weak NSObject *weakCaptured = nil;
|
|
302
|
+
@autoreleasepool {
|
|
303
|
+
BGSRNFakeReport *report = [BGSRNFakeReport new];
|
|
304
|
+
NSObject *captured = [NSObject new];
|
|
305
|
+
weakReport = report;
|
|
306
|
+
weakCaptured = captured;
|
|
307
|
+
BGSCallback completion = ^{
|
|
308
|
+
(void)captured;
|
|
309
|
+
};
|
|
310
|
+
[_bridge dispatchPhase:BGSRNReportPhaseBefore
|
|
311
|
+
report:report
|
|
312
|
+
isTerminating:NO
|
|
313
|
+
onMainThread:YES
|
|
314
|
+
completion:completion];
|
|
315
|
+
XCTAssertTrue([_bridge complete:_requests.lastObject[@"handleId"]]);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
XCTAssertEqual(_tasks.count, 1u);
|
|
319
|
+
XCTAssertTrue(_tasks[0].cancelled);
|
|
320
|
+
XCTAssertNotNil(_tasks[0].block, @"precondition: the cancelled deadline task still holds the handle");
|
|
321
|
+
XCTAssertNil(weakReport, @"a finished handle must not keep its report alive");
|
|
322
|
+
XCTAssertNil(weakCaptured, @"a finished handle must not keep the SDK's completion alive");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
- (void)testAThrowingSdkCompletionDoesNotEscape {
|
|
326
|
+
[self attachWithBothPhases];
|
|
327
|
+
BGSCallback throwing = ^{
|
|
328
|
+
[NSException raise:NSInternalInconsistencyException format:@"sdk failure"];
|
|
329
|
+
};
|
|
330
|
+
[_bridge dispatchPhase:BGSRNReportPhaseBefore report:_report isTerminating:NO onMainThread:YES completion:throwing];
|
|
331
|
+
|
|
332
|
+
XCTAssertTrue([_bridge complete:_requests.lastObject[@"handleId"]]);
|
|
333
|
+
|
|
334
|
+
XCTAssertNoThrow([_bridge dispatchPhase:BGSRNReportPhaseBefore
|
|
335
|
+
report:_report
|
|
336
|
+
isTerminating:YES
|
|
337
|
+
onMainThread:YES
|
|
338
|
+
completion:throwing]);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/// The request carries the report, and the live deadline, to JS.
|
|
342
|
+
- (void)testTheLiveRequestCarriesTheReportAndTheLiveDeadline {
|
|
343
|
+
[self attachWithBothPhases];
|
|
344
|
+
_report.fakeType = @"crash";
|
|
345
|
+
|
|
346
|
+
[self dispatchLive:BGSRNReportPhaseBefore terminating:NO];
|
|
347
|
+
|
|
348
|
+
NSDictionary *request = _requests.lastObject;
|
|
349
|
+
XCTAssertEqualObjects(request[@"phase"], @"before");
|
|
350
|
+
XCTAssertEqualObjects(request[@"reportId"], @"report-1");
|
|
351
|
+
XCTAssertEqualObjects(request[@"type"], @"crash");
|
|
352
|
+
XCTAssertEqualObjects(request[@"deadlineMs"], @25000.0);
|
|
353
|
+
XCTAssertEqual(_tasks[0].delayMs, 25000);
|
|
354
|
+
XCTAssertEqualObjects(_lines[0],
|
|
355
|
+
([NSString stringWithFormat:@"BugseeRN report handler %@ phase=before deadline=25000",
|
|
356
|
+
request[@"handleId"]]));
|
|
357
|
+
|
|
358
|
+
XCTAssertTrue([_bridge complete:request[@"handleId"]]);
|
|
359
|
+
XCTAssertEqualObjects(_lines[1],
|
|
360
|
+
([NSString stringWithFormat:@"BugseeRN report handler %@ completed by=js",
|
|
361
|
+
request[@"handleId"]]));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/// Unlike Android, a recovered report (off main) DOES reach JS on iOS: the SDK
|
|
365
|
+
/// re-persists it when a late completion arrives. It gets the short deadline.
|
|
366
|
+
- (void)testARecoveredReportReachesJsWithTheRecoveryDeadline {
|
|
367
|
+
[self attachWithBothPhases];
|
|
368
|
+
|
|
369
|
+
[_bridge dispatchPhase:BGSRNReportPhaseAfter report:_report isTerminating:NO onMainThread:NO completion:_completion];
|
|
370
|
+
|
|
371
|
+
XCTAssertEqual(_requests.count, 1u);
|
|
372
|
+
XCTAssertEqualObjects(_requests[0][@"deadlineMs"], @2500.0);
|
|
373
|
+
XCTAssertEqual(_tasks[0].delayMs, 2500);
|
|
374
|
+
XCTAssertEqual(_completions, 0);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
- (void)testSharedIsOneInstance {
|
|
378
|
+
XCTAssertNotNil(BGSRNReportHandlerBridge.shared);
|
|
379
|
+
XCTAssertTrue(BGSRNReportHandlerBridge.shared == BGSRNReportHandlerBridge.shared);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@end
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import Bugsee;
|
|
3
|
+
@import BugseeRNSupport;
|
|
4
|
+
|
|
5
|
+
#import "BGSRNFakeReport.h"
|
|
6
|
+
|
|
7
|
+
/// Mirrors Android's `ReportOpsTest` by name where the rule is shared.
|
|
8
|
+
@interface BGSRNReportOpsTests : XCTestCase
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
@implementation BGSRNReportOpsTests {
|
|
12
|
+
BGSRNFakeReport *_report;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (void)setUp {
|
|
16
|
+
[super setUp];
|
|
17
|
+
_report = [BGSRNFakeReport new];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (void)assertRejected:(NSDictionary *)patch {
|
|
21
|
+
NSError *error = nil;
|
|
22
|
+
XCTAssertFalse([BGSRNReportOps applyPatch:patch toReport:_report error:&error], @"accepted %@", patch);
|
|
23
|
+
XCTAssertEqualObjects(error.domain, BGSRNReportErrorDomain);
|
|
24
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
25
|
+
XCTAssertEqualObjects(BGSRNReportErrorWireCode(error), @"E_REPORT_BAD_ARGUMENT");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (void)assertApplied:(NSDictionary *)patch {
|
|
29
|
+
NSError *error = nil;
|
|
30
|
+
const BOOL applied = [BGSRNReportOps applyPatch:patch toReport:_report error:&error];
|
|
31
|
+
XCTAssertTrue(applied, @"rejected %@: %@", patch, error);
|
|
32
|
+
XCTAssertNil(error);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#pragma mark - Severity
|
|
36
|
+
|
|
37
|
+
/// An untouched report reads 0, "not set". It crosses as 0; JS maps it to
|
|
38
|
+
/// undefined rather than inventing a level nobody chose.
|
|
39
|
+
- (void)testReadsUnsetSeverityAsZero {
|
|
40
|
+
XCTAssertEqualObjects([BGSRNReportOps readReport:_report][@"severity"], @0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// By the SDK's value, which both platforms and the JS type speak.
|
|
44
|
+
- (void)testReadsSeverityByValue {
|
|
45
|
+
_report.fakeSeverity = BugseeSeverityCritical;
|
|
46
|
+
XCTAssertEqualObjects([BGSRNReportOps readReport:_report][@"severity"], @4);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (void)testAppliesSeverityOneToFive {
|
|
50
|
+
for (NSInteger value = 1; value <= 5; value++) {
|
|
51
|
+
NSError *error = nil;
|
|
52
|
+
XCTAssertTrue([BGSRNReportOps applyPatch:@{ @"severity" : @((double)value) } toReport:_report error:&error]);
|
|
53
|
+
XCTAssertNil(error);
|
|
54
|
+
XCTAssertEqual((NSInteger)_report.fakeSeverity, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// The SDK setter IGNORES a value outside 1..5 and keeps the current one --
|
|
59
|
+
/// silently. Unchecked, `setSeverity(0)` would resolve as if it had worked.
|
|
60
|
+
- (void)testRejectsSeverityZeroAndSixAndLeavesTheReportAlone {
|
|
61
|
+
_report.fakeSeverity = BugseeSeverityHigh;
|
|
62
|
+
[self assertRejected:@{ @"severity" : @0 }];
|
|
63
|
+
[self assertRejected:@{ @"severity" : @6 }];
|
|
64
|
+
[self assertRejected:@{ @"severity" : @2.5 }];
|
|
65
|
+
[self assertRejected:@{ @"severity" : @"3" }];
|
|
66
|
+
[self assertRejected:@{ @"severity" : @YES }];
|
|
67
|
+
[self assertRejected:@{ @"severity" : NSNull.null }];
|
|
68
|
+
XCTAssertEqual(_report.fakeSeverity, BugseeSeverityHigh);
|
|
69
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// The rejection never echoes the value a caller sent: anything JS allows can
|
|
73
|
+
/// arrive, and rendering it into the message would carry it back to JS.
|
|
74
|
+
- (void)testSeverityRejectionNeverEchoesTheOffendingValue {
|
|
75
|
+
NSError *error = nil;
|
|
76
|
+
XCTAssertFalse([BGSRNReportOps applyPatch:@{ @"severity" : @"s3cret-severity-value" }
|
|
77
|
+
toReport:_report
|
|
78
|
+
error:&error]);
|
|
79
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error), @"severity must be an integer 1..5");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#pragma mark - Patch
|
|
83
|
+
|
|
84
|
+
/// A valid field next to an invalid one must not land on its own.
|
|
85
|
+
- (void)testPatchIsAllOrNothing {
|
|
86
|
+
[self assertRejected:@{
|
|
87
|
+
@"summary" : @"new summary",
|
|
88
|
+
@"labels" : @[ @"a", @"b" ],
|
|
89
|
+
@"attributes" : @{ @"k" : @"v" },
|
|
90
|
+
@"severity" : @9,
|
|
91
|
+
}];
|
|
92
|
+
XCTAssertNil(_report.fakeSummary);
|
|
93
|
+
XCTAssertEqual(_report.fakeLabels.count, 0u);
|
|
94
|
+
XCTAssertEqual(_report.fakeAttributes.count, 0u);
|
|
95
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Parity with the JS proxy, which rejects it before crossing: an empty
|
|
99
|
+
/// attribute name is a bad argument like any other malformed field, and fails
|
|
100
|
+
/// the whole patch -- the valid name next to it included.
|
|
101
|
+
- (void)testRejectsAnEmptyAttributeNameAndAppliesNothing {
|
|
102
|
+
NSDictionary *patch = @{
|
|
103
|
+
@"summary" : @"new summary",
|
|
104
|
+
@"attributes" : @{ @"ok" : @"v", @"" : @"x" },
|
|
105
|
+
};
|
|
106
|
+
[self assertRejected:patch];
|
|
107
|
+
NSError *error = nil;
|
|
108
|
+
[BGSRNReportOps applyPatch:patch toReport:_report error:&error];
|
|
109
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error), @"attribute name must be a non-empty string");
|
|
110
|
+
XCTAssertNil(_report.fakeSummary);
|
|
111
|
+
XCTAssertEqual(_report.fakeAttributes.count, 0u);
|
|
112
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// One call, not `clearLabels` + `addLabels:`: between the two, the SDK (or a
|
|
116
|
+
/// concurrent reader) would see a report with no labels at all.
|
|
117
|
+
- (void)testLabelsReplaceThroughReplaceLabels {
|
|
118
|
+
[_report.fakeLabels addObject:@"old"];
|
|
119
|
+
[self assertApplied:@{ @"labels" : @[ @"x", @"y" ] }];
|
|
120
|
+
XCTAssertEqualObjects(_report.fakeLabels, (@[ @"x", @"y" ]));
|
|
121
|
+
XCTAssertEqualObjects(_report.mutations, @[ @"replaceLabels:" ]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- (void)testNSNullRemovesAnAttribute {
|
|
125
|
+
_report.fakeAttributes[@"gone"] = @"value";
|
|
126
|
+
_report.fakeAttributes[@"kept"] = @"value";
|
|
127
|
+
[self assertApplied:@{ @"attributes" : @{ @"gone" : NSNull.null, @"added" : @7 } }];
|
|
128
|
+
XCTAssertNil(_report.fakeAttributes[@"gone"]);
|
|
129
|
+
XCTAssertEqualObjects(_report.fakeAttributes[@"kept"], @"value");
|
|
130
|
+
XCTAssertEqualObjects(_report.fakeAttributes[@"added"], @7);
|
|
131
|
+
XCTAssertTrue([_report.mutations containsObject:@"removeAttributeForName:"]);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Clear-then-set in one patch, whatever order the dictionary iterates in.
|
|
135
|
+
- (void)testClearAttributesRunsBeforeAttributes {
|
|
136
|
+
_report.fakeAttributes[@"old"] = @"value";
|
|
137
|
+
[self assertApplied:@{ @"attributes" : @{ @"fresh" : @YES }, @"clearAttributes" : @YES }];
|
|
138
|
+
XCTAssertEqualObjects(_report.fakeAttributes, @{ @"fresh" : @YES });
|
|
139
|
+
XCTAssertEqualObjects(_report.mutations, (@[ @"clearAllAttributes", @"setAttribute:forName:" ]));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
- (void)testSummaryAndDescriptionSetAndClear {
|
|
143
|
+
_report.fakeDescription = @"old";
|
|
144
|
+
[self assertApplied:@{ @"summary" : @"s", @"description" : NSNull.null }];
|
|
145
|
+
XCTAssertEqualObjects(_report.fakeSummary, @"s");
|
|
146
|
+
XCTAssertNil(_report.fakeDescription);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// A misspelled key must fail loudly, not drop part of the patch.
|
|
150
|
+
- (void)testUnknownPatchKeyIsRejected {
|
|
151
|
+
[self assertRejected:@{ @"summary" : @"s", @"sumary" : @"typo" }];
|
|
152
|
+
XCTAssertNil(_report.fakeSummary);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
- (void)testMalformedFieldsAreRejected {
|
|
156
|
+
[self assertRejected:@{ @"summary" : @3 }];
|
|
157
|
+
[self assertRejected:@{ @"labels" : @"a" }];
|
|
158
|
+
[self assertRejected:@{ @"labels" : @[ @"a", @1 ] }];
|
|
159
|
+
[self assertRejected:@{ @"clearAttributes" : @NO }];
|
|
160
|
+
[self assertRejected:@{ @"clearAttributes" : @1 }];
|
|
161
|
+
[self assertRejected:@{ @"attributes" : @[] }];
|
|
162
|
+
[self assertRejected:@{ @"attributes" : @{ @"k" : @[] } }];
|
|
163
|
+
[self assertRejected:@{ @"attributes" : @{ @"k" : @(INFINITY) } }];
|
|
164
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// JS numbers are doubles; an integral one is stored as an integer, so an
|
|
168
|
+
/// attribute of 3 reaches the backend as 3 and not 3.0.
|
|
169
|
+
- (void)testIntegralNumbersCrossAsIntegers {
|
|
170
|
+
[self assertApplied:@{ @"attributes" : @{ @"n" : @3.0, @"f" : @2.5, @"b" : @YES } }];
|
|
171
|
+
NSNumber *n = _report.fakeAttributes[@"n"];
|
|
172
|
+
XCTAssertNotNil(n);
|
|
173
|
+
XCTAssertEqualObjects(n ? @(n.objCType) : nil, @(@encode(long long)));
|
|
174
|
+
XCTAssertEqualObjects(_report.fakeAttributes[@"n"], @3);
|
|
175
|
+
XCTAssertEqualObjects(_report.fakeAttributes[@"f"], @2.5);
|
|
176
|
+
XCTAssertEqual((__bridge CFBooleanRef)_report.fakeAttributes[@"b"], kCFBooleanTrue);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#pragma mark - Read
|
|
180
|
+
|
|
181
|
+
/// The SDK documents these ascending; sorted again here, defensively.
|
|
182
|
+
- (void)testScreenshotIdsAreSortedAscending {
|
|
183
|
+
_report.fakeScreenshotDisplayIds = @[ @2, @0, @1 ];
|
|
184
|
+
XCTAssertEqualObjects([BGSRNReportOps readReport:_report][@"screenshotDisplayIds"], (@[ @0, @1, @2 ]));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// The whole snapshot the JS side normalises, in one read.
|
|
188
|
+
- (void)testReadReturnsTheWholeSnapshot {
|
|
189
|
+
_report.fakeSummary = @"s";
|
|
190
|
+
_report.fakeDescription = @"d";
|
|
191
|
+
[_report.fakeLabels addObject:@"l"];
|
|
192
|
+
_report.fakeAttributes[@"n"] = @1;
|
|
193
|
+
_report.fakeAttributes[@"opaque"] = [NSDate date];
|
|
194
|
+
[_report.fakeAttachmentNames addObject:@"a.txt"];
|
|
195
|
+
|
|
196
|
+
NSDictionary *read = [BGSRNReportOps readReport:_report];
|
|
197
|
+
|
|
198
|
+
XCTAssertEqualObjects(read[@"summary"], @"s");
|
|
199
|
+
XCTAssertEqualObjects(read[@"description"], @"d");
|
|
200
|
+
XCTAssertEqualObjects(read[@"labels"], @[ @"l" ]);
|
|
201
|
+
// A value JS has no type for is dropped, not stringified into a fake one.
|
|
202
|
+
XCTAssertEqualObjects(read[@"attributes"], @{ @"n" : @1 });
|
|
203
|
+
XCTAssertEqualObjects(read[@"attachmentNames"], @[ @"a.txt" ]);
|
|
204
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/// Unset text is omitted rather than NSNull; JS reads either as undefined.
|
|
208
|
+
- (void)testReadOmitsUnsetText {
|
|
209
|
+
NSDictionary *read = [BGSRNReportOps readReport:_report];
|
|
210
|
+
XCTAssertNil(read[@"summary"]);
|
|
211
|
+
XCTAssertNil(read[@"description"]);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#pragma mark - Attachments
|
|
215
|
+
|
|
216
|
+
- (void)testANilFromTheSdkIsARejectedAttachment {
|
|
217
|
+
_report.rejectAttachments = YES;
|
|
218
|
+
NSError *error = nil;
|
|
219
|
+
XCTAssertFalse([BGSRNReportOps addData:@"AQ==" name:@"blob" mimeType:nil toReport:_report error:&error]);
|
|
220
|
+
XCTAssertEqual(error.code, BGSRNReportErrorAttachmentRejected);
|
|
221
|
+
XCTAssertEqualObjects(BGSRNReportErrorWireCode(error), @"E_REPORT_ATTACHMENT_REJECTED");
|
|
222
|
+
|
|
223
|
+
error = nil;
|
|
224
|
+
XCTAssertFalse([BGSRNReportOps addFileAtPath:@"/nonexistent"
|
|
225
|
+
name:@"file"
|
|
226
|
+
mimeType:nil
|
|
227
|
+
move:NO
|
|
228
|
+
toReport:_report
|
|
229
|
+
error:&error]);
|
|
230
|
+
XCTAssertEqual(error.code, BGSRNReportErrorAttachmentRejected);
|
|
231
|
+
|
|
232
|
+
_report.rejectAttachments = NO;
|
|
233
|
+
error = nil;
|
|
234
|
+
XCTAssertTrue([BGSRNReportOps addData:@"AQ==" name:@"blob" mimeType:@"application/octet-stream" toReport:_report error:&error]);
|
|
235
|
+
XCTAssertNil(error);
|
|
236
|
+
const uint8_t one = 1;
|
|
237
|
+
XCTAssertEqualObjects(_report.lastDataAttachment,
|
|
238
|
+
(@[ [NSData dataWithBytes:&one length:1], @"blob", @"application/octet-stream" ]));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/// Undecodable input never reaches the SDK.
|
|
242
|
+
- (void)testInvalidBase64IsABadArgument {
|
|
243
|
+
NSError *error = nil;
|
|
244
|
+
XCTAssertFalse([BGSRNReportOps addData:@"not base64!" name:@"blob" mimeType:nil toReport:_report error:&error]);
|
|
245
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
246
|
+
XCTAssertEqualObjects(BGSRNReportErrorWireCode(error), @"E_REPORT_BAD_ARGUMENT");
|
|
247
|
+
XCTAssertNil(_report.lastDataAttachment);
|
|
248
|
+
XCTAssertEqualObjects(_report.mutations, @[]);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
- (void)testFileAttachmentPassesMoveThrough {
|
|
252
|
+
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:
|
|
253
|
+
[NSString stringWithFormat:@"bugsee-rn-%@.log", NSUUID.UUID.UUIDString]];
|
|
254
|
+
XCTAssertTrue([@"log" writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil]);
|
|
255
|
+
[self addTeardownBlock:^{
|
|
256
|
+
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
257
|
+
}];
|
|
258
|
+
|
|
259
|
+
NSError *error = nil;
|
|
260
|
+
XCTAssertTrue([BGSRNReportOps addFileAtPath:path name:@"app.log" mimeType:@"text/plain" move:YES toReport:_report error:&error]);
|
|
261
|
+
XCTAssertEqualObjects(_report.lastFileAttachment, (@[ path, @"app.log", @"text/plain", @YES ]));
|
|
262
|
+
|
|
263
|
+
XCTAssertTrue([BGSRNReportOps addFileAtPath:path name:@"app.log" mimeType:nil move:NO toReport:_report error:&error]);
|
|
264
|
+
XCTAssertEqualObjects(_report.lastFileAttachment, (@[ path, @"app.log", NSNull.null, @NO ]));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
- (void)testWireCodeIsNilForAForeignError {
|
|
268
|
+
XCTAssertNil(BGSRNReportErrorWireCode([NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:nil]));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#pragma mark - Messages
|
|
272
|
+
|
|
273
|
+
/// A developer-chosen identifier is named; the value never is.
|
|
274
|
+
- (void)testAnUnknownKeyAndABadAttributeAreNamed {
|
|
275
|
+
NSError *error = nil;
|
|
276
|
+
XCTAssertFalse([BGSRNReportOps applyPatch:@{ @"summray" : @"s3cret" } toReport:_report error:&error]);
|
|
277
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error), @"update() received an unknown key \"summray\"");
|
|
278
|
+
error = nil;
|
|
279
|
+
XCTAssertFalse([BGSRNReportOps applyPatch:@{ @"attributes" : @{ @"plan" : @[ @"s3cret" ] } }
|
|
280
|
+
toReport:_report
|
|
281
|
+
error:&error]);
|
|
282
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error),
|
|
283
|
+
@"attribute \"plan\" must be a string, boolean, finite number or null");
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/// Through the real call path: the rejection says the text is malformed and
|
|
287
|
+
/// never repeats it. The same wording as Android's `ReportOps.applyJson`.
|
|
288
|
+
- (void)testApplyPatchJSONRejectsMalformedTextWithoutEchoingIt {
|
|
289
|
+
NSError *error = nil;
|
|
290
|
+
XCTAssertFalse([BGSRNReportOps applyPatchJSON:@"{\"summary\": \"s3cret-do-not-leak" toReport:_report error:&error]);
|
|
291
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
292
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error), @"update() patch is not a JSON object: malformed JSON");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
@end
|