catalyst-core 0.0.3-canary.9 → 0.1.0-beta.2
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/README.md +4 -5
- package/bin/catalyst.js +28 -15
- package/changelog.md +139 -30
- package/dist/native/androidProject/app/build.gradle.kts +125 -15
- package/dist/native/androidProject/app/proguard-rules.pro +85 -14
- package/dist/native/androidProject/app/src/debug/res/xml/network_security_config.xml +8 -0
- package/dist/native/androidProject/app/src/main/AndroidManifest.xml +10 -3
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +552 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CatalystConstants.kt +109 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +605 -124
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +405 -47
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +341 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +954 -71
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/SplashActivity.kt +111 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/URLWhitelistManager.kt +231 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +49 -55
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +81 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/design/DesignTokens.kt +307 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/EmulatorDetector.kt +203 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/FridaDetector.kt +187 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertHandler.kt +170 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertUI.kt +366 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityBottomSheet.kt +138 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckManager.kt +511 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckScheduler.kt +68 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +47 -11
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DeviceInfoUtils.kt +38 -13
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DownloadUtils.kt +36 -14
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FileUtils.kt +3 -2
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +57 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/IntentUtils.kt +31 -6
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +82 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NetworkUtils.kt +105 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationConstants.kt +28 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationUtils.kt +639 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/SafeAreaUtils.kt +62 -0
- package/dist/native/androidProject/app/src/main/res/drawable/splashscreen_fallback.png +0 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_main.xml +1 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_splash.xml +20 -0
- package/dist/native/androidProject/app/src/main/res/values/themes.xml +23 -0
- package/dist/native/androidProject/app/src/main/res/values-night/themes.xml +11 -0
- package/dist/native/androidProject/app/src/main/res/xml/network_security_config.xml +12 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +166 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +94 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeMessageValidatorTest.kt +267 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +286 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +296 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ConfigMappingTest.kt +594 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CustomWebviewTest.kt +466 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +187 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +304 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +424 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +469 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/SecurityBridgeTest.kt +199 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/URLWhitelistManagerTest.kt +462 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +391 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +224 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +399 -0
- package/dist/native/androidProject/build.gradle.kts +6 -0
- package/dist/native/androidProject/gradle/libs.versions.toml +8 -2
- package/dist/native/androidSetup.js +4 -3
- package/dist/native/assets/catalyst.png +0 -0
- package/dist/native/bridge/WebBridge.js +16 -3
- package/dist/native/bridge/constants/NativeInterfaces.js +28 -10
- package/dist/native/bridge/errors.js +1 -1
- package/dist/native/bridge/hooks.js +76 -16
- package/dist/native/bridge/safeArea.js +5 -0
- package/dist/native/bridge/standardizedHooks.js +23 -5
- package/dist/native/bridge/useBaseHook.js +7 -9
- package/dist/native/bridge/utils/CameraUtils.js +58 -0
- package/dist/native/bridge/utils/FileObjectConverter.js +40 -0
- package/dist/native/bridge/utils/NativeBridge.js +57 -8
- package/dist/native/buildAppAndroid.js +115 -43
- package/dist/native/buildAppIos.js +291 -26
- package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +21 -0
- package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +24 -0
- package/dist/native/iosnativeWebView/Configurations/Shared.xcconfig +50 -0
- package/dist/native/iosnativeWebView/Package.resolved +32 -0
- package/dist/native/iosnativeWebView/Package.swift +37 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +293 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +299 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +199 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +125 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +70 -0
- package/dist/native/iosnativeWebView/Sources/Core/Notifications/NotificationModels.swift +156 -0
- package/dist/native/iosnativeWebView/Sources/Core/Protocols/NotificationHandlerProtocol.swift +35 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +26 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift +69 -36
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +363 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +67 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +1053 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FrameworkServerUtils.swift +901 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ImageHandler.swift +206 -20
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NetworkMonitor.swift +112 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NotificationHandlerProvider.swift +20 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NullNotificationHandler.swift +85 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ResourceURLProtocol.swift +60 -25
- package/dist/native/iosnativeWebView/Sources/Core/Utils/SafeAreaUtils.swift +132 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/ScreenSecureManager.swift +131 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/URLWhitelistManager.swift +224 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +43 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +991 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +166 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +340 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +149 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +611 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +334 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +95 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +86 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +181 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +182 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +395 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +84 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AccentColor.colorset/Contents.json +8 -8
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AppIcon.appiconset/Contents.json +10 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +65 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Info-Release.plist +21 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +13 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Preview Content/Preview Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebView.entitlements +12 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +80 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/localhost.p12 +0 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +118 -100
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +69 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/xcshareddata/xcschemes/iosnativeWebView.xcscheme +9 -4
- package/dist/native/iosnativeWebView/iosnativeWebView.xctestplan +47 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BootTimingUtilityTests.swift +236 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift +212 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +418 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +390 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ConfigMappingTests.swift +299 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +383 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FrameworkServerUtilsTests.swift +391 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +581 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NotificationHandlerTests.swift +430 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ScreenSecureManagerTests.swift +121 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/URLWhitelistManagerTests.swift +367 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +440 -0
- package/dist/native/renameAndroidProject.js +80 -70
- package/dist/native/setupEmulatorIos.js +22 -5
- package/dist/native/setupServer.js +11 -10
- package/dist/native/terminalProgress.js +10 -10
- package/dist/native/utils.js +4 -5
- package/dist/otel.js +4 -0
- package/dist/scripts/build.js +2 -2
- package/dist/scripts/devBuild.js +2 -2
- package/dist/scripts/loadEnvironmentVariables.js +3 -1
- package/dist/scripts/scriptUtils.js +2 -2
- package/dist/sentry.js +4 -1
- package/dist/server/renderer/document/Body.js +4 -4
- package/dist/server/renderer/handler.js +7 -5
- package/dist/webpack/development.client.babel.js +1 -1
- package/mcp_v2/conversion-tasks.json +326 -0
- package/mcp_v2/knowledge-base.json +1068 -0
- package/mcp_v2/lib/helpers.js +165 -0
- package/mcp_v2/mcp.js +563 -0
- package/mcp_v2/package.json +13 -0
- package/mcp_v2/schema.sql +88 -0
- package/mcp_v2/setup.js +278 -0
- package/mcp_v2/tools/build.js +686 -0
- package/mcp_v2/tools/config.js +453 -0
- package/mcp_v2/tools/conversion.js +799 -0
- package/mcp_v2/tools/debug.js +113 -0
- package/mcp_v2/tools/knowledge.js +219 -0
- package/mcp_v2/tools/sync.js +23 -0
- package/mcp_v2/tools/tasks.js +945 -0
- package/package.json +11 -15
- package/dist/native/androidProject/.idea/.name +0 -1
- package/dist/native/androidProject/.idea/AndroidProjectSystem.xml +0 -6
- package/dist/native/androidProject/.idea/compiler.xml +0 -6
- package/dist/native/androidProject/.idea/deploymentTargetSelector.xml +0 -10
- package/dist/native/androidProject/.idea/gradle.xml +0 -18
- package/dist/native/androidProject/.idea/migrations.xml +0 -10
- package/dist/native/androidProject/.idea/misc.xml +0 -10
- package/dist/native/androidProject/.idea/runConfigurations.xml +0 -17
- package/dist/native/androidProject/.idea/vcs.xml +0 -6
- package/dist/native/iosnativeWebView/iosnativeWebView/NativeBridge.swift +0 -217
- package/dist/native/iosnativeWebView/iosnativeWebView/WebView.swift +0 -96
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewModel.swift +0 -47
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewNavigationDelegate.swift +0 -140
- package/license +0 -10
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import Foundation
|
|
3
|
+
@testable import CatalystCore
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Unit tests for BootTimingUtility
|
|
7
|
+
*
|
|
8
|
+
* Tests the centralized timing utility for measuring app boot performance.
|
|
9
|
+
* Only enabled in DEBUG builds for performance testing.
|
|
10
|
+
*
|
|
11
|
+
* Categories:
|
|
12
|
+
* 1. Timing Capture (2 tests)
|
|
13
|
+
* 2. Metrics Calculation (2 tests)
|
|
14
|
+
* 3. Performance Reporting (2 tests)
|
|
15
|
+
*
|
|
16
|
+
* Total: 6 tests
|
|
17
|
+
*
|
|
18
|
+
* Testing Approach:
|
|
19
|
+
* - Tests verify timing function behavior in DEBUG mode
|
|
20
|
+
* - Tests verify timestamp formatting and elapsed time calculation
|
|
21
|
+
* - Tests verify logging does not crash in release mode (no-op)
|
|
22
|
+
* - Tests are lightweight and focus on utility logic
|
|
23
|
+
*/
|
|
24
|
+
final class BootTimingUtilityTests: XCTestCase {
|
|
25
|
+
|
|
26
|
+
// ========================================
|
|
27
|
+
// CATEGORY 1: Timing Capture (2 tests)
|
|
28
|
+
// ========================================
|
|
29
|
+
|
|
30
|
+
func testTimingCapture_AppLaunchTimeInitialized() {
|
|
31
|
+
// Verify APP_LAUNCH_TIME is initialized
|
|
32
|
+
#if DEBUG
|
|
33
|
+
// In DEBUG mode, APP_LAUNCH_TIME should be set to a valid timestamp
|
|
34
|
+
let currentTime = CFAbsoluteTimeGetCurrent()
|
|
35
|
+
|
|
36
|
+
// APP_LAUNCH_TIME should be less than or equal to current time
|
|
37
|
+
// (it was set when the module loaded)
|
|
38
|
+
XCTAssertLessThanOrEqual(APP_LAUNCH_TIME, currentTime,
|
|
39
|
+
"APP_LAUNCH_TIME should be initialized to a time <= current time")
|
|
40
|
+
|
|
41
|
+
// APP_LAUNCH_TIME should be a reasonable recent time (within last hour)
|
|
42
|
+
let oneHourAgo = currentTime - 3600
|
|
43
|
+
XCTAssertGreaterThan(APP_LAUNCH_TIME, oneHourAgo,
|
|
44
|
+
"APP_LAUNCH_TIME should be within the last hour (reasonable for test execution)")
|
|
45
|
+
#else
|
|
46
|
+
// In RELEASE mode, we can't test APP_LAUNCH_TIME as it doesn't exist
|
|
47
|
+
XCTAssertTrue(true, "Skipping DEBUG-only test in RELEASE build")
|
|
48
|
+
#endif
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func testTimingCapture_LogWithTimestampDoesNotCrash() {
|
|
52
|
+
// Verify logWithTimestamp does not crash with various inputs
|
|
53
|
+
|
|
54
|
+
// Test with normal message
|
|
55
|
+
logWithTimestamp("Test message 1")
|
|
56
|
+
|
|
57
|
+
// Test with empty message
|
|
58
|
+
logWithTimestamp("")
|
|
59
|
+
|
|
60
|
+
// Test with special characters
|
|
61
|
+
logWithTimestamp("Test with 🚀 emoji and special chars: <>!@#$%")
|
|
62
|
+
|
|
63
|
+
// Test with long message
|
|
64
|
+
let longMessage = String(repeating: "A", count: 1000)
|
|
65
|
+
logWithTimestamp(longMessage)
|
|
66
|
+
|
|
67
|
+
// Test with newlines
|
|
68
|
+
logWithTimestamp("Line 1\nLine 2\nLine 3")
|
|
69
|
+
|
|
70
|
+
// If we reach here without crashing, test passes
|
|
71
|
+
XCTAssertTrue(true, "logWithTimestamp should handle all message types without crashing")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ========================================
|
|
75
|
+
// CATEGORY 2: Metrics Calculation (2 tests)
|
|
76
|
+
// ========================================
|
|
77
|
+
|
|
78
|
+
func testMetricsCalculation_ElapsedTimeCalculation() {
|
|
79
|
+
#if DEBUG
|
|
80
|
+
// Capture time before logging
|
|
81
|
+
let timeBefore = CFAbsoluteTimeGetCurrent()
|
|
82
|
+
|
|
83
|
+
// Small delay to ensure measurable elapsed time
|
|
84
|
+
Thread.sleep(forTimeInterval: 0.01) // 10ms delay
|
|
85
|
+
|
|
86
|
+
// Capture time after delay
|
|
87
|
+
let timeAfter = CFAbsoluteTimeGetCurrent()
|
|
88
|
+
|
|
89
|
+
// Calculate elapsed time from APP_LAUNCH_TIME
|
|
90
|
+
let elapsedBefore = (timeBefore - APP_LAUNCH_TIME) * 1000 // Convert to ms
|
|
91
|
+
let elapsedAfter = (timeAfter - APP_LAUNCH_TIME) * 1000
|
|
92
|
+
|
|
93
|
+
// Verify elapsed time increases
|
|
94
|
+
XCTAssertGreaterThan(elapsedAfter, elapsedBefore,
|
|
95
|
+
"Elapsed time should increase over time")
|
|
96
|
+
|
|
97
|
+
// Verify the difference is approximately 10ms (with tolerance for system variance)
|
|
98
|
+
let difference = elapsedAfter - elapsedBefore
|
|
99
|
+
XCTAssertGreaterThan(difference, 5.0, "Time difference should be at least 5ms")
|
|
100
|
+
XCTAssertLessThan(difference, 50.0, "Time difference should be less than 50ms (accounting for system load)")
|
|
101
|
+
#else
|
|
102
|
+
XCTAssertTrue(true, "Skipping DEBUG-only test in RELEASE build")
|
|
103
|
+
#endif
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func testMetricsCalculation_TimestampFormatting() {
|
|
107
|
+
#if DEBUG
|
|
108
|
+
// Test timestamp formatting by directly calculating elapsed time
|
|
109
|
+
let elapsed = (CFAbsoluteTimeGetCurrent() - APP_LAUNCH_TIME) * 1000
|
|
110
|
+
|
|
111
|
+
// Format using same method as logWithTimestamp
|
|
112
|
+
let formatted = String(format: "%.3f", elapsed)
|
|
113
|
+
|
|
114
|
+
// Verify format is valid
|
|
115
|
+
XCTAssertFalse(formatted.isEmpty, "Formatted timestamp should not be empty")
|
|
116
|
+
|
|
117
|
+
// Verify it contains decimal point
|
|
118
|
+
XCTAssertTrue(formatted.contains("."), "Formatted timestamp should contain decimal point")
|
|
119
|
+
|
|
120
|
+
// Verify it has 3 decimal places
|
|
121
|
+
if let decimalIndex = formatted.firstIndex(of: ".") {
|
|
122
|
+
let afterDecimal = formatted[formatted.index(after: decimalIndex)...]
|
|
123
|
+
XCTAssertEqual(afterDecimal.count, 3, "Timestamp should have exactly 3 decimal places")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Verify it's a valid number
|
|
127
|
+
XCTAssertNotNil(Double(formatted), "Formatted timestamp should be parseable as Double")
|
|
128
|
+
|
|
129
|
+
// Verify it's a positive number
|
|
130
|
+
if let value = Double(formatted) {
|
|
131
|
+
XCTAssertGreaterThan(value, 0, "Elapsed time should be positive")
|
|
132
|
+
}
|
|
133
|
+
#else
|
|
134
|
+
XCTAssertTrue(true, "Skipping DEBUG-only test in RELEASE build")
|
|
135
|
+
#endif
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ========================================
|
|
139
|
+
// CATEGORY 3: Performance Reporting (2 tests)
|
|
140
|
+
// ========================================
|
|
141
|
+
|
|
142
|
+
func testPerformanceReporting_LoggingInDebugMode() {
|
|
143
|
+
#if DEBUG
|
|
144
|
+
// Verify that logging works in DEBUG mode
|
|
145
|
+
// We can't directly capture log output in unit tests, but we can verify:
|
|
146
|
+
// 1. The function executes without crashing
|
|
147
|
+
// 2. The timing values are reasonable
|
|
148
|
+
|
|
149
|
+
let messagesToLog = [
|
|
150
|
+
"App initialization started",
|
|
151
|
+
"Config loaded",
|
|
152
|
+
"WebView initialized",
|
|
153
|
+
"Navigation complete",
|
|
154
|
+
"App ready"
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
for message in messagesToLog {
|
|
158
|
+
// This should log with timestamp in DEBUG mode
|
|
159
|
+
logWithTimestamp(message)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// If we reach here, logging worked without crashing
|
|
163
|
+
XCTAssertTrue(true, "Logging should work in DEBUG mode without crashes")
|
|
164
|
+
#else
|
|
165
|
+
XCTAssertTrue(true, "Skipping DEBUG-only test in RELEASE build")
|
|
166
|
+
#endif
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
func testPerformanceReporting_NoOpInReleaseMode() {
|
|
170
|
+
// This test verifies that in RELEASE mode, logWithTimestamp is a no-op
|
|
171
|
+
// We can't directly test the conditional compilation, but we can verify
|
|
172
|
+
// that calling the function doesn't cause side effects
|
|
173
|
+
|
|
174
|
+
#if !DEBUG
|
|
175
|
+
// In RELEASE mode
|
|
176
|
+
logWithTimestamp("This should be a no-op")
|
|
177
|
+
|
|
178
|
+
// If we reach here without crashing, the no-op worked
|
|
179
|
+
XCTAssertTrue(true, "logWithTimestamp should be a no-op in RELEASE mode")
|
|
180
|
+
#else
|
|
181
|
+
// In DEBUG mode, we'll just verify it doesn't crash
|
|
182
|
+
logWithTimestamp("This should log in DEBUG mode")
|
|
183
|
+
XCTAssertTrue(true, "logWithTimestamp should work in DEBUG mode")
|
|
184
|
+
#endif
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ========================================
|
|
188
|
+
// BONUS TESTS: Edge Cases
|
|
189
|
+
// ========================================
|
|
190
|
+
|
|
191
|
+
func testEdgeCase_ConcurrentLogging() {
|
|
192
|
+
// Test that concurrent logging doesn't cause issues
|
|
193
|
+
let expectation = self.expectation(description: "Concurrent logging completes")
|
|
194
|
+
expectation.expectedFulfillmentCount = 10
|
|
195
|
+
|
|
196
|
+
for i in 0..<10 {
|
|
197
|
+
DispatchQueue.global(qos: .background).async {
|
|
198
|
+
logWithTimestamp("Concurrent log \(i)")
|
|
199
|
+
expectation.fulfill()
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
waitForExpectations(timeout: 5.0) { error in
|
|
204
|
+
XCTAssertNil(error, "Concurrent logging should complete without errors")
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
func testEdgeCase_RapidSuccessiveLogging() {
|
|
209
|
+
// Test rapid successive logging calls
|
|
210
|
+
for i in 0..<100 {
|
|
211
|
+
logWithTimestamp("Rapid log \(i)")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// If we reach here without crashing, test passes
|
|
215
|
+
XCTAssertTrue(true, "Rapid successive logging should not crash")
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
func testEdgeCase_UnicodeCharacters() {
|
|
219
|
+
// Test with various unicode characters
|
|
220
|
+
let unicodeMessages = [
|
|
221
|
+
"测试中文字符",
|
|
222
|
+
"テスト日本語",
|
|
223
|
+
"테스트 한국어",
|
|
224
|
+
"тест русский",
|
|
225
|
+
"اختبار العربية",
|
|
226
|
+
"🚀🎉✅❌⚠️",
|
|
227
|
+
"Mixed: Hello 世界 🌍"
|
|
228
|
+
]
|
|
229
|
+
|
|
230
|
+
for message in unicodeMessages {
|
|
231
|
+
logWithTimestamp(message)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
XCTAssertTrue(true, "Unicode characters should be handled correctly")
|
|
235
|
+
}
|
|
236
|
+
}
|
package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import WebKit
|
|
3
|
+
@testable import CatalystCore
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Unit tests for BridgeCommandHandler — security commands.
|
|
7
|
+
*
|
|
8
|
+
* Coverage:
|
|
9
|
+
* 1. setScreenSecure routing (3 tests)
|
|
10
|
+
* 2. getScreenSecure routing (2 tests)
|
|
11
|
+
* 3. clearWebData routing (3 tests)
|
|
12
|
+
*
|
|
13
|
+
* Total: 8 tests
|
|
14
|
+
*
|
|
15
|
+
* Each test drives the full bridge pipeline (NativeBridge → BridgeCommandHandler)
|
|
16
|
+
* via a MockWKWebView and captures the evaluateJavaScript call that the delegate
|
|
17
|
+
* would fire back to the web layer.
|
|
18
|
+
*
|
|
19
|
+
* MockWKWebView and MockWKScriptMessage are defined in NativeBridgeTests.swift
|
|
20
|
+
* and BridgeMessageValidatorTests.swift respectively (shared across the test target).
|
|
21
|
+
*/
|
|
22
|
+
final class BridgeCommandHandlerSecurityTests: XCTestCase {
|
|
23
|
+
|
|
24
|
+
var bridge: NativeBridge!
|
|
25
|
+
var mockWebView: MockWKWebView!
|
|
26
|
+
var mockViewController: UIViewController!
|
|
27
|
+
|
|
28
|
+
override func setUp() {
|
|
29
|
+
super.setUp()
|
|
30
|
+
mockWebView = MockWKWebView()
|
|
31
|
+
mockViewController = UIViewController()
|
|
32
|
+
bridge = NativeBridge(webView: mockWebView, viewController: mockViewController)
|
|
33
|
+
bridge.register()
|
|
34
|
+
// Ensure a clean screen-secure state before each test
|
|
35
|
+
ScreenSecureManager.shared.setScreenSecure(false)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override func tearDown() {
|
|
39
|
+
bridge.unregister()
|
|
40
|
+
bridge = nil
|
|
41
|
+
mockWebView = nil
|
|
42
|
+
mockViewController = nil
|
|
43
|
+
ScreenSecureManager.shared.setScreenSecure(false)
|
|
44
|
+
super.tearDown()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ============================================================
|
|
48
|
+
// CATEGORY 1: setScreenSecure routing (3 tests)
|
|
49
|
+
// ============================================================
|
|
50
|
+
|
|
51
|
+
func testSetScreenSecure_Enable_FiresOnScreenSecureSetCallback() {
|
|
52
|
+
let exp = expectation(description: "ON_SCREEN_SECURE_SET callback fired")
|
|
53
|
+
|
|
54
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
55
|
+
if script.contains("ON_SCREEN_SECURE_SET") {
|
|
56
|
+
exp.fulfill()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let message = createMessage(command: "setScreenSecure", data: ["enable": true])
|
|
61
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
62
|
+
didReceive: message)
|
|
63
|
+
|
|
64
|
+
wait(for: [exp], timeout: 2.0)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func testSetScreenSecure_Enable_CallbackContainsSecureTrue() {
|
|
68
|
+
let exp = expectation(description: "ON_SCREEN_SECURE_SET payload has secure:true")
|
|
69
|
+
|
|
70
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
71
|
+
if script.contains("ON_SCREEN_SECURE_SET") {
|
|
72
|
+
XCTAssertTrue(
|
|
73
|
+
script.contains("\"secure\"") || script.contains("secure"),
|
|
74
|
+
"Callback should include secure field"
|
|
75
|
+
)
|
|
76
|
+
XCTAssertTrue(
|
|
77
|
+
script.contains("true"),
|
|
78
|
+
"secure should be true after enabling"
|
|
79
|
+
)
|
|
80
|
+
exp.fulfill()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let message = createMessage(command: "setScreenSecure", data: ["enable": true])
|
|
85
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
86
|
+
didReceive: message)
|
|
87
|
+
|
|
88
|
+
wait(for: [exp], timeout: 2.0)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func testSetScreenSecure_InvalidParams_FiresErrorCallback() {
|
|
92
|
+
// Passing a non-dict, non-string param is handled by the fallback in
|
|
93
|
+
// BridgeCommandHandler.setScreenSecure — it fires ON_SCREEN_SECURE_ERROR.
|
|
94
|
+
let exp = expectation(description: "ON_SCREEN_SECURE_ERROR fired for nil params")
|
|
95
|
+
|
|
96
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
97
|
+
if script.contains("ON_SCREEN_SECURE_ERROR") {
|
|
98
|
+
exp.fulfill()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Route via bridge with data that contains no "enable" key at all
|
|
103
|
+
let message = createMessage(command: "setScreenSecure", data: [:])
|
|
104
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
105
|
+
didReceive: message)
|
|
106
|
+
|
|
107
|
+
// The empty dict triggers the else branch → ON_SCREEN_SECURE_ERROR
|
|
108
|
+
wait(for: [exp], timeout: 2.0)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ============================================================
|
|
112
|
+
// CATEGORY 2: getScreenSecure routing (2 tests)
|
|
113
|
+
// ============================================================
|
|
114
|
+
|
|
115
|
+
func testGetScreenSecure_FiresOnScreenSecureStatusCallback() {
|
|
116
|
+
let exp = expectation(description: "ON_SCREEN_SECURE_STATUS callback fired")
|
|
117
|
+
|
|
118
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
119
|
+
if script.contains("ON_SCREEN_SECURE_STATUS") {
|
|
120
|
+
exp.fulfill()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let message = createMessage(command: "getScreenSecure", data: [:])
|
|
125
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
126
|
+
didReceive: message)
|
|
127
|
+
|
|
128
|
+
wait(for: [exp], timeout: 2.0)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
func testGetScreenSecure_ReflectsCurrentState() {
|
|
132
|
+
// Set state first, then query it via the bridge
|
|
133
|
+
ScreenSecureManager.shared.setScreenSecure(true)
|
|
134
|
+
|
|
135
|
+
let exp = expectation(description: "ON_SCREEN_SECURE_STATUS reflects secure:true")
|
|
136
|
+
|
|
137
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
138
|
+
if script.contains("ON_SCREEN_SECURE_STATUS") {
|
|
139
|
+
XCTAssertTrue(script.contains("true"),
|
|
140
|
+
"Status callback should reflect secure=true")
|
|
141
|
+
exp.fulfill()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let message = createMessage(command: "getScreenSecure", data: [:])
|
|
146
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
147
|
+
didReceive: message)
|
|
148
|
+
|
|
149
|
+
wait(for: [exp], timeout: 2.0)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ============================================================
|
|
153
|
+
// CATEGORY 3: clearWebData routing (3 tests)
|
|
154
|
+
// ============================================================
|
|
155
|
+
|
|
156
|
+
func testClearWebData_WhenWebViewPresent_FiresOnWebDataClearedCallback() {
|
|
157
|
+
// BridgeCommandHandler needs a webView injected to proceed past the guard
|
|
158
|
+
// NativeBridge injects it during register(), so the mock is already set.
|
|
159
|
+
let exp = expectation(description: "ON_WEB_DATA_CLEARED callback fired")
|
|
160
|
+
|
|
161
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
162
|
+
if script.contains("ON_WEB_DATA_CLEARED") {
|
|
163
|
+
exp.fulfill()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let message = createMessage(command: "clearWebData", data: [:])
|
|
168
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
169
|
+
didReceive: message)
|
|
170
|
+
|
|
171
|
+
// clearWebData is async (WKWebsiteDataStore removal) — allow extra time
|
|
172
|
+
wait(for: [exp], timeout: 5.0)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func testClearWebData_SuccessPayloadContainsSuccessTrue() {
|
|
176
|
+
let exp = expectation(description: "clearWebData success payload has success:true")
|
|
177
|
+
|
|
178
|
+
mockWebView.onEvaluateJavaScript = { script in
|
|
179
|
+
if script.contains("ON_WEB_DATA_CLEARED") {
|
|
180
|
+
XCTAssertTrue(script.contains("true"),
|
|
181
|
+
"success field should be true in cleared callback")
|
|
182
|
+
exp.fulfill()
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let message = createMessage(command: "clearWebData", data: [:])
|
|
187
|
+
bridge.userContentController(mockWebView.configuration.userContentController,
|
|
188
|
+
didReceive: message)
|
|
189
|
+
|
|
190
|
+
wait(for: [exp], timeout: 5.0)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
func testClearWebData_CommandAcceptedByValidator() {
|
|
194
|
+
// Validates command reaches the handler without being rejected by BridgeMessageValidator
|
|
195
|
+
let messageBody: [String: Any] = ["command": "clearWebData", "data": [:]]
|
|
196
|
+
let message = MockWKScriptMessage(name: "NativeBridge", body: messageBody)
|
|
197
|
+
let result = BridgeMessageValidator.validate(message: message)
|
|
198
|
+
|
|
199
|
+
XCTAssertTrue(result.isValid, "clearWebData should pass BridgeMessageValidator")
|
|
200
|
+
XCTAssertEqual(result.command, "clearWebData")
|
|
201
|
+
XCTAssertNil(result.error)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ============================================================
|
|
205
|
+
// Helpers
|
|
206
|
+
// ============================================================
|
|
207
|
+
|
|
208
|
+
private func createMessage(command: String, data: [String: Any]) -> WKScriptMessage {
|
|
209
|
+
let body: [String: Any] = ["command": command, "data": data]
|
|
210
|
+
return MockWKScriptMessage(name: "NativeBridge", body: body)
|
|
211
|
+
}
|
|
212
|
+
}
|