@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.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +552 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +944 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,548 @@
1
+ @import XCTest;
2
+ @import UIKit;
3
+ @import BugseeRNSupport;
4
+
5
+ /// Stands in for `RCTSurfaceHostingView`; the module's predicate matches the
6
+ /// real class by name.
7
+ @interface BGSRNFakeReactRoot : UIView
8
+ @end
9
+
10
+ @implementation BGSRNFakeReactRoot
11
+ @end
12
+
13
+ /// Stands in for `RCTModalHostViewComponentView`; the module's predicate
14
+ /// matches the real class by name.
15
+ @interface BGSRNFakeModalHost : UIView
16
+ /// What `RCTModalHostViewComponentView` presents its content in.
17
+ @property (nonatomic, strong, nullable) UIViewController *viewController;
18
+ @end
19
+
20
+ @implementation BGSRNFakeModalHost
21
+ @end
22
+
23
+ /// The `vh` origin must put the React tree where the SDK places its native
24
+ /// nodes -- on iOS on the screen, through the screen's fixed space
25
+ /// (`+[BGSTrackerApplication screenRectForRect:inView:]`) -- so the two trees
26
+ /// share one space by construction.
27
+ @interface BGSRNReactWindowTests : XCTestCase
28
+ @end
29
+
30
+ @implementation BGSRNReactWindowTests {
31
+ BOOL (^_isReactRoot)(UIView *);
32
+ }
33
+
34
+ - (void)setUp {
35
+ [super setUp];
36
+ _isReactRoot = ^BOOL(UIView *view) {
37
+ return [view isKindOfClass:BGSRNFakeReactRoot.class];
38
+ };
39
+ }
40
+
41
+ - (UIWindow *)windowAt:(CGRect)frame hostingAtDepth:(NSUInteger)depth {
42
+ UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
43
+ if (depth == NSNotFound) {
44
+ [window addSubview:[UIView new]];
45
+ return window;
46
+ }
47
+ UIView *parent = window;
48
+ for (NSUInteger i = 0; i < depth; i++) {
49
+ UIView *child = [UIView new];
50
+ [parent addSubview:child];
51
+ parent = child;
52
+ }
53
+ [parent addSubview:[BGSRNFakeReactRoot new]];
54
+ return window;
55
+ }
56
+
57
+ /// The SDK's placement of `rect` in `view` on iOS, as
58
+ /// `+[BGSTrackerApplication screenRectForRect:inView:]` computes it.
59
+ - (CGRect)sdkScreenRectForRect:(CGRect)rect inView:(UIView *)view {
60
+ UIWindow *window = [view isKindOfClass:UIWindow.class] ? (UIWindow *)view : view.window;
61
+ UIScreen *screen = window.windowScene.screen;
62
+ id<UICoordinateSpace> fixedSpace = screen.fixedCoordinateSpace;
63
+ return [fixedSpace convertRect:[view convertRect:rect toCoordinateSpace:fixedSpace]
64
+ toCoordinateSpace:screen.coordinateSpace];
65
+ }
66
+
67
+ - (void)skipWithoutAScreenFor:(UIWindow *)window {
68
+ if (window.windowScene.screen == nil) {
69
+ XCTSkip(@"The test runner put the window on no screen");
70
+ }
71
+ }
72
+
73
+ - (void)testTheOriginIsWhereTheHostingWindowStartsOnTheScreen {
74
+ UIWindow *key = [self windowAt:CGRectMake(0, 0, 390, 844) hostingAtDepth:NSNotFound];
75
+ UIWindow *hosting = [self windowAt:CGRectMake(120.5, 64, 300, 400) hostingAtDepth:3];
76
+ [self skipWithoutAScreenFor:hosting];
77
+
78
+ NSValue *origin = BGSRNReactRootOrigin(key, @[ key, hosting ], _isReactRoot);
79
+
80
+ XCTAssertEqualObjects(origin, BGSRNWindowRecordedOrigin(hosting));
81
+ XCTAssertTrue(CGPointEqualToPoint(origin.CGPointValue,
82
+ [self sdkScreenRectForRect:hosting.bounds inView:hosting].origin));
83
+ }
84
+
85
+ /// What JS computes (`measureInWindow` + origin) is what the SDK computes for
86
+ /// the same view (its rect on the screen).
87
+ - (void)testANodePlusTheOriginLandsWhereTheSdkPutsIt {
88
+ UIWindow *window = [self windowAt:CGRectMake(40, 30, 300, 400) hostingAtDepth:0];
89
+ [self skipWithoutAScreenFor:window];
90
+ UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 200, 200)];
91
+ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(5, 7, 50, 60)];
92
+ [container addSubview:view];
93
+ [window addSubview:container];
94
+
95
+ const CGPoint origin = BGSRNReactRootOrigin(window, @[ window ], _isReactRoot).CGPointValue;
96
+ const CGRect inWindow = [view convertRect:view.bounds toView:nil];
97
+ const CGRect sdk = [self sdkScreenRectForRect:view.frame inView:view.superview];
98
+
99
+ XCTAssertEqualWithAccuracy(inWindow.origin.x + origin.x, sdk.origin.x, 0.001);
100
+ XCTAssertEqualWithAccuracy(inWindow.origin.y + origin.y, sdk.origin.y, 0.001);
101
+ }
102
+
103
+ - (void)testAHostingWindowOnNoScreenIsNoOrigin {
104
+ UIWindow *window = [self windowAt:CGRectMake(40, 30, 300, 400) hostingAtDepth:0];
105
+ window.windowScene = nil;
106
+
107
+ XCTAssertNil(BGSRNReactRootOrigin(window, @[ window ], _isReactRoot));
108
+ }
109
+
110
+ - (void)testTheKeyWindowIsPreferredWhenSeveralHost {
111
+ UIWindow *other = [self windowAt:CGRectMake(1, 2, 10, 10) hostingAtDepth:0];
112
+ UIWindow *key = [self windowAt:CGRectMake(3, 4, 10, 10) hostingAtDepth:0];
113
+
114
+ XCTAssertEqual(BGSRNWindowHostingReactRoot(key, @[ other, key ], _isReactRoot, BGSRNReactRootSearchBudget), key);
115
+ }
116
+
117
+ /// The SDK walks the key window even when its scene list lacks it.
118
+ - (void)testTheKeyWindowIsSearchedEvenIfNotInTheList {
119
+ UIWindow *key = [self windowAt:CGRectMake(3, 4, 10, 10) hostingAtDepth:1];
120
+
121
+ XCTAssertEqual(BGSRNWindowHostingReactRoot(key, @[], _isReactRoot, BGSRNReactRootSearchBudget), key);
122
+ }
123
+
124
+ - (void)testNoHostingWindowIsNoOrigin {
125
+ UIWindow *key = [self windowAt:CGRectMake(0, 0, 10, 10) hostingAtDepth:NSNotFound];
126
+
127
+ XCTAssertNil(BGSRNReactRootOrigin(key, @[ key ], _isReactRoot));
128
+ XCTAssertNil(BGSRNReactRootOrigin(nil, @[], _isReactRoot));
129
+ }
130
+
131
+ - (void)testTheSearchIsBoundedPerWindow {
132
+ UIWindow *deep = [self windowAt:CGRectMake(0, 0, 10, 10) hostingAtDepth:5];
133
+
134
+ // The window, 5 plain views, then the root: the 7th view inspected.
135
+ XCTAssertNil(BGSRNWindowHostingReactRoot(deep, @[], _isReactRoot, 6));
136
+ XCTAssertEqual(BGSRNWindowHostingReactRoot(deep, @[], _isReactRoot, 7), deep);
137
+ }
138
+
139
+ - (void)testTheSdkWalkedWindowsAreEmptyWithoutAKeyWindow {
140
+ XCTAssertEqualObjects(BGSRNSdkWalkedWindows(nil), @[]);
141
+ }
142
+
143
+ #pragma mark - The <Modal> host by React tag (PR 48)
144
+
145
+ /// The window placement the Modal origins take, as the module passes
146
+ /// `BGSRNWindowRecordedOrigin`. The test runner's windows are on no screen,
147
+ /// where that has no place, so these tests place a window at its
148
+ /// `frame.origin`; `testAModalOriginAddsTheWindowsPlacement` checks the term.
149
+ - (NSValue *_Nullable (^)(UIWindow *))frameOrigin {
150
+ return ^NSValue *_Nullable(UIWindow *window) {
151
+ return [NSValue valueWithCGPoint:window.frame.origin];
152
+ };
153
+ }
154
+
155
+
156
+ - (BOOL (^)(UIView *))isModalHost {
157
+ return ^BOOL(UIView *view) {
158
+ return [view isKindOfClass:BGSRNFakeModalHost.class];
159
+ };
160
+ }
161
+
162
+ /// A native view with the host's tag, earlier in the same window, is what
163
+ /// `viewWithTag:` returns; the walk must keep going and find the host.
164
+ - (void)testANativeViewWithTheSameTagBeforeTheHostStillFindsTheHost {
165
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
166
+ UIView *dummy = [UIView new];
167
+ dummy.tag = 42;
168
+ [window addSubview:dummy];
169
+ UIView *container = [UIView new];
170
+ [window addSubview:container];
171
+ BGSRNFakeModalHost *host = [BGSRNFakeModalHost new];
172
+ host.tag = 42;
173
+ [container addSubview:host];
174
+ XCTAssertEqual([window viewWithTag:42], dummy, @"the fixture must put the dummy first");
175
+
176
+ UIView *found = BGSRNUniqueTaggedView(@[ window ], 42, [self isModalHost], BGSRNModalHostSearchBudget);
177
+
178
+ XCTAssertEqual(found, host);
179
+ }
180
+
181
+ /// Same when the dummy is the host's own ancestor.
182
+ - (void)testAnAncestorWithTheSameTagStillFindsTheHost {
183
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
184
+ UIView *dummy = [UIView new];
185
+ dummy.tag = 7;
186
+ [window addSubview:dummy];
187
+ BGSRNFakeModalHost *host = [BGSRNFakeModalHost new];
188
+ host.tag = 7;
189
+ [dummy addSubview:host];
190
+
191
+ XCTAssertEqual(BGSRNUniqueTaggedView(@[ window ], 7, [self isModalHost], BGSRNModalHostSearchBudget), host);
192
+ }
193
+
194
+ /// A wrong-class match in one window does not stop the search of the next.
195
+ - (void)testAWrongClassMatchInOneWindowStillSearchesTheNext {
196
+ UIWindow *first = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
197
+ UIView *dummy = [UIView new];
198
+ dummy.tag = 42;
199
+ [first addSubview:dummy];
200
+ UIWindow *second = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
201
+ BGSRNFakeModalHost *host = [BGSRNFakeModalHost new];
202
+ host.tag = 42;
203
+ [second addSubview:host];
204
+
205
+ XCTAssertEqual(BGSRNUniqueTaggedView(@[ first, second ], 42, [self isModalHost], BGSRNModalHostSearchBudget), host);
206
+ }
207
+
208
+ /// The class alone is not enough: another Modal's host has another tag.
209
+ - (void)testAHostWithAnotherTagIsNotAMatch {
210
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
211
+ BGSRNFakeModalHost *other = [BGSRNFakeModalHost new];
212
+ other.tag = 43;
213
+ [window addSubview:other];
214
+ UIView *dummy = [UIView new];
215
+ dummy.tag = 42;
216
+ [window addSubview:dummy];
217
+
218
+ XCTAssertNil(BGSRNUniqueTaggedView(@[ window ], 42, [self isModalHost], BGSRNModalHostSearchBudget));
219
+ }
220
+
221
+ - (void)testTheTaggedSearchIsBoundedPerWindow {
222
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
223
+ UIView *parent = window;
224
+ for (NSUInteger i = 0; i < 5; i++) {
225
+ UIView *child = [UIView new];
226
+ [parent addSubview:child];
227
+ parent = child;
228
+ }
229
+ BGSRNFakeModalHost *host = [BGSRNFakeModalHost new];
230
+ host.tag = 42;
231
+ [parent addSubview:host];
232
+
233
+ // The window, five levels, then the host: the seventh view visited.
234
+ XCTAssertNil(BGSRNUniqueTaggedView(@[ window ], 42, [self isModalHost], 6));
235
+ XCTAssertEqual(BGSRNUniqueTaggedView(@[ window ], 42, [self isModalHost], 7), host);
236
+ }
237
+
238
+ #pragma mark - Which host places a <Modal> lane (PR 48, round 2)
239
+
240
+ /// A host with `tag`, presenting its content at `contentFrame` inside
241
+ /// `window` when `presentedIn` is non-nil (a stand-in for a presented view
242
+ /// controller: its view is in a window), not presented otherwise.
243
+ - (BGSRNFakeModalHost *)hostTagged:(NSInteger)tag
244
+ inWindow:(UIWindow *)window
245
+ presentedIn:(nullable UIWindow *)presentedIn
246
+ contentFrame:(CGRect)contentFrame {
247
+ BGSRNFakeModalHost *host = [BGSRNFakeModalHost new];
248
+ host.tag = tag;
249
+ [window addSubview:host];
250
+ UIViewController *controller = [UIViewController new];
251
+ controller.view.frame = contentFrame;
252
+ if (presentedIn != nil) {
253
+ [presentedIn addSubview:controller.view];
254
+ }
255
+ host.viewController = controller;
256
+ return host;
257
+ }
258
+
259
+ - (BGSRNSecureRectangles *)storeWithLaneOn:(NSInteger)surface claim:(NSInteger *)claim {
260
+ BGSRNSecureRectangles *store = [[BGSRNSecureRectangles alloc] init];
261
+ const NSInteger current = [store claimRuntime];
262
+ const int32_t rects[] = {1, 2, 3, 4};
263
+ XCTAssertTrue([store setCoordinates:rects count:4 forDisplay:0 surface:surface runtime:current]);
264
+ if (claim != NULL) {
265
+ *claim = current;
266
+ }
267
+ return store;
268
+ }
269
+
270
+ - (void)testTheHostOriginIsThePresentedContentInItsWindowPlusTheWindowsOrigin {
271
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(10, 20, 390, 844)];
272
+ BGSRNFakeModalHost *host = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 60, 390, 784)];
273
+
274
+ XCTAssertEqualObjects(BGSRNModalHostOrigin(host, [self frameOrigin]), [NSValue valueWithCGPoint:CGPointMake(10, 80)]);
275
+ }
276
+
277
+ /// The window's term is the placement the module passes: the window's place
278
+ /// on its screen (`BGSRNWindowRecordedOrigin`), the main surface's convention,
279
+ /// not `frame.origin`, which is {0, 0} for a Stage Manager window or the
280
+ /// right-hand one side by side.
281
+ - (void)testAModalOriginAddsTheWindowsPlacement {
282
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(10, 20, 390, 844)];
283
+ BGSRNFakeModalHost *host = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 60, 390, 784)];
284
+ NSValue *_Nullable (^onTheScreen)(UIWindow *) = ^NSValue *_Nullable(UIWindow *placed) {
285
+ return placed == window ? [NSValue valueWithCGPoint:CGPointMake(300, 40)] : nil;
286
+ };
287
+
288
+ XCTAssertEqualObjects(BGSRNModalHostOrigin(host, onTheScreen), [NSValue valueWithCGPoint:CGPointMake(300, 100)]);
289
+ }
290
+
291
+ /// A window with no place (on no screen) gives the Modal no origin: its lane
292
+ /// keeps the origin it had, unknown for a new one, rather than a guess.
293
+ - (void)testAModalInAWindowWithNoPlacementHasNoOrigin {
294
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(10, 20, 390, 844)];
295
+ BGSRNFakeModalHost *host = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 60, 390, 784)];
296
+
297
+ XCTAssertNil(BGSRNModalHostOrigin(host, ^NSValue *_Nullable(UIWindow *placed) {
298
+ return nil;
299
+ }));
300
+ }
301
+
302
+ - (void)testAHostWhoseContentHasNoWindowHasNoOrigin {
303
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
304
+ BGSRNFakeModalHost *host = [self hostTagged:42 inWindow:window presentedIn:nil contentFrame:CGRectMake(0, 60, 390, 784)];
305
+
306
+ XCTAssertNil(BGSRNModalHostOrigin(host, [self frameOrigin]));
307
+ XCTAssertNil(BGSRNModalHostOrigin([UIView new], [self frameOrigin]));
308
+ }
309
+
310
+ /// What a module's view registry answers: `host` for `tag`, nothing else.
311
+ - (BGSRNSecureHostResolver)registryWith:(UIView *)host calls:(NSUInteger *)calls {
312
+ __weak UIView *weakHost = host;
313
+ return ^id _Nullable(NSInteger tag) {
314
+ if (calls != NULL) {
315
+ *calls += 1;
316
+ }
317
+ return tag == weakHost.tag ? weakHost : nil;
318
+ };
319
+ }
320
+
321
+ /// Two hosts with tag 42, only the second presented and the current
322
+ /// runtime's: the origin comes from the second, though the walk meets the
323
+ /// first one first.
324
+ - (void)testTheOriginComesFromTheCurrentRuntimesHost {
325
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
326
+ [self hostTagged:42 inWindow:window presentedIn:nil contentFrame:CGRectMake(0, 300, 390, 544)];
327
+ BGSRNFakeModalHost *current = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 60, 390, 784)];
328
+ NSInteger claim = 0;
329
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:&claim];
330
+ XCTAssertTrue([store setHostResolver:[self registryWith:current calls:NULL] forSurface:42 runtime:claim]);
331
+
332
+ NSValue *origin = BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]);
333
+
334
+ XCTAssertEqualObjects(origin, [NSValue valueWithCGPoint:CGPointMake(0, 60)]);
335
+ }
336
+
337
+ /// The host is mounted after the publish that names it: the lookup is asked
338
+ /// on each pull until it finds the host, which is then held, not looked up
339
+ /// again.
340
+ - (void)testTheLookupIsAskedUntilTheHostIsMountedThenTheHostIsHeld {
341
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
342
+ NSInteger claim = 0;
343
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:&claim];
344
+ __block UIView *mounted = nil;
345
+ __block NSUInteger calls = 0;
346
+ [store setHostResolver:^id _Nullable(NSInteger tag) {
347
+ calls += 1;
348
+ return mounted;
349
+ }
350
+ forSurface:42
351
+ runtime:claim];
352
+
353
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
354
+ XCTAssertEqual(calls, 1u);
355
+
356
+ mounted = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 60, 390, 784)];
357
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
358
+ [NSValue valueWithCGPoint:CGPointMake(0, 60)]);
359
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
360
+ [NSValue valueWithCGPoint:CGPointMake(0, 60)]);
361
+ XCTAssertEqual(calls, 2u);
362
+ }
363
+
364
+ /// What the registry answers must be a Modal host with the surface's tag.
365
+ - (void)testALookupAnswerThatIsNotAModalHostIsNotUsed {
366
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
367
+ UIView *plain = [UIView new];
368
+ plain.tag = 42;
369
+ [window addSubview:plain];
370
+ NSInteger claim = 0;
371
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:&claim];
372
+ [store setHostResolver:^id _Nullable(NSInteger tag) {
373
+ return plain;
374
+ }
375
+ forSurface:42
376
+ runtime:claim];
377
+
378
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
379
+ XCTAssertNil([store hostForSurface:42 accepting:^BOOL(id candidate) { return NO; }]);
380
+ }
381
+
382
+ /// A reload with a sheet up: after the new runtime claims, the old host's
383
+ /// origin is never used, though it is still presented with the same tag.
384
+ - (void)testAfterAClaimTheOldHostsOriginIsNeverUsed {
385
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
386
+ BGSRNFakeModalHost *old = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 300, 390, 544)];
387
+ NSInteger oldClaim = 0;
388
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:&oldClaim];
389
+ XCTAssertTrue([store setHostResolver:[self registryWith:old calls:NULL] forSurface:42 runtime:oldClaim]);
390
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
391
+ [NSValue valueWithCGPoint:CGPointMake(0, 300)]);
392
+
393
+ const NSInteger current = [store claimRuntime];
394
+ XCTAssertNil([store hostForSurface:42 accepting:^BOOL(id candidate) { return YES; }],
395
+ @"a claim forgets every host and lookup");
396
+ const int32_t rects[] = {1, 2, 3, 4};
397
+ [store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:current];
398
+ BGSRNFakeModalHost *fresh = [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 0, 390, 844)];
399
+
400
+ // Before the new module names its host: two matches, so no origin.
401
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
402
+ // The old module's late naming is stale.
403
+ XCTAssertFalse([store setHostResolver:[self registryWith:old calls:NULL] forSurface:42 runtime:oldClaim]);
404
+ XCTAssertFalse([store setHost:old forSurface:42 runtime:oldClaim]);
405
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
406
+ // The new module's lookup places the lane by its own host.
407
+ XCTAssertTrue([store setHostResolver:[self registryWith:fresh calls:NULL] forSurface:42 runtime:current]);
408
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
409
+ [NSValue valueWithCGPoint:CGPointZero]);
410
+ }
411
+
412
+ /// The fallback walk cannot tell two hosts with one tag apart: no origin,
413
+ /// even when only one is presented.
414
+ - (void)testTwoWalkMatchesGiveNoOrigin {
415
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
416
+ [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 300, 390, 544)];
417
+ UIWindow *other = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
418
+ [self hostTagged:42 inWindow:other presentedIn:nil contentFrame:CGRectMake(0, 60, 390, 784)];
419
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:NULL];
420
+
421
+ XCTAssertNil(BGSRNUniqueTaggedView(@[ window, other ], 42, [self isModalHost], BGSRNModalHostSearchBudget));
422
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window, other ], [self isModalHost], [self frameOrigin]));
423
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
424
+ [NSValue valueWithCGPoint:CGPointMake(0, 300)]);
425
+ }
426
+
427
+ /// The one walk match whose content has no window gives no origin.
428
+ - (void)testAWalkMatchThatIsNotPresentedGivesNoOrigin {
429
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
430
+ [self hostTagged:42 inWindow:window presentedIn:nil contentFrame:CGRectMake(0, 60, 390, 784)];
431
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:NULL];
432
+
433
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
434
+ }
435
+
436
+ /// A held host that has gone is looked up again; the lookup not finding it
437
+ /// leaves the origin unknown, not a search that could find another host.
438
+ - (void)testAGoneHostTheLookupCannotFindGivesNoOrigin {
439
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
440
+ [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 300, 390, 544)];
441
+ NSInteger claim = 0;
442
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:&claim];
443
+ __block NSUInteger calls = 0;
444
+ @autoreleasepool {
445
+ BGSRNFakeModalHost *gone = [BGSRNFakeModalHost new];
446
+ gone.tag = 42;
447
+ XCTAssertTrue([store setHost:gone forSurface:42 runtime:claim]);
448
+ [store setHostResolver:^id _Nullable(NSInteger tag) {
449
+ calls += 1;
450
+ return nil;
451
+ }
452
+ forSurface:42
453
+ runtime:claim];
454
+ }
455
+
456
+ XCTAssertNil(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]));
457
+ XCTAssertEqual(calls, 1u);
458
+ }
459
+
460
+ /// A reload with a sheet up, before the new runtime's Modal has mounted: the
461
+ /// old runtime's presented host is the only one with tag 42, and the new
462
+ /// runtime has named its lookup, which finds nothing yet. The old host's
463
+ /// origin must not place the new lane: it stays unknown and is served as the
464
+ /// whole display.
465
+ - (void)testAnOldHostAloneWhileTheNewHostIsNotMountedGivesNoOrigin {
466
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
467
+ [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 300, 390, 544)];
468
+ BGSRNSecureRectangles *store = [[BGSRNSecureRectangles alloc] init];
469
+ [store setDisplaySize:CGSizeMake(390, 844) forDisplay:0];
470
+ [store setOrigin:CGPointZero forDisplay:0];
471
+ [store claimRuntime];
472
+ const NSInteger current = [store claimRuntime];
473
+ const int32_t rects[] = {10, 20, 110, 120};
474
+ XCTAssertTrue([store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:current]);
475
+ XCTAssertTrue([store setHostResolver:^id _Nullable(NSInteger tag) {
476
+ return nil;
477
+ }
478
+ forSurface:42
479
+ runtime:current]);
480
+ XCTAssertNotNil(BGSRNUniqueTaggedView(@[ window ], 42, [self isModalHost], BGSRNModalHostSearchBudget),
481
+ @"the fixture's old host is the walk's one match");
482
+
483
+ NSValue *origin = BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]);
484
+
485
+ XCTAssertNil(origin);
486
+ // What the pull then serves: the lane's origin is still unknown.
487
+ NSData *snapshot = [store snapshotForDisplay:0];
488
+ int32_t served[6] = {0};
489
+ [snapshot getBytes:served length:sizeof(served)];
490
+ XCTAssertEqual(CFSwapInt32LittleToHost((uint32_t)served[1]), 1u);
491
+ XCTAssertEqual((int32_t)CFSwapInt32LittleToHost((uint32_t)served[2]), 0);
492
+ XCTAssertEqual((int32_t)CFSwapInt32LittleToHost((uint32_t)served[3]), 0);
493
+ XCTAssertEqual((int32_t)CFSwapInt32LittleToHost((uint32_t)served[4]), 390);
494
+ XCTAssertEqual((int32_t)CFSwapInt32LittleToHost((uint32_t)served[5]), 844);
495
+ }
496
+
497
+ /// With no lookup ever named (no registry), the walk's one presented match
498
+ /// places the lane.
499
+ - (void)testWithNoLookupNamedTheUniqueWalkPlacesTheLane {
500
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
501
+ [self hostTagged:42 inWindow:window presentedIn:window contentFrame:CGRectMake(0, 300, 390, 544)];
502
+ BGSRNSecureRectangles *store = [self storeWithLaneOn:42 claim:NULL];
503
+
504
+ XCTAssertFalse([store isHostNamedForSurface:42]);
505
+ XCTAssertEqualObjects(BGSRNSecureSurfaceOrigin(store, 42, @[ window ], [self isModalHost], [self frameOrigin]),
506
+ [NSValue valueWithCGPoint:CGPointMake(0, 300)]);
507
+ }
508
+
509
+ /// The tracker keeps the root view itself, so the search hands it back.
510
+ - (void)testTheSearchReturnsTheRootView {
511
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
512
+ UIView *container = [UIView new];
513
+ BGSRNFakeReactRoot *root = [BGSRNFakeReactRoot new];
514
+ [container addSubview:root];
515
+ [window addSubview:container];
516
+
517
+ XCTAssertEqual(BGSRNReactRootView(window, @[], _isReactRoot, BGSRNReactRootSearchBudget), root);
518
+ XCTAssertNil(BGSRNReactRootView(nil, @[], _isReactRoot, BGSRNReactRootSearchBudget));
519
+ }
520
+
521
+ /// A window that is not on a screen has no place on one; the tracker then
522
+ /// keeps the last origin rather than serve the rectangles at {0, 0}.
523
+ - (void)testAWindowOnNoScreenHasNoScreenOrigin {
524
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(37, 53, 100, 100)];
525
+ window.windowScene = nil;
526
+
527
+ XCTAssertNil(BGSRNWindowRecordedOrigin(window));
528
+ }
529
+
530
+ /// The test runner's scene fills its iPhone screen, so a window placed at
531
+ /// {37, 53} in it starts at {37, 53} on the screen. A window side by side or
532
+ /// in Stage Manager adds its scene's place, which only a device shows.
533
+ - (void)testAWindowStartsOnTheScreenWhereItSitsInAFullScreenScene {
534
+ UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(37, 53, 100, 100)];
535
+ UIWindowScene *scene = window.windowScene;
536
+ if (scene == nil
537
+ || !CGRectEqualToRect(scene.coordinateSpace.bounds, scene.screen.bounds)) {
538
+ XCTSkip(@"The test runner has no scene filling its screen");
539
+ }
540
+
541
+ NSValue *origin = BGSRNWindowRecordedOrigin(window);
542
+
543
+ XCTAssertNotNil(origin);
544
+ XCTAssertEqualWithAccuracy(origin.CGPointValue.x, 37, 0.5);
545
+ XCTAssertEqualWithAccuracy(origin.CGPointValue.y, 53, 0.5);
546
+ }
547
+
548
+ @end
@@ -0,0 +1,51 @@
1
+ @import XCTest;
2
+ @import Bugsee;
3
+ @import BugseeRNSupport;
4
+
5
+ /// Upload severity is the requested value when it is 1..5, otherwise the
6
+ /// launch option, otherwise High (3). A nil string array stays nil.
7
+ @interface BGSRNReportArgsTests : XCTestCase
8
+ @end
9
+
10
+ @implementation BGSRNReportArgsTests
11
+
12
+ - (void)testARequestedSeverityWins {
13
+ NSDictionary *options = @{BugseeOptionReportingDefaultBugPriority : @(BugseeSeverityLow)};
14
+ XCTAssertEqual(BGSRNUploadSeverity(BugseeSeverityCritical, options), BugseeSeverityCritical);
15
+ XCTAssertEqual(BGSRNUploadSeverity(BugseeSeverityLow, nil), BugseeSeverityLow);
16
+ XCTAssertEqual(BGSRNDefaultBugPriorityFallback, 3);
17
+ }
18
+
19
+ - (void)testZeroTakesTheLaunchOption {
20
+ NSDictionary *options =
21
+ @{BugseeOptionReportingDefaultBugPriority : @(BugseeSeverityCritical)};
22
+ XCTAssertEqual(BGSRNUploadSeverity(0, options), BugseeSeverityCritical);
23
+ }
24
+
25
+ - (void)testZeroWithoutTheOptionIsHigh {
26
+ XCTAssertEqual(BGSRNUploadSeverity(0, @{}), BugseeSeverityHigh);
27
+ XCTAssertEqual(BGSRNUploadSeverity(0, nil), BugseeSeverityHigh);
28
+ }
29
+
30
+ - (void)testAnOutOfRangeOptionIsHigh {
31
+ XCTAssertEqual(BGSRNUploadSeverity(0, @{BugseeOptionReportingDefaultBugPriority : @(6)}),
32
+ BugseeSeverityHigh);
33
+ XCTAssertEqual(BGSRNUploadSeverity(0, @{BugseeOptionReportingDefaultBugPriority : @(0)}),
34
+ BugseeSeverityHigh);
35
+ XCTAssertEqual(BGSRNUploadSeverity(0, @{BugseeOptionReportingDefaultBugPriority : @(2.5)}),
36
+ BugseeSeverityHigh);
37
+ XCTAssertEqual(BGSRNUploadSeverity(0, @{BugseeOptionReportingDefaultBugPriority : @"4"}),
38
+ BugseeSeverityHigh);
39
+ }
40
+
41
+ - (void)testStringArrayKeepsStrings {
42
+ NSArray *mixed = @[ @"a", @1, @"b" ];
43
+ XCTAssertEqualObjects(BGSRNStringArray(mixed), (@[ @"a", @"b" ]));
44
+ XCTAssertEqualObjects(BGSRNStringArray(@[ @"only" ]), (@[ @"only" ]));
45
+ }
46
+
47
+ - (void)testStringArrayOfNilIsNil {
48
+ XCTAssertNil(BGSRNStringArray(nil));
49
+ }
50
+
51
+ @end
@@ -0,0 +1,22 @@
1
+ @import XCTest;
2
+ @import BugseeRNSupport;
3
+
4
+ /// The deadline JS gets for a handle must land inside the SDK's cap for the
5
+ /// path it is on. Overshooting is not a softer failure: the SDK proceeds
6
+ /// without us, and whatever JS writes after that goes to a report that has
7
+ /// already moved on.
8
+ @interface BGSRNReportDeadlinesTests : XCTestCase
9
+ @end
10
+
11
+ @implementation BGSRNReportDeadlinesTests
12
+
13
+ /// Live reports are dispatched on main with a 30 s per-handler cap; recovered
14
+ /// ones off main with a 3 s cap. Each deadline stops short of its cap.
15
+ - (void)testMainThreadIsLiveAndOffMainIsRecovery {
16
+ XCTAssertEqual(BGSRNLiveDeadlineMs, 25000);
17
+ XCTAssertEqual(BGSRNRecoveryDeadlineMs, 2500);
18
+ XCTAssertEqual(BGSRNDeadlineMs(YES), 25000);
19
+ XCTAssertEqual(BGSRNDeadlineMs(NO), 2500);
20
+ }
21
+
22
+ @end