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,440 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import WebKit
|
|
3
|
+
import SwiftUI
|
|
4
|
+
@testable import CatalystCore
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Unit tests for WebView and WebViewNavigationDelegate
|
|
8
|
+
*
|
|
9
|
+
* Tests the main WebView wrapper and navigation handling logic.
|
|
10
|
+
* Mirrors Android CustomWebviewTest for cross-platform parity.
|
|
11
|
+
*
|
|
12
|
+
* Categories:
|
|
13
|
+
* 1. WebView Configuration (5 tests)
|
|
14
|
+
* 2. Navigation Handling (6 tests)
|
|
15
|
+
* 3. Resource Loading (4 tests)
|
|
16
|
+
* 4. State Management (3 tests)
|
|
17
|
+
*
|
|
18
|
+
* Total: 18 tests
|
|
19
|
+
*
|
|
20
|
+
* Testing Approach:
|
|
21
|
+
* - Tests focus on navigation delegate logic and view model state management
|
|
22
|
+
* - WKWebView itself is not fully instantiated (requires iOS runtime)
|
|
23
|
+
* - URL whitelisting integration is tested via URLWhitelistManager
|
|
24
|
+
* - Cache integration is tested via CacheManager mock
|
|
25
|
+
*/
|
|
26
|
+
final class WebViewTests: XCTestCase {
|
|
27
|
+
|
|
28
|
+
// Test fixtures
|
|
29
|
+
var viewModel: WebViewModel!
|
|
30
|
+
var navigationDelegate: WebViewNavigationDelegate!
|
|
31
|
+
var mockWebView: WKWebView!
|
|
32
|
+
|
|
33
|
+
@MainActor
|
|
34
|
+
override func setUp() async throws {
|
|
35
|
+
try await super.setUp()
|
|
36
|
+
|
|
37
|
+
// Create view model
|
|
38
|
+
viewModel = WebViewModel()
|
|
39
|
+
|
|
40
|
+
// Create navigation delegate
|
|
41
|
+
navigationDelegate = WebViewNavigationDelegate(viewModel: viewModel, initialURL: nil)
|
|
42
|
+
|
|
43
|
+
// Create a basic WKWebView for testing
|
|
44
|
+
let config = WKWebViewConfiguration()
|
|
45
|
+
mockWebView = WKWebView(frame: .zero, configuration: config)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@MainActor
|
|
49
|
+
override func tearDown() async throws {
|
|
50
|
+
viewModel = nil
|
|
51
|
+
navigationDelegate = nil
|
|
52
|
+
mockWebView = nil
|
|
53
|
+
try await super.tearDown()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ========================================
|
|
57
|
+
// CATEGORY 1: WebView Configuration (5 tests)
|
|
58
|
+
// ========================================
|
|
59
|
+
|
|
60
|
+
@MainActor
|
|
61
|
+
func testWebViewConfiguration_WKWebViewSetup() {
|
|
62
|
+
// Test that WKWebView is configured correctly
|
|
63
|
+
|
|
64
|
+
let config = WKWebViewConfiguration()
|
|
65
|
+
let webView = WKWebView(frame: .zero, configuration: config)
|
|
66
|
+
|
|
67
|
+
// Verify web view is created
|
|
68
|
+
XCTAssertNotNil(webView, "WKWebView should be created")
|
|
69
|
+
XCTAssertNotNil(webView.configuration, "WKWebView configuration should exist")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@MainActor
|
|
73
|
+
func testWebViewConfiguration_UserAgentConfiguration() {
|
|
74
|
+
// Test user agent string configuration
|
|
75
|
+
|
|
76
|
+
let config = WKWebViewConfiguration()
|
|
77
|
+
let webView = WKWebView(frame: .zero, configuration: config)
|
|
78
|
+
|
|
79
|
+
// Custom user agent can be set
|
|
80
|
+
webView.customUserAgent = "CustomUserAgent/1.0"
|
|
81
|
+
|
|
82
|
+
XCTAssertEqual(webView.customUserAgent, "CustomUserAgent/1.0",
|
|
83
|
+
"Custom user agent should be set correctly")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@MainActor
|
|
87
|
+
func testWebViewConfiguration_ContentControllerSetup() {
|
|
88
|
+
// Test that content controller is properly configured
|
|
89
|
+
|
|
90
|
+
let config = WKWebViewConfiguration()
|
|
91
|
+
let contentController = config.userContentController
|
|
92
|
+
|
|
93
|
+
XCTAssertNotNil(contentController, "User content controller should exist")
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@MainActor
|
|
97
|
+
func testWebViewConfiguration_NavigationDelegateAssignment() {
|
|
98
|
+
// Test that navigation delegate can be assigned
|
|
99
|
+
|
|
100
|
+
let config = WKWebViewConfiguration()
|
|
101
|
+
let webView = WKWebView(frame: .zero, configuration: config)
|
|
102
|
+
|
|
103
|
+
webView.navigationDelegate = navigationDelegate
|
|
104
|
+
|
|
105
|
+
XCTAssertNotNil(webView.navigationDelegate,
|
|
106
|
+
"Navigation delegate should be assigned")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@MainActor
|
|
110
|
+
func testWebViewConfiguration_JavaScriptEnabled() {
|
|
111
|
+
// Test that JavaScript is enabled in preferences
|
|
112
|
+
|
|
113
|
+
let config = WKWebViewConfiguration()
|
|
114
|
+
let preferences = WKWebpagePreferences()
|
|
115
|
+
preferences.allowsContentJavaScript = true
|
|
116
|
+
config.defaultWebpagePreferences = preferences
|
|
117
|
+
|
|
118
|
+
XCTAssertTrue(config.defaultWebpagePreferences.allowsContentJavaScript,
|
|
119
|
+
"JavaScript should be enabled")
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ========================================
|
|
123
|
+
// CATEGORY 2: Navigation Handling (6 tests)
|
|
124
|
+
// ========================================
|
|
125
|
+
|
|
126
|
+
@MainActor
|
|
127
|
+
func testNavigationHandling_AllowedURLLoading() async {
|
|
128
|
+
// Test that allowed URLs are permitted for navigation
|
|
129
|
+
|
|
130
|
+
let allowedURL = URL(string: "https://example.com")!
|
|
131
|
+
|
|
132
|
+
// Configure URLWhitelistManager to allow this URL
|
|
133
|
+
#if DEBUG
|
|
134
|
+
URLWhitelistManager.shared.testInitialize(
|
|
135
|
+
enabled: true,
|
|
136
|
+
allowedUrls: ["https://example.com*"]
|
|
137
|
+
)
|
|
138
|
+
#endif
|
|
139
|
+
|
|
140
|
+
let navigationAction = createNavigationAction(url: allowedURL)
|
|
141
|
+
let expectation = XCTestExpectation(description: "Navigation decision received")
|
|
142
|
+
var allowedDecision = false
|
|
143
|
+
|
|
144
|
+
navigationDelegate.webView(mockWebView,
|
|
145
|
+
decidePolicyFor: navigationAction) { policy in
|
|
146
|
+
allowedDecision = (policy == .allow)
|
|
147
|
+
expectation.fulfill()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
await fulfillment(of: [expectation], timeout: 2.0)
|
|
151
|
+
|
|
152
|
+
XCTAssertTrue(allowedDecision || !URLWhitelistManager.shared.isAccessControlEnabled,
|
|
153
|
+
"Allowed URL should be permitted")
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@MainActor
|
|
157
|
+
func testNavigationHandling_BlockedURLNavigation() async {
|
|
158
|
+
// Test that blocked URLs are rejected
|
|
159
|
+
|
|
160
|
+
let blockedURL = URL(string: "https://blocked.com")!
|
|
161
|
+
|
|
162
|
+
// Configure URLWhitelistManager to block this URL
|
|
163
|
+
#if DEBUG
|
|
164
|
+
URLWhitelistManager.shared.testInitialize(
|
|
165
|
+
enabled: true,
|
|
166
|
+
allowedUrls: ["https://allowed.com*"]
|
|
167
|
+
)
|
|
168
|
+
#endif
|
|
169
|
+
|
|
170
|
+
let navigationAction = createNavigationAction(url: blockedURL)
|
|
171
|
+
let expectation = XCTestExpectation(description: "Navigation decision received")
|
|
172
|
+
var blockedDecision = false
|
|
173
|
+
|
|
174
|
+
navigationDelegate.webView(mockWebView,
|
|
175
|
+
decidePolicyFor: navigationAction) { policy in
|
|
176
|
+
blockedDecision = (policy == .cancel)
|
|
177
|
+
expectation.fulfill()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
await fulfillment(of: [expectation], timeout: 2.0)
|
|
181
|
+
|
|
182
|
+
XCTAssertTrue(blockedDecision, "Blocked URL should be cancelled")
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@MainActor
|
|
186
|
+
func testNavigationHandling_ExternalDomainHandling() {
|
|
187
|
+
// Test that external domains are detected and handled
|
|
188
|
+
|
|
189
|
+
let externalURL = URL(string: "https://external.com")!
|
|
190
|
+
|
|
191
|
+
// Enable access control with limited allowed URLs
|
|
192
|
+
#if DEBUG
|
|
193
|
+
URLWhitelistManager.shared.testInitialize(
|
|
194
|
+
enabled: true,
|
|
195
|
+
allowedUrls: ["https://myapp.com*"]
|
|
196
|
+
)
|
|
197
|
+
#endif
|
|
198
|
+
|
|
199
|
+
// Check if URL is external
|
|
200
|
+
let isExternal = URLWhitelistManager.shared.isExternalDomain(externalURL)
|
|
201
|
+
|
|
202
|
+
XCTAssertTrue(isExternal,
|
|
203
|
+
"URL outside allowed patterns should be detected as external")
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@MainActor
|
|
207
|
+
func testNavigationHandling_URLWhitelistIntegration() {
|
|
208
|
+
// Test integration with URLWhitelistManager
|
|
209
|
+
|
|
210
|
+
let testURL = URL(string: "https://test.com/page")!
|
|
211
|
+
|
|
212
|
+
// Configure whitelist
|
|
213
|
+
#if DEBUG
|
|
214
|
+
URLWhitelistManager.shared.testInitialize(
|
|
215
|
+
enabled: true,
|
|
216
|
+
allowedUrls: ["https://test.com*"]
|
|
217
|
+
)
|
|
218
|
+
#endif
|
|
219
|
+
|
|
220
|
+
let isAllowed = URLWhitelistManager.shared.isUrlAllowed(testURL)
|
|
221
|
+
|
|
222
|
+
XCTAssertTrue(isAllowed, "URL matching whitelist pattern should be allowed")
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@MainActor
|
|
226
|
+
func testNavigationHandling_LocalhostFrameworkURLBypass() {
|
|
227
|
+
// Test that localhost framework URLs bypass access control
|
|
228
|
+
|
|
229
|
+
let frameworkURL = URL(string: "https://localhost:8080/framework-server/file.pdf")!
|
|
230
|
+
|
|
231
|
+
// Enable strict access control
|
|
232
|
+
#if DEBUG
|
|
233
|
+
URLWhitelistManager.shared.testInitialize(
|
|
234
|
+
enabled: true,
|
|
235
|
+
allowedUrls: ["https://myapp.com*"]
|
|
236
|
+
)
|
|
237
|
+
#endif
|
|
238
|
+
|
|
239
|
+
let isAllowed = URLWhitelistManager.shared.isUrlAllowed(frameworkURL)
|
|
240
|
+
|
|
241
|
+
XCTAssertTrue(isAllowed,
|
|
242
|
+
"Localhost framework URLs should bypass access control")
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@MainActor
|
|
246
|
+
func testNavigationHandling_SpecialURLSchemeDetection() {
|
|
247
|
+
// Test that special URL schemes (tel:, mailto:, sms:) are detected
|
|
248
|
+
|
|
249
|
+
let telURL = URL(string: "tel:1234567890")!
|
|
250
|
+
let mailtoURL = URL(string: "mailto:test@example.com")!
|
|
251
|
+
let smsURL = URL(string: "sms:1234567890")!
|
|
252
|
+
|
|
253
|
+
XCTAssertEqual(telURL.scheme, "tel", "Tel URL scheme should be detected")
|
|
254
|
+
XCTAssertEqual(mailtoURL.scheme, "mailto", "Mailto URL scheme should be detected")
|
|
255
|
+
XCTAssertEqual(smsURL.scheme, "sms", "SMS URL scheme should be detected")
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ========================================
|
|
259
|
+
// CATEGORY 3: Resource Loading (4 tests)
|
|
260
|
+
// ========================================
|
|
261
|
+
|
|
262
|
+
@MainActor
|
|
263
|
+
func testResourceLoading_CachePatternMatching_CSS() {
|
|
264
|
+
// Test cache pattern matching for CSS files
|
|
265
|
+
|
|
266
|
+
let cssURL = URL(string: "https://myapp.com/static/styles.abc123.css")!
|
|
267
|
+
let cssWithQuery = URL(string: "https://myapp.com/styles.css?v=1.0")!
|
|
268
|
+
|
|
269
|
+
// Configure cache manager to recognize CSS patterns
|
|
270
|
+
let shouldCacheCSS = CacheManager.shared.shouldCacheURL(cssURL)
|
|
271
|
+
let shouldCacheCSSQuery = CacheManager.shared.shouldCacheURL(cssWithQuery)
|
|
272
|
+
|
|
273
|
+
// Cache manager should handle CSS files based on configured patterns
|
|
274
|
+
XCTAssertNotNil(shouldCacheCSS, "Cache manager should process CSS URLs")
|
|
275
|
+
XCTAssertNotNil(shouldCacheCSSQuery, "Cache manager should process CSS URLs with query")
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@MainActor
|
|
279
|
+
func testResourceLoading_CachePatternMatching_JavaScript() {
|
|
280
|
+
// Test cache pattern matching for JavaScript files
|
|
281
|
+
|
|
282
|
+
let jsURL = URL(string: "https://myapp.com/static/app.xyz789.js")!
|
|
283
|
+
let jsWithQuery = URL(string: "https://myapp.com/bundle.js?v=2.0")!
|
|
284
|
+
|
|
285
|
+
let shouldCacheJS = CacheManager.shared.shouldCacheURL(jsURL)
|
|
286
|
+
let shouldCacheJSQuery = CacheManager.shared.shouldCacheURL(jsWithQuery)
|
|
287
|
+
|
|
288
|
+
// Cache manager should handle JS files based on configured patterns
|
|
289
|
+
XCTAssertNotNil(shouldCacheJS, "Cache manager should process JS URLs")
|
|
290
|
+
XCTAssertNotNil(shouldCacheJSQuery, "Cache manager should process JS URLs with query")
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@MainActor
|
|
294
|
+
func testResourceLoading_APICallDetection() {
|
|
295
|
+
// Test API call detection logic
|
|
296
|
+
|
|
297
|
+
let apiURL = URL(string: "https://api.myapp.com/v1/users")!
|
|
298
|
+
let apiWithQuery = URL(string: "https://myapp.com/api/data?id=123")!
|
|
299
|
+
|
|
300
|
+
// API URLs typically shouldn't be cached (or have different cache rules)
|
|
301
|
+
let host = apiURL.host ?? ""
|
|
302
|
+
let path = apiURL.path
|
|
303
|
+
|
|
304
|
+
let isAPIHost = host.contains("api.")
|
|
305
|
+
let isAPIPath = path.contains("/api/")
|
|
306
|
+
|
|
307
|
+
XCTAssertTrue(isAPIHost || isAPIPath,
|
|
308
|
+
"API URLs should be detectable by host or path")
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@MainActor
|
|
312
|
+
func testResourceLoading_StaticResourceDetection() {
|
|
313
|
+
// Test static resource detection by extension
|
|
314
|
+
|
|
315
|
+
let imageURL = URL(string: "https://myapp.com/images/logo.png")!
|
|
316
|
+
let fontURL = URL(string: "https://myapp.com/fonts/roboto.woff2")!
|
|
317
|
+
let htmlURL = URL(string: "https://myapp.com/page.html")!
|
|
318
|
+
|
|
319
|
+
let imageExt = imageURL.pathExtension.lowercased()
|
|
320
|
+
let fontExt = fontURL.pathExtension.lowercased()
|
|
321
|
+
let htmlExt = htmlURL.pathExtension.lowercased()
|
|
322
|
+
|
|
323
|
+
XCTAssertEqual(imageExt, "png", "Image extension should be detected")
|
|
324
|
+
XCTAssertEqual(fontExt, "woff2", "Font extension should be detected")
|
|
325
|
+
XCTAssertEqual(htmlExt, "html", "HTML extension should be detected")
|
|
326
|
+
|
|
327
|
+
// Common static resource extensions
|
|
328
|
+
let staticExtensions = ["png", "jpg", "jpeg", "gif", "svg", "css", "js",
|
|
329
|
+
"woff", "woff2", "ttf", "eot"]
|
|
330
|
+
let isImageStatic = staticExtensions.contains(imageExt)
|
|
331
|
+
let isFontStatic = staticExtensions.contains(fontExt)
|
|
332
|
+
|
|
333
|
+
XCTAssertTrue(isImageStatic, "Image should be recognized as static resource")
|
|
334
|
+
XCTAssertTrue(isFontStatic, "Font should be recognized as static resource")
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ========================================
|
|
338
|
+
// CATEGORY 4: State Management (3 tests)
|
|
339
|
+
// ========================================
|
|
340
|
+
|
|
341
|
+
@MainActor
|
|
342
|
+
func testStateManagement_LoadingStateTracking() {
|
|
343
|
+
// Test that loading state is tracked correctly
|
|
344
|
+
|
|
345
|
+
// Initial state
|
|
346
|
+
XCTAssertTrue(viewModel.isLoading, "Should start in loading state")
|
|
347
|
+
|
|
348
|
+
// Start loading
|
|
349
|
+
viewModel.setLoading(true, fromCache: false)
|
|
350
|
+
XCTAssertTrue(viewModel.isLoading, "Should be loading")
|
|
351
|
+
XCTAssertFalse(viewModel.isLoadingFromCache, "Should not be from cache")
|
|
352
|
+
|
|
353
|
+
// Finish loading
|
|
354
|
+
viewModel.setLoading(false, fromCache: false)
|
|
355
|
+
XCTAssertEqual(viewModel.loadingProgress, 1.0,
|
|
356
|
+
"Progress should be 1.0 when loading finishes")
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
@MainActor
|
|
360
|
+
func testStateManagement_ProgressObservation() {
|
|
361
|
+
// Test that progress is tracked correctly
|
|
362
|
+
|
|
363
|
+
// Initial progress
|
|
364
|
+
XCTAssertEqual(viewModel.loadingProgress, 0.0,
|
|
365
|
+
"Initial progress should be 0")
|
|
366
|
+
|
|
367
|
+
// Update progress
|
|
368
|
+
viewModel.setProgress(0.5)
|
|
369
|
+
XCTAssertEqual(viewModel.loadingProgress, 0.5,
|
|
370
|
+
"Progress should be updated to 0.5")
|
|
371
|
+
|
|
372
|
+
viewModel.setProgress(0.75)
|
|
373
|
+
XCTAssertEqual(viewModel.loadingProgress, 0.75,
|
|
374
|
+
"Progress should be updated to 0.75")
|
|
375
|
+
|
|
376
|
+
viewModel.setProgress(1.0)
|
|
377
|
+
XCTAssertEqual(viewModel.loadingProgress, 1.0,
|
|
378
|
+
"Progress should reach 1.0")
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
@MainActor
|
|
382
|
+
func testStateManagement_ErrorStateHandling() {
|
|
383
|
+
// Test that error state resets properly
|
|
384
|
+
|
|
385
|
+
// Set to loading state
|
|
386
|
+
viewModel.setLoading(true, fromCache: false)
|
|
387
|
+
viewModel.setProgress(0.5)
|
|
388
|
+
|
|
389
|
+
// Simulate error by resetting
|
|
390
|
+
viewModel.reset()
|
|
391
|
+
|
|
392
|
+
// Verify state is reset
|
|
393
|
+
XCTAssertFalse(viewModel.isLoading, "Should not be loading after reset")
|
|
394
|
+
XCTAssertEqual(viewModel.loadingProgress, 0,
|
|
395
|
+
"Progress should be 0 after reset")
|
|
396
|
+
XCTAssertFalse(viewModel.isLoadingFromCache,
|
|
397
|
+
"Should not be loading from cache after reset")
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ========================================
|
|
401
|
+
// Helper Methods
|
|
402
|
+
// ========================================
|
|
403
|
+
|
|
404
|
+
private func createNavigationAction(url: URL) -> WKNavigationAction {
|
|
405
|
+
// Create a mock navigation action
|
|
406
|
+
// Note: WKNavigationAction cannot be directly instantiated, so we use a workaround
|
|
407
|
+
// by creating a URLRequest and using the web view's load method
|
|
408
|
+
|
|
409
|
+
let request = URLRequest(url: url)
|
|
410
|
+
|
|
411
|
+
// Create a temporary web view to generate a navigation action
|
|
412
|
+
let tempWebView = WKWebView(frame: .zero)
|
|
413
|
+
tempWebView.load(request)
|
|
414
|
+
|
|
415
|
+
// In practice, we rely on the delegate being called with real navigation actions
|
|
416
|
+
// For testing, we verify the logic with URL directly
|
|
417
|
+
|
|
418
|
+
// Return a mock object - in actual tests, we verify the decision handler logic
|
|
419
|
+
// through integration with URLWhitelistManager
|
|
420
|
+
return MockNavigationAction(request: request)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ========================================
|
|
425
|
+
// Mock Objects
|
|
426
|
+
// ========================================
|
|
427
|
+
|
|
428
|
+
/// Mock navigation action for testing
|
|
429
|
+
private class MockNavigationAction: WKNavigationAction {
|
|
430
|
+
private let mockRequest: URLRequest
|
|
431
|
+
|
|
432
|
+
init(request: URLRequest) {
|
|
433
|
+
self.mockRequest = request
|
|
434
|
+
super.init()
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
override var request: URLRequest {
|
|
438
|
+
return mockRequest
|
|
439
|
+
}
|
|
440
|
+
}
|