@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,568 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import BugseeRNSupport;
|
|
3
|
+
|
|
4
|
+
/// The SDK PULLS this buffer once per captured frame — on iOS from the MAIN
|
|
5
|
+
/// thread — and re-reads the rectangles only when the version differs from the
|
|
6
|
+
/// one it saw last. Two properties follow, and both are load-bearing:
|
|
7
|
+
///
|
|
8
|
+
/// * a change MUST move the version, or the SDK goes on redacting the region
|
|
9
|
+
/// the app has stopped considering secret and, worse, records a newly
|
|
10
|
+
/// secret one in the clear until something else moves the version;
|
|
11
|
+
/// * a no-op write must NOT move it, or the SDK re-reads on every frame.
|
|
12
|
+
@interface BGSRNSecureRectanglesTests : XCTestCase
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@implementation BGSRNSecureRectanglesTests {
|
|
16
|
+
BGSRNSecureRectangles *_store;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (void)setUp {
|
|
20
|
+
[super setUp];
|
|
21
|
+
_store = [[BGSRNSecureRectangles alloc] init];
|
|
22
|
+
// The main surface's origin read, as the first pull does: every test about
|
|
23
|
+
// publishing and versions starts here. The fail-closed tests use a bare
|
|
24
|
+
// store.
|
|
25
|
+
[_store setOrigin:CGPointZero forDisplay:0];
|
|
26
|
+
[_store setOrigin:CGPointZero forDisplay:1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Reads the buffer as the SDK does: little-endian int32, `[version, count, …]`.
|
|
30
|
+
- (NSArray<NSNumber *> *)unpack:(NSData *)data {
|
|
31
|
+
XCTAssertEqual(data.length % sizeof(int32_t), 0u,
|
|
32
|
+
@"the buffer must be a whole number of int32s");
|
|
33
|
+
NSMutableArray *out = [NSMutableArray array];
|
|
34
|
+
const NSUInteger count = data.length / sizeof(int32_t);
|
|
35
|
+
for (NSUInteger i = 0; i < count; i++) {
|
|
36
|
+
int32_t value = 0;
|
|
37
|
+
[data getBytes:&value range:NSMakeRange(i * sizeof(int32_t), sizeof(int32_t))];
|
|
38
|
+
[out addObject:@(CFSwapInt32LittleToHost((uint32_t)value))];
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)testPublishesAnEmptySetBeforeAnythingIsSecured {
|
|
44
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
45
|
+
XCTAssertEqual(packed.count, 2u);
|
|
46
|
+
XCTAssertEqualObjects(packed[1], @0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (void)testPacksVersionCountThenEachRectangle {
|
|
50
|
+
const int32_t rects[] = {1, 2, 3, 4, 10, 20, 30, 40};
|
|
51
|
+
[_store setCoordinates:rects count:8 forDisplay:0];
|
|
52
|
+
|
|
53
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
54
|
+
XCTAssertEqualObjects(packed[1], @2);
|
|
55
|
+
XCTAssertEqualObjects([packed subarrayWithRange:NSMakeRange(2, 8)],
|
|
56
|
+
(@[@1, @2, @3, @4, @10, @20, @30, @40]));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Not a tautology: the SDK reads raw int32s, so a host-endian write on a
|
|
60
|
+
/// big-endian host would be read byte-reversed and redact nowhere near the
|
|
61
|
+
/// intended region.
|
|
62
|
+
- (void)testEncodesCoordinatesLittleEndian {
|
|
63
|
+
const int32_t rects[] = {0x01020304, 0, 0, 0};
|
|
64
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
65
|
+
|
|
66
|
+
NSData *data = [_store snapshotForDisplay:0];
|
|
67
|
+
uint8_t bytes[4] = {0};
|
|
68
|
+
[data getBytes:bytes range:NSMakeRange(2 * sizeof(int32_t), 4)];
|
|
69
|
+
XCTAssertEqual(bytes[0], 0x04);
|
|
70
|
+
XCTAssertEqual(bytes[3], 0x01);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
- (void)testMovesTheVersionWhenTheRectanglesChange {
|
|
74
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
75
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
76
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
77
|
+
|
|
78
|
+
XCTAssertNotEqualObjects(before, [self unpack:[_store snapshotForDisplay:0]][0]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (void)testHoldsTheVersionWhenNothingChanges {
|
|
82
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
83
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
84
|
+
NSNumber *settled = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
85
|
+
|
|
86
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
87
|
+
|
|
88
|
+
XCTAssertEqualObjects(settled, [self unpack:[_store snapshotForDisplay:0]][0]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// The dangerous case: same COUNT, different coordinates. A version keyed on
|
|
92
|
+
/// the number of rectangles would hold here.
|
|
93
|
+
- (void)testMovesTheVersionWhenOnlyTheCoordinatesChange {
|
|
94
|
+
const int32_t first[] = {1, 2, 3, 4};
|
|
95
|
+
[_store setCoordinates:first count:4 forDisplay:0];
|
|
96
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
97
|
+
|
|
98
|
+
const int32_t second[] = {9, 2, 3, 4};
|
|
99
|
+
[_store setCoordinates:second count:4 forDisplay:0];
|
|
100
|
+
|
|
101
|
+
XCTAssertNotEqualObjects(before, [self unpack:[_store snapshotForDisplay:0]][0]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
- (void)testMovesTheVersionWhenTheLastRectangleIsRemoved {
|
|
105
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
106
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
107
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
108
|
+
|
|
109
|
+
[_store setCoordinates:NULL count:0 forDisplay:0];
|
|
110
|
+
|
|
111
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
112
|
+
XCTAssertNotEqualObjects(before, packed[0]);
|
|
113
|
+
XCTAssertEqualObjects(packed[1], @0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// The freshness clock is per display, so one screen cannot stale another.
|
|
117
|
+
- (void)testVersionsEachDisplayIndependently {
|
|
118
|
+
NSNumber *otherBefore = [self unpack:[_store snapshotForDisplay:1]][0];
|
|
119
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
120
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
121
|
+
|
|
122
|
+
NSArray *other = [self unpack:[_store snapshotForDisplay:1]];
|
|
123
|
+
XCTAssertEqualObjects(otherBefore, other[0]);
|
|
124
|
+
XCTAssertEqualObjects(other[1], @0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// An immutable NSData per pull. The SDK's header is explicit that a buffer
|
|
128
|
+
/// rewritten from another thread while it reads is a use-after-free, and our
|
|
129
|
+
/// writes arrive from the JS thread while the pull is on the main one.
|
|
130
|
+
- (void)testHandsOutASnapshotThatCannotAliasTheStore {
|
|
131
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
132
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
133
|
+
|
|
134
|
+
NSData *first = [_store snapshotForDisplay:0];
|
|
135
|
+
const int32_t changed[] = {7, 8, 9, 10};
|
|
136
|
+
[_store setCoordinates:changed count:4 forDisplay:0];
|
|
137
|
+
|
|
138
|
+
XCTAssertEqualObjects([self unpack:first][2], @1,
|
|
139
|
+
@"a snapshot already handed out must not change underneath its reader");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// Four coordinates per rectangle. A truncated tail would be packed as a
|
|
143
|
+
/// rectangle with garbage coordinates, redacting somewhere arbitrary.
|
|
144
|
+
- (void)testIgnoresACoordinateListThatIsNotWholeRectangles {
|
|
145
|
+
const int32_t rects[] = {1, 2, 3};
|
|
146
|
+
XCTAssertFalse([_store setCoordinates:rects count:3 forDisplay:0]);
|
|
147
|
+
|
|
148
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
149
|
+
XCTAssertEqualObjects(packed[1], @0, @"a rejected write must not publish anything");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// An origin-only write that leaves the served buffer empty must keep the
|
|
153
|
+
/// snapshot at the empty-set version (1), not message-nil's 0. Android's
|
|
154
|
+
/// empty snapshot stays at version 1 the same way.
|
|
155
|
+
- (void)testAnOriginOnlyWriteThatLeavesServedEmptyKeepsVersionOne {
|
|
156
|
+
[_store setOrigin:CGPointMake(0, 96) forDisplay:0];
|
|
157
|
+
|
|
158
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
159
|
+
XCTAssertEqualObjects(packed[0], @1,
|
|
160
|
+
@"origin-only with no rectangles must not report version 0");
|
|
161
|
+
XCTAssertEqualObjects(packed[1], @0);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// The main origin must not move another surface's rectangle, and that
|
|
165
|
+
/// surface's own origin must.
|
|
166
|
+
- (void)testTheMainOriginDoesNotMoveAnotherSurfacesRectangle {
|
|
167
|
+
const int32_t mainRects[] = {10, 20, 30, 40};
|
|
168
|
+
const int32_t modalRects[] = {100, 200, 150, 250};
|
|
169
|
+
[_store setCoordinates:mainRects count:4 forDisplay:0 surface:BGSRNSecureMainSurface];
|
|
170
|
+
[_store setCoordinates:modalRects count:4 forDisplay:0 surface:42];
|
|
171
|
+
[_store setOrigin:CGPointMake(0, 96) forDisplay:0 surface:BGSRNSecureMainSurface];
|
|
172
|
+
[_store setOrigin:CGPointMake(0, 0) forDisplay:0 surface:42];
|
|
173
|
+
|
|
174
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
175
|
+
XCTAssertEqualObjects(packed[1], @2);
|
|
176
|
+
XCTAssertEqualObjects([packed subarrayWithRange:NSMakeRange(2, 8)],
|
|
177
|
+
(@[ @10, @116, @30, @136, @100, @200, @150, @250 ]));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
- (void)testAnotherSurfacesOwnOriginMovesOnlyItsRectangle {
|
|
181
|
+
const int32_t mainRects[] = {10, 20, 30, 40};
|
|
182
|
+
const int32_t modalRects[] = {100, 200, 150, 250};
|
|
183
|
+
[_store setCoordinates:mainRects count:4 forDisplay:0 surface:BGSRNSecureMainSurface];
|
|
184
|
+
[_store setCoordinates:modalRects count:4 forDisplay:0 surface:42];
|
|
185
|
+
[_store setOrigin:CGPointMake(0, 96) forDisplay:0 surface:BGSRNSecureMainSurface];
|
|
186
|
+
[_store setOrigin:CGPointMake(7, 40) forDisplay:0 surface:42];
|
|
187
|
+
|
|
188
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
189
|
+
XCTAssertEqualObjects(packed[1], @2);
|
|
190
|
+
XCTAssertEqualObjects([packed subarrayWithRange:NSMakeRange(2, 8)],
|
|
191
|
+
(@[ @10, @116, @30, @136, @107, @240, @157, @290 ]));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// A Modal's rectangles before its origin is recorded redact exactly the screen.
|
|
195
|
+
- (void)testASurfaceWithNoOriginYetServesTheScreenBounds {
|
|
196
|
+
const int32_t modalRects[] = {100, 200, 150, 250, 1, 2, 3, 4};
|
|
197
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
198
|
+
[_store setCoordinates:modalRects count:8 forDisplay:0 surface:42];
|
|
199
|
+
|
|
200
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
201
|
+
XCTAssertEqualObjects(packed[1], @1);
|
|
202
|
+
XCTAssertEqualObjects([packed subarrayWithRange:NSMakeRange(2, 4)], (@[ @0, @0, @402, @874 ]));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
- (void)testAFractionalScreenSizeIsRoundedUp {
|
|
206
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
207
|
+
[_store setDisplaySize:CGSizeMake(402.5, 873.2) forDisplay:0];
|
|
208
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
209
|
+
|
|
210
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
211
|
+
(@[ @0, @0, @403, @874 ]));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
- (void)testBeforeTheScreenSizeIsKnownTheWholeDisplayIsTheFallbackSquare {
|
|
215
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
216
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
217
|
+
|
|
218
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
219
|
+
(@[ @0, @0, @(BGSRNSecureFallbackDisplaySize), @(BGSRNSecureFallbackDisplaySize) ]));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
- (void)testRecordingTheScreenSizeMovesTheVersionOnlyWhenWhatIsServedChanges {
|
|
223
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
224
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
225
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
226
|
+
|
|
227
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
228
|
+
NSNumber *sized = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
229
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
230
|
+
[_store setDisplaySize:CGSizeZero forDisplay:0];
|
|
231
|
+
|
|
232
|
+
XCTAssertNotEqualObjects(sized, before);
|
|
233
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][0], sized);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
- (void)testRecordingTheSurfacesOriginReplacesTheWholeDisplayRectangle {
|
|
237
|
+
const int32_t modalRects[] = {100, 200, 150, 250};
|
|
238
|
+
[_store setCoordinates:modalRects count:4 forDisplay:0 surface:42];
|
|
239
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
240
|
+
|
|
241
|
+
[_store setOrigin:CGPointZero forDisplay:0 surface:42];
|
|
242
|
+
|
|
243
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
244
|
+
XCTAssertNotEqualObjects(packed[0], before);
|
|
245
|
+
XCTAssertEqualObjects([packed subarrayWithRange:NSMakeRange(2, 4)], (@[ @100, @200, @150, @250 ]));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/// The main surface fails closed too, until its first origin is recorded.
|
|
249
|
+
- (void)testTheMainSurfaceWithNoOriginYetServesTheScreenBounds {
|
|
250
|
+
BGSRNSecureRectangles *bare = [[BGSRNSecureRectangles alloc] init];
|
|
251
|
+
const int32_t rects[] = {10, 20, 30, 40};
|
|
252
|
+
[bare setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
253
|
+
[bare setCoordinates:rects count:4 forDisplay:0];
|
|
254
|
+
|
|
255
|
+
XCTAssertEqualObjects([[self unpack:[bare snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
256
|
+
(@[ @0, @0, @402, @874 ]));
|
|
257
|
+
|
|
258
|
+
[bare setOrigin:CGPointMake(0, 59) forDisplay:0];
|
|
259
|
+
XCTAssertEqualObjects([[self unpack:[bare snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
260
|
+
(@[ @10, @79, @30, @99 ]));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/// A fractional origin grows the rectangle by under a point, never shrinks it.
|
|
264
|
+
- (void)testAFractionalOriginRoundsEveryEdgeOutward {
|
|
265
|
+
const int32_t rects[] = {10, 20, 30, 40};
|
|
266
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
267
|
+
[_store setOrigin:CGPointMake(0.5, 59.25) forDisplay:0 surface:42];
|
|
268
|
+
|
|
269
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
270
|
+
(@[ @10, @79, @31, @100 ]));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
- (void)testANegativeFractionalOriginAlsoRoundsOutward {
|
|
274
|
+
const int32_t rects[] = {10, 20, 30, 40};
|
|
275
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
276
|
+
[_store setOrigin:CGPointMake(-0.5, -0.5) forDisplay:0];
|
|
277
|
+
|
|
278
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
279
|
+
(@[ @9, @19, @30, @40 ]));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
- (void)testAnOriginSaturatesInsteadOfWrapping {
|
|
283
|
+
const int32_t rects[] = {INT32_MAX - 1, INT32_MIN + 1, INT32_MAX - 1, INT32_MIN + 1};
|
|
284
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
285
|
+
[_store setOrigin:CGPointMake(10, -10) forDisplay:0];
|
|
286
|
+
|
|
287
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(2, 4)],
|
|
288
|
+
(@[ @(INT32_MAX), @((uint32_t)INT32_MIN), @(INT32_MAX), @((uint32_t)INT32_MIN) ]),
|
|
289
|
+
@"unpack reads each int32's bits as unsigned");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
- (void)testRecordingTheSameOriginAgainHoldsTheVersion {
|
|
293
|
+
const int32_t rects[] = {10, 20, 30, 40};
|
|
294
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
295
|
+
[_store setOrigin:CGPointMake(0, 59) forDisplay:0 surface:42];
|
|
296
|
+
NSNumber *settled = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
297
|
+
|
|
298
|
+
[_store setOrigin:CGPointMake(0, 59) forDisplay:0 surface:42];
|
|
299
|
+
|
|
300
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][0], settled);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
- (void)testListsTheSurfacesOtherThanTheMainOne {
|
|
304
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
305
|
+
[_store setCoordinates:rects count:4 forDisplay:0];
|
|
306
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:78];
|
|
307
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
308
|
+
[_store setCoordinates:rects count:4 forDisplay:1 surface:99];
|
|
309
|
+
|
|
310
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], (@[ @42, @78 ]));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
- (void)testDropsOnlyAnEmptyNonMainSurface {
|
|
314
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
315
|
+
[_store setCoordinates:NULL count:0 forDisplay:0 surface:42];
|
|
316
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:78];
|
|
317
|
+
[_store setCoordinates:NULL count:0 forDisplay:0];
|
|
318
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
319
|
+
|
|
320
|
+
[_store dropSurfaceIfEmpty:42];
|
|
321
|
+
[_store dropSurfaceIfEmpty:78];
|
|
322
|
+
[_store dropSurfaceIfEmpty:BGSRNSecureMainSurface];
|
|
323
|
+
|
|
324
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], (@[ @78 ]));
|
|
325
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][0], before);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/// A new runtime drops the Modal surfaces the old one left; the main one
|
|
329
|
+
/// stays, emptied, with its origin.
|
|
330
|
+
- (void)testClaimingANewRuntimeDropsEveryModalSurfaceButKeepsTheMainOne {
|
|
331
|
+
const int32_t mainRects[] = {10, 20, 30, 40};
|
|
332
|
+
const int32_t modalRects[] = {100, 200, 150, 250};
|
|
333
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
334
|
+
[_store setCoordinates:mainRects count:4 forDisplay:0];
|
|
335
|
+
[_store setCoordinates:modalRects count:4 forDisplay:0 surface:42];
|
|
336
|
+
[_store setCoordinates:modalRects count:4 forDisplay:1 surface:43];
|
|
337
|
+
NSNumber *before = [self unpack:[_store snapshotForDisplay:0]][0];
|
|
338
|
+
|
|
339
|
+
[_store claimRuntime];
|
|
340
|
+
|
|
341
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[]);
|
|
342
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:1], @[]);
|
|
343
|
+
NSArray *packed = [self unpack:[_store snapshotForDisplay:0]];
|
|
344
|
+
XCTAssertNotEqualObjects(packed[0], before);
|
|
345
|
+
XCTAssertEqualObjects(packed[1], @0);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// The main surface's origin survives the claim: the new runtime's first set
|
|
349
|
+
/// is placed, not failed closed.
|
|
350
|
+
- (void)testAClaimKeepsTheMainSurfacesOrigin {
|
|
351
|
+
const int32_t oldRects[] = {10, 20, 30, 40};
|
|
352
|
+
const int32_t newRects[] = {1, 2, 3, 4};
|
|
353
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
354
|
+
[_store setOrigin:CGPointMake(5, 7) forDisplay:0];
|
|
355
|
+
[_store setCoordinates:oldRects count:4 forDisplay:0];
|
|
356
|
+
|
|
357
|
+
const NSInteger current = [_store claimRuntime];
|
|
358
|
+
XCTAssertTrue([_store setCoordinates:newRects count:4 forDisplay:0 surface:BGSRNSecureMainSurface runtime:current]);
|
|
359
|
+
|
|
360
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(1, 5)],
|
|
361
|
+
(@[ @1, @6, @9, @8, @11 ]));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/// The old runtime's main set must not outlive it: its clearing write is
|
|
365
|
+
/// stale, and a new tree that never publishes on the main surface would
|
|
366
|
+
/// otherwise keep masking where the old secure view was.
|
|
367
|
+
- (void)testAClaimWithAMainSetThenAStaleEmptyWriteAndNoNewPublishServesNothing {
|
|
368
|
+
const int32_t rects[] = {10, 20, 30, 40};
|
|
369
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
370
|
+
const NSInteger old = [_store claimRuntime];
|
|
371
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:BGSRNSecureMainSurface runtime:old];
|
|
372
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][1], @1);
|
|
373
|
+
|
|
374
|
+
[_store claimRuntime];
|
|
375
|
+
XCTAssertFalse([_store setCoordinates:NULL count:0 forDisplay:0 surface:BGSRNSecureMainSurface runtime:old]);
|
|
376
|
+
|
|
377
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][1], @0);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
- (void)testReleasingTheCurrentRuntimeDropsItsModalSurfaces {
|
|
381
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
382
|
+
const NSInteger claim = [_store claimRuntime];
|
|
383
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
384
|
+
|
|
385
|
+
[_store releaseRuntime:claim];
|
|
386
|
+
|
|
387
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[]);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/// A reload can start the new module before the old one is released.
|
|
391
|
+
- (void)testReleasingAnOldRuntimeLeavesTheNewRuntimesSurfaces {
|
|
392
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
393
|
+
const NSInteger old = [_store claimRuntime];
|
|
394
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42];
|
|
395
|
+
[_store claimRuntime];
|
|
396
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:58];
|
|
397
|
+
|
|
398
|
+
[_store releaseRuntime:old];
|
|
399
|
+
|
|
400
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[ @58 ]);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/// The old module is not invalidated yet when the new one claims: its late
|
|
404
|
+
/// publish must not put back the Modal lane the claim dropped, which would
|
|
405
|
+
/// fail closed over the whole screen for the rest of the process.
|
|
406
|
+
- (void)testAStaleNonEmptyWriteDoesNotRecreateADroppedLane {
|
|
407
|
+
const int32_t rects[] = {100, 200, 150, 250};
|
|
408
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
409
|
+
const NSInteger old = [_store claimRuntime];
|
|
410
|
+
XCTAssertTrue([_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:old]);
|
|
411
|
+
[_store claimRuntime];
|
|
412
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[]);
|
|
413
|
+
NSData *before = [_store snapshotForDisplay:0];
|
|
414
|
+
|
|
415
|
+
XCTAssertFalse([_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:old]);
|
|
416
|
+
|
|
417
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[]);
|
|
418
|
+
XCTAssertEqualObjects([_store snapshotForDisplay:0], before);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// Fabric numbers React tags from 1 again after a reload, so the old
|
|
422
|
+
/// runtime's unmount clears the same key the new runtime's Modal now
|
|
423
|
+
/// publishes on. That empty write must not uncover the new Modal.
|
|
424
|
+
- (void)testAStaleEmptyWriteDoesNotClearTheNewRuntimesLaneOnTheSameTag {
|
|
425
|
+
const int32_t oldRects[] = {1, 2, 3, 4};
|
|
426
|
+
const int32_t newRects[] = {100, 200, 150, 250};
|
|
427
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
428
|
+
const NSInteger old = [_store claimRuntime];
|
|
429
|
+
[_store setCoordinates:oldRects count:4 forDisplay:0 surface:42 runtime:old];
|
|
430
|
+
const NSInteger current = [_store claimRuntime];
|
|
431
|
+
[_store setCoordinates:newRects count:4 forDisplay:0 surface:42 runtime:current];
|
|
432
|
+
[_store setOrigin:CGPointMake(10, 20) forDisplay:0 surface:42];
|
|
433
|
+
NSData *before = [_store snapshotForDisplay:0];
|
|
434
|
+
XCTAssertEqualObjects([[self unpack:before] subarrayWithRange:NSMakeRange(1, 5)],
|
|
435
|
+
(@[ @1, @110, @220, @160, @270 ]));
|
|
436
|
+
|
|
437
|
+
XCTAssertFalse([_store setCoordinates:NULL count:0 forDisplay:0 surface:42 runtime:old]);
|
|
438
|
+
|
|
439
|
+
XCTAssertEqualObjects([_store snapshotForDisplay:0], before);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
- (void)testTheCurrentRuntimesWritesStillApply {
|
|
443
|
+
const int32_t rects[] = {100, 200, 150, 250};
|
|
444
|
+
[_store setDisplaySize:CGSizeMake(402, 874) forDisplay:0];
|
|
445
|
+
[_store claimRuntime];
|
|
446
|
+
const NSInteger current = [_store claimRuntime];
|
|
447
|
+
XCTAssertEqual([_store currentClaim], current);
|
|
448
|
+
|
|
449
|
+
XCTAssertTrue([_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:current]);
|
|
450
|
+
[_store setOrigin:CGPointMake(10, 20) forDisplay:0 surface:42];
|
|
451
|
+
XCTAssertEqualObjects([[self unpack:[_store snapshotForDisplay:0]] subarrayWithRange:NSMakeRange(1, 5)],
|
|
452
|
+
(@[ @1, @110, @220, @160, @270 ]));
|
|
453
|
+
|
|
454
|
+
XCTAssertTrue([_store setCoordinates:NULL count:0 forDisplay:0 surface:42 runtime:current]);
|
|
455
|
+
XCTAssertEqualObjects([self unpack:[_store snapshotForDisplay:0]][1], @0);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/// A malformed write from the current runtime is still rejected, not applied.
|
|
459
|
+
- (void)testTheCurrentRuntimesMalformedWriteIsStillRejected {
|
|
460
|
+
const int32_t rects[] = {1, 2, 3};
|
|
461
|
+
const NSInteger current = [_store claimRuntime];
|
|
462
|
+
|
|
463
|
+
XCTAssertFalse([_store setCoordinates:rects count:3 forDisplay:0 surface:42 runtime:current]);
|
|
464
|
+
XCTAssertEqualObjects([_store surfacesForDisplay:0], @[]);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
#pragma mark - A Modal surface's host (PR 48, round 2)
|
|
468
|
+
|
|
469
|
+
static BOOL (^const BGSRNAcceptAny)(id) = ^BOOL(id candidate) {
|
|
470
|
+
return YES;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
- (void)testAHostIsRecordedOnlyForTheCurrentRuntimesModalLane {
|
|
474
|
+
NSObject *host = [NSObject new];
|
|
475
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
476
|
+
const NSInteger old = [_store claimRuntime];
|
|
477
|
+
XCTAssertFalse([_store setHost:host forSurface:42 runtime:old], @"no lane for 42 yet");
|
|
478
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:old];
|
|
479
|
+
XCTAssertFalse([_store setHost:host forSurface:BGSRNSecureMainSurface runtime:old]);
|
|
480
|
+
XCTAssertTrue([_store setHost:host forSurface:42 runtime:old]);
|
|
481
|
+
XCTAssertEqual([_store hostForSurface:42 accepting:BGSRNAcceptAny], host);
|
|
482
|
+
|
|
483
|
+
const NSInteger current = [_store claimRuntime];
|
|
484
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
485
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:current];
|
|
486
|
+
XCTAssertFalse([_store setHost:host forSurface:42 runtime:old]);
|
|
487
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
488
|
+
XCTAssertTrue([_store setHost:host forSurface:42 runtime:current]);
|
|
489
|
+
XCTAssertEqual([_store hostForSurface:42 accepting:BGSRNAcceptAny], host);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
- (void)testALookupIsNamedOnlyByTheCurrentRuntime {
|
|
493
|
+
NSObject *host = [NSObject new];
|
|
494
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
495
|
+
BGSRNSecureHostResolver lookup = ^id _Nullable(NSInteger tag) {
|
|
496
|
+
return host;
|
|
497
|
+
};
|
|
498
|
+
const NSInteger old = [_store claimRuntime];
|
|
499
|
+
XCTAssertFalse([_store setHostResolver:lookup forSurface:42 runtime:old], @"no lane for 42 yet");
|
|
500
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:old];
|
|
501
|
+
[_store claimRuntime];
|
|
502
|
+
const NSInteger current = [_store claimRuntime];
|
|
503
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:current];
|
|
504
|
+
|
|
505
|
+
XCTAssertFalse([_store setHostResolver:lookup forSurface:42 runtime:old]);
|
|
506
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
507
|
+
XCTAssertTrue([_store setHostResolver:lookup forSurface:42 runtime:current]);
|
|
508
|
+
XCTAssertEqual([_store hostForSurface:42 accepting:BGSRNAcceptAny], host);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/// A claim that lands while a lookup is running: what it found is not kept.
|
|
512
|
+
- (void)testAHostFoundAcrossANewClaimIsNotKept {
|
|
513
|
+
NSObject *host = [NSObject new];
|
|
514
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
515
|
+
const NSInteger old = [_store claimRuntime];
|
|
516
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:old];
|
|
517
|
+
BGSRNSecureRectangles *store = _store;
|
|
518
|
+
[_store setHostResolver:^id _Nullable(NSInteger tag) {
|
|
519
|
+
const NSInteger current = [store claimRuntime];
|
|
520
|
+
const int32_t again[] = {1, 2, 3, 4};
|
|
521
|
+
[store setCoordinates:again count:4 forDisplay:0 surface:42 runtime:current];
|
|
522
|
+
return host;
|
|
523
|
+
}
|
|
524
|
+
forSurface:42
|
|
525
|
+
runtime:old];
|
|
526
|
+
|
|
527
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
528
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
- (void)testASurfacesHostGoesWithItsLastLane {
|
|
532
|
+
NSObject *host = [NSObject new];
|
|
533
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
534
|
+
const NSInteger claim = [_store claimRuntime];
|
|
535
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:claim];
|
|
536
|
+
[_store setHost:host forSurface:42 runtime:claim];
|
|
537
|
+
[_store setHostResolver:^id _Nullable(NSInteger tag) {
|
|
538
|
+
return host;
|
|
539
|
+
}
|
|
540
|
+
forSurface:42
|
|
541
|
+
runtime:claim];
|
|
542
|
+
|
|
543
|
+
[_store setCoordinates:NULL count:0 forDisplay:0 surface:42 runtime:claim];
|
|
544
|
+
[_store dropSurfaceIfEmpty:42];
|
|
545
|
+
|
|
546
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
- (void)testReleasingTheCurrentRuntimeForgetsItsHosts {
|
|
550
|
+
NSObject *host = [NSObject new];
|
|
551
|
+
const int32_t rects[] = {1, 2, 3, 4};
|
|
552
|
+
const NSInteger claim = [_store claimRuntime];
|
|
553
|
+
[_store setCoordinates:rects count:4 forDisplay:0 surface:42 runtime:claim];
|
|
554
|
+
[_store setHost:host forSurface:42 runtime:claim];
|
|
555
|
+
|
|
556
|
+
[_store releaseRuntime:claim];
|
|
557
|
+
|
|
558
|
+
XCTAssertNil([_store hostForSurface:42 accepting:BGSRNAcceptAny]);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/// The shared store outlives any one wrapper: the init provider registers one
|
|
562
|
+
/// before launch and setWrapperInfo swaps in another, and the regions the app
|
|
563
|
+
/// marked secret must survive that.
|
|
564
|
+
- (void)testSharedStoreIsOneInstance {
|
|
565
|
+
XCTAssertTrue([BGSRNSecureRectangles shared] == [BGSRNSecureRectangles shared]);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
@end
|