@native-sdk/cli 0.0.0 → 0.4.1
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/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const std = support.std;
|
|
3
|
+
const geometry = support.geometry;
|
|
4
|
+
const trace = support.trace;
|
|
5
|
+
const json = support.json;
|
|
6
|
+
const canvas = support.canvas;
|
|
7
|
+
const automation = support.automation;
|
|
8
|
+
const bridge = support.bridge;
|
|
9
|
+
const app_manifest = support.app_manifest;
|
|
10
|
+
const platform = support.platform;
|
|
11
|
+
const security = support.security;
|
|
12
|
+
const extensions = support.extensions;
|
|
13
|
+
const window_state = support.window_state;
|
|
14
|
+
const runtime_module = support.runtime_module;
|
|
15
|
+
const bridge_payload = support.bridge_payload;
|
|
16
|
+
const canvas_frame = support.canvas_frame;
|
|
17
|
+
const App = support.App;
|
|
18
|
+
const Runtime = support.Runtime;
|
|
19
|
+
const Options = support.Options;
|
|
20
|
+
const Event = support.Event;
|
|
21
|
+
const LifecycleEvent = support.LifecycleEvent;
|
|
22
|
+
const CommandEvent = support.CommandEvent;
|
|
23
|
+
const Command = support.Command;
|
|
24
|
+
const CommandSource = support.CommandSource;
|
|
25
|
+
const FrameDiagnostics = support.FrameDiagnostics;
|
|
26
|
+
const ShortcutEvent = support.ShortcutEvent;
|
|
27
|
+
const Appearance = support.Appearance;
|
|
28
|
+
const GpuFrame = support.GpuFrame;
|
|
29
|
+
const GpuSurfaceFrameEvent = support.GpuSurfaceFrameEvent;
|
|
30
|
+
const GpuSurfaceResizeEvent = support.GpuSurfaceResizeEvent;
|
|
31
|
+
const GpuSurfaceInputEvent = support.GpuSurfaceInputEvent;
|
|
32
|
+
const CanvasWidgetPointerEvent = support.CanvasWidgetPointerEvent;
|
|
33
|
+
const CanvasWidgetKeyboardEvent = support.CanvasWidgetKeyboardEvent;
|
|
34
|
+
const CanvasWidgetDisplayListChrome = support.CanvasWidgetDisplayListChrome;
|
|
35
|
+
const CanvasPresentationMode = support.CanvasPresentationMode;
|
|
36
|
+
const CanvasPresentationResult = support.CanvasPresentationResult;
|
|
37
|
+
const CanvasWidgetAccessibilityActionKind = support.CanvasWidgetAccessibilityActionKind;
|
|
38
|
+
const CanvasWidgetAccessibilityAction = support.CanvasWidgetAccessibilityAction;
|
|
39
|
+
const CanvasWidgetFileDropEvent = support.CanvasWidgetFileDropEvent;
|
|
40
|
+
const CanvasWidgetDragEvent = support.CanvasWidgetDragEvent;
|
|
41
|
+
const InvalidationReason = support.InvalidationReason;
|
|
42
|
+
const TestHarness = support.TestHarness;
|
|
43
|
+
const max_canvas_commands_per_view = support.max_canvas_commands_per_view;
|
|
44
|
+
const max_canvas_widget_nodes_per_view = support.max_canvas_widget_nodes_per_view;
|
|
45
|
+
const jsonStringField = support.jsonStringField;
|
|
46
|
+
const jsonNumberField = support.jsonNumberField;
|
|
47
|
+
const jsonBoolField = support.jsonBoolField;
|
|
48
|
+
const canvasRenderAnimationFinalOverrideNoop = support.canvasRenderAnimationFinalOverrideNoop;
|
|
49
|
+
const copyInto = support.copyInto;
|
|
50
|
+
const writeViewJson = support.writeViewJson;
|
|
51
|
+
const canvasFrameScratchStorage = support.canvasFrameScratchStorage;
|
|
52
|
+
const runtimeViewInfo = support.runtimeViewInfo;
|
|
53
|
+
const runtimeViewCanvasFrameRenderOverrides = support.runtimeViewCanvasFrameRenderOverrides;
|
|
54
|
+
const runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides = support.runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides;
|
|
55
|
+
const runtimeViewWidgetSemantics = support.runtimeViewWidgetSemantics;
|
|
56
|
+
const runtimeViewSetCanvasWidgetSelected = support.runtimeViewSetCanvasWidgetSelected;
|
|
57
|
+
const runtimeViewCanvasWidgetDirtyBounds = support.runtimeViewCanvasWidgetDirtyBounds;
|
|
58
|
+
const dispatchAutomationWidgetAction = support.dispatchAutomationWidgetAction;
|
|
59
|
+
const shellBoundsForWindow = support.shellBoundsForWindow;
|
|
60
|
+
const reloadWindows = support.reloadWindows;
|
|
61
|
+
const canvasWidgetSemanticsById = support.canvasWidgetSemanticsById;
|
|
62
|
+
const platformWidgetAccessibilityNodeById = support.platformWidgetAccessibilityNodeById;
|
|
63
|
+
const builtinBridgeErrorCode = support.builtinBridgeErrorCode;
|
|
64
|
+
const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
|
|
65
|
+
const testViewByLabel = support.testViewByLabel;
|
|
66
|
+
const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
|
|
67
|
+
|
|
68
|
+
test "runtime handles built-in JavaScript webview bridge commands" {
|
|
69
|
+
const TestApp = struct {
|
|
70
|
+
fn app(self: *@This()) App {
|
|
71
|
+
return .{ .context = self, .name = "webview-bridge", .source = platform.WebViewSource.html("<p>WebView</p>") };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
76
|
+
defer harness.destroy(std.testing.allocator);
|
|
77
|
+
harness.runtime.options.js_window_api = true;
|
|
78
|
+
const webview_origins = [_][]const u8{ "zero://inline", "https://example.com", "https://example.org" };
|
|
79
|
+
harness.runtime.options.security.navigation.allowed_origins = &webview_origins;
|
|
80
|
+
var app_state: TestApp = .{};
|
|
81
|
+
try harness.start(app_state.app());
|
|
82
|
+
|
|
83
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
84
|
+
.bytes = "{\"id\":\"1\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.com\",\"frame\":{\"x\":10,\"y\":20,\"width\":300,\"height\":200},\"layer\":2,\"transparent\":true,\"bridge\":false}}",
|
|
85
|
+
.origin = "zero://inline",
|
|
86
|
+
.window_id = 1,
|
|
87
|
+
} });
|
|
88
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
89
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.webview_count);
|
|
90
|
+
try std.testing.expectEqualStrings("preview", harness.null_platform.webviews[0].label);
|
|
91
|
+
try std.testing.expectEqualStrings("https://example.com", harness.null_platform.webviews[0].url);
|
|
92
|
+
try std.testing.expectEqual(@as(i32, 2), harness.null_platform.webviews[0].layer);
|
|
93
|
+
try std.testing.expect(harness.null_platform.webviews[0].transparent);
|
|
94
|
+
try std.testing.expect(!harness.null_platform.webviews[0].bridge_enabled);
|
|
95
|
+
|
|
96
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
97
|
+
.bytes = "{\"id\":\"2\",\"command\":\"native-sdk.webview.setFrame\",\"payload\":{\"label\":\"preview\",\"frame\":{\"x\":11,\"y\":22,\"width\":333,\"height\":222}}}",
|
|
98
|
+
.origin = "zero://inline",
|
|
99
|
+
.window_id = 1,
|
|
100
|
+
} });
|
|
101
|
+
try std.testing.expectEqual(@as(f32, 333), harness.null_platform.webviews[0].frame.width);
|
|
102
|
+
|
|
103
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
104
|
+
.bytes = "{\"id\":\"3\",\"command\":\"native-sdk.webview.navigate\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.org\"}}",
|
|
105
|
+
.origin = "zero://inline",
|
|
106
|
+
.window_id = 1,
|
|
107
|
+
} });
|
|
108
|
+
try std.testing.expectEqualStrings("https://example.org", harness.null_platform.webviews[0].url);
|
|
109
|
+
|
|
110
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
111
|
+
.bytes = "{\"id\":\"4\",\"command\":\"native-sdk.webview.setZoom\",\"payload\":{\"label\":\"preview\",\"zoom\":1.25}}",
|
|
112
|
+
.origin = "zero://inline",
|
|
113
|
+
.window_id = 1,
|
|
114
|
+
} });
|
|
115
|
+
try std.testing.expectEqual(@as(f64, 1.25), harness.null_platform.webviews[0].zoom);
|
|
116
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"zoom\":1.25") != null);
|
|
117
|
+
|
|
118
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
119
|
+
.bytes = "{\"id\":\"5\",\"command\":\"native-sdk.webview.setLayer\",\"payload\":{\"label\":\"preview\",\"layer\":10}}",
|
|
120
|
+
.origin = "zero://inline",
|
|
121
|
+
.window_id = 1,
|
|
122
|
+
} });
|
|
123
|
+
try std.testing.expectEqual(@as(i32, 10), harness.null_platform.webviews[0].layer);
|
|
124
|
+
|
|
125
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
126
|
+
.bytes = "{\"id\":\"6\",\"command\":\"native-sdk.webview.list\",\"payload\":{}}",
|
|
127
|
+
.origin = "zero://inline",
|
|
128
|
+
.window_id = 1,
|
|
129
|
+
} });
|
|
130
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
131
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"url\":\"zero://inline\"") != null);
|
|
132
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"layer\":10") != null);
|
|
133
|
+
|
|
134
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
135
|
+
.bytes = "{\"id\":\"7\",\"command\":\"native-sdk.webview.setFrame\",\"payload\":{\"label\":\"main\",\"frame\":{\"x\":0,\"y\":0,\"width\":640,\"height\":80}}}",
|
|
136
|
+
.origin = "zero://inline",
|
|
137
|
+
.window_id = 1,
|
|
138
|
+
} });
|
|
139
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
140
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"height\":80") != null);
|
|
141
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"zoom\":1") != null);
|
|
142
|
+
|
|
143
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
144
|
+
.bytes = "{\"id\":\"8\",\"command\":\"native-sdk.webview.setZoom\",\"payload\":{\"label\":\"main\",\"zoom\":1.1}}",
|
|
145
|
+
.origin = "zero://inline",
|
|
146
|
+
.window_id = 1,
|
|
147
|
+
} });
|
|
148
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
149
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"height\":80") != null);
|
|
150
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"zoom\":1.1") != null);
|
|
151
|
+
|
|
152
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
153
|
+
.bytes = "{\"id\":\"9\",\"command\":\"native-sdk.webview.list\",\"payload\":{}}",
|
|
154
|
+
.origin = "zero://inline",
|
|
155
|
+
.window_id = 1,
|
|
156
|
+
.webview_label = "preview",
|
|
157
|
+
} });
|
|
158
|
+
try std.testing.expectEqualStrings("preview", harness.null_platform.lastBridgeResponseWebViewLabel());
|
|
159
|
+
|
|
160
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
161
|
+
.bytes = "{\"id\":\"9\",\"command\":\"native-sdk.webview.list\",\"payload\":{}}",
|
|
162
|
+
.origin = "zero://inline",
|
|
163
|
+
.window_id = 1,
|
|
164
|
+
.webview_label = "main",
|
|
165
|
+
} });
|
|
166
|
+
try std.testing.expectEqualStrings("main", harness.null_platform.lastBridgeResponseWebViewLabel());
|
|
167
|
+
|
|
168
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
169
|
+
.bytes = "{\"id\":\"10\",\"command\":\"native-sdk.webview.close\",\"payload\":{\"label\":\"preview\"}}",
|
|
170
|
+
.origin = "zero://inline",
|
|
171
|
+
.window_id = 1,
|
|
172
|
+
} });
|
|
173
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.webview_count);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
test "runtime handles built-in JavaScript view bridge commands" {
|
|
177
|
+
const TestApp = struct {
|
|
178
|
+
command_count: u32 = 0,
|
|
179
|
+
last_command: []const u8 = "",
|
|
180
|
+
last_source: CommandSource = .runtime,
|
|
181
|
+
last_view_label: []const u8 = "",
|
|
182
|
+
|
|
183
|
+
fn app(self: *@This()) App {
|
|
184
|
+
return .{ .context = self, .name = "view-bridge", .source = platform.WebViewSource.html("<p>Views</p>"), .event_fn = event };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
188
|
+
_ = runtime;
|
|
189
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
190
|
+
switch (event_value) {
|
|
191
|
+
.command => |command| {
|
|
192
|
+
self.command_count += 1;
|
|
193
|
+
self.last_command = command.name;
|
|
194
|
+
self.last_source = command.source;
|
|
195
|
+
self.last_view_label = command.view_label;
|
|
196
|
+
},
|
|
197
|
+
else => {},
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
203
|
+
defer harness.destroy(std.testing.allocator);
|
|
204
|
+
harness.runtime.options.js_window_api = true;
|
|
205
|
+
const view_origins = [_][]const u8{ "zero://inline", "zero://app" };
|
|
206
|
+
harness.runtime.options.security.navigation.allowed_origins = &view_origins;
|
|
207
|
+
var app_state: TestApp = .{};
|
|
208
|
+
try harness.start(app_state.app());
|
|
209
|
+
|
|
210
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
211
|
+
.bytes = "{\"id\":\"1\",\"command\":\"native-sdk.view.create\",\"payload\":{\"label\":\"toolbar\",\"kind\":\"toolbar\",\"frame\":{\"x\":0,\"y\":0,\"width\":640,\"height\":44},\"role\":\"toolbar\",\"accessibilityLabel\":\"Main tools\",\"text\":\"Tools\",\"command\":\"app.tools\",\"layer\":3}}",
|
|
212
|
+
.origin = "zero://inline",
|
|
213
|
+
.window_id = 1,
|
|
214
|
+
} });
|
|
215
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
216
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"id\":") != null);
|
|
217
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"kind\":\"toolbar\"") != null);
|
|
218
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"accessibilityLabel\":\"Main tools\"") != null);
|
|
219
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"text\":\"Tools\"") != null);
|
|
220
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"command\":\"app.tools\"") != null);
|
|
221
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.view_count);
|
|
222
|
+
try std.testing.expectEqualStrings("Main tools", harness.null_platform.views[0].accessibility_label);
|
|
223
|
+
try std.testing.expectEqualStrings("app.tools", harness.null_platform.views[0].command);
|
|
224
|
+
|
|
225
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .native_command = .{
|
|
226
|
+
.name = "app.tools",
|
|
227
|
+
.window_id = 1,
|
|
228
|
+
.view_label = "toolbar",
|
|
229
|
+
} });
|
|
230
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
231
|
+
try std.testing.expectEqualStrings("app.tools", app_state.last_command);
|
|
232
|
+
try std.testing.expectEqual(CommandSource.toolbar, app_state.last_source);
|
|
233
|
+
try std.testing.expectEqualStrings("toolbar", app_state.last_view_label);
|
|
234
|
+
|
|
235
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
236
|
+
.bytes = "{\"id\":\"2\",\"command\":\"native-sdk.view.list\",\"payload\":{}}",
|
|
237
|
+
.origin = "zero://inline",
|
|
238
|
+
.window_id = 1,
|
|
239
|
+
} });
|
|
240
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
241
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"toolbar\"") != null);
|
|
242
|
+
|
|
243
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
244
|
+
.bytes = "{\"id\":\"3\",\"command\":\"native-sdk.view.focus\",\"payload\":{\"label\":\"toolbar\"}}",
|
|
245
|
+
.origin = "zero://inline",
|
|
246
|
+
.window_id = 1,
|
|
247
|
+
} });
|
|
248
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"toolbar\"") != null);
|
|
249
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
|
|
250
|
+
|
|
251
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
252
|
+
.bytes = "{\"id\":\"3-next\",\"command\":\"native-sdk.view.focusNext\",\"payload\":{}}",
|
|
253
|
+
.origin = "zero://inline",
|
|
254
|
+
.window_id = 1,
|
|
255
|
+
} });
|
|
256
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
257
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
|
|
258
|
+
|
|
259
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
260
|
+
.bytes = "{\"id\":\"3-prev\",\"command\":\"native-sdk.view.focusPrevious\",\"payload\":{}}",
|
|
261
|
+
.origin = "zero://inline",
|
|
262
|
+
.window_id = 1,
|
|
263
|
+
} });
|
|
264
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"toolbar\"") != null);
|
|
265
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
|
|
266
|
+
|
|
267
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
268
|
+
.bytes = "{\"id\":\"4\",\"command\":\"native-sdk.view.setFrame\",\"payload\":{\"label\":\"toolbar\",\"frame\":{\"x\":0,\"y\":0,\"width\":640,\"height\":52}}}",
|
|
269
|
+
.origin = "zero://inline",
|
|
270
|
+
.window_id = 1,
|
|
271
|
+
} });
|
|
272
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"height\":52") != null);
|
|
273
|
+
|
|
274
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
275
|
+
.bytes = "{\"id\":\"5\",\"command\":\"native-sdk.view.setVisible\",\"payload\":{\"label\":\"toolbar\",\"visible\":false}}",
|
|
276
|
+
.origin = "zero://inline",
|
|
277
|
+
.window_id = 1,
|
|
278
|
+
} });
|
|
279
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"visible\":false") != null);
|
|
280
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":false") != null);
|
|
281
|
+
|
|
282
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
283
|
+
.bytes = "{\"id\":\"5-list\",\"command\":\"native-sdk.view.list\",\"payload\":{}}",
|
|
284
|
+
.origin = "zero://inline",
|
|
285
|
+
.window_id = 1,
|
|
286
|
+
} });
|
|
287
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"main\"") != null);
|
|
288
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
|
|
289
|
+
|
|
290
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
291
|
+
.bytes = "{\"id\":\"6\",\"command\":\"native-sdk.view.update\",\"payload\":{\"label\":\"toolbar\",\"visible\":true,\"enabled\":false,\"role\":\"banner\",\"accessibilityLabel\":\"Primary actions\",\"text\":\"Actions\",\"command\":\"app.actions\"}}",
|
|
292
|
+
.origin = "zero://inline",
|
|
293
|
+
.window_id = 1,
|
|
294
|
+
} });
|
|
295
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"enabled\":false") != null);
|
|
296
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"role\":\"banner\"") != null);
|
|
297
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"accessibilityLabel\":\"Primary actions\"") != null);
|
|
298
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"text\":\"Actions\"") != null);
|
|
299
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"command\":\"app.actions\"") != null);
|
|
300
|
+
try std.testing.expectEqualStrings("Primary actions", harness.null_platform.views[0].accessibility_label);
|
|
301
|
+
try std.testing.expectEqualStrings("app.actions", harness.null_platform.views[0].command);
|
|
302
|
+
|
|
303
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
304
|
+
.bytes = "{\"id\":\"7\",\"command\":\"native-sdk.view.close\",\"payload\":{\"label\":\"toolbar\"}}",
|
|
305
|
+
.origin = "zero://inline",
|
|
306
|
+
.window_id = 1,
|
|
307
|
+
} });
|
|
308
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"open\":false") != null);
|
|
309
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":false") != null);
|
|
310
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.view_count);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
test "runtime handles GPU surface options in JavaScript view bridge commands" {
|
|
314
|
+
const TestApp = struct {
|
|
315
|
+
fn app(self: *@This()) App {
|
|
316
|
+
return .{ .context = self, .name = "gpu-view-bridge", .source = platform.WebViewSource.html("<p>GPU</p>") };
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
321
|
+
defer harness.destroy(std.testing.allocator);
|
|
322
|
+
harness.null_platform.gpu_surfaces = true;
|
|
323
|
+
harness.runtime.options.js_window_api = true;
|
|
324
|
+
const view_origins = [_][]const u8{ "zero://inline", "zero://app" };
|
|
325
|
+
harness.runtime.options.security.navigation.allowed_origins = &view_origins;
|
|
326
|
+
var app_state: TestApp = .{};
|
|
327
|
+
try harness.start(app_state.app());
|
|
328
|
+
|
|
329
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
330
|
+
.bytes = "{\"id\":\"gpu\",\"command\":\"native-sdk.view.create\",\"payload\":{\"label\":\"canvas\",\"kind\":\"gpuSurface\",\"frame\":{\"width\":320,\"height\":240},\"gpuBackend\":\"metal\",\"gpuPixelFormat\":\"bgra8_unorm\",\"gpuPresentMode\":\"timer\",\"gpuAlphaMode\":\"opaque\",\"gpuColorSpace\":\"srgb\",\"gpuVsync\":true}}",
|
|
331
|
+
.origin = "zero://inline",
|
|
332
|
+
.window_id = 1,
|
|
333
|
+
} });
|
|
334
|
+
const response = harness.null_platform.lastBridgeResponse();
|
|
335
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"ok\":true") != null);
|
|
336
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"kind\":\"gpu_surface\"") != null);
|
|
337
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuBackend\":\"metal\"") != null);
|
|
338
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuPixelFormat\":\"bgra8_unorm\"") != null);
|
|
339
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuPresentMode\":\"timer\"") != null);
|
|
340
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuAlphaMode\":\"opaque\"") != null);
|
|
341
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuColorSpace\":\"srgb\"") != null);
|
|
342
|
+
try std.testing.expect(std.mem.indexOf(u8, response, "\"gpuVsync\":true") != null);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
test "runtime gates JavaScript view API with view permission" {
|
|
346
|
+
const TestApp = struct {
|
|
347
|
+
fn app(self: *@This()) App {
|
|
348
|
+
return .{ .context = self, .name = "view-permission", .source = platform.WebViewSource.html("<p>Views</p>") };
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const view_permission = [_][]const u8{security.permission_view};
|
|
353
|
+
const allowed = try TestHarness().create(std.testing.allocator, .{});
|
|
354
|
+
defer allowed.destroy(std.testing.allocator);
|
|
355
|
+
allowed.runtime.options.js_window_api = true;
|
|
356
|
+
allowed.runtime.options.security.permissions = &view_permission;
|
|
357
|
+
var app_state: TestApp = .{};
|
|
358
|
+
try allowed.start(app_state.app());
|
|
359
|
+
try allowed.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
360
|
+
.bytes = "{\"id\":\"allowed\",\"command\":\"native-sdk.view.list\",\"payload\":{}}",
|
|
361
|
+
.origin = "zero://inline",
|
|
362
|
+
.window_id = 1,
|
|
363
|
+
} });
|
|
364
|
+
try std.testing.expect(std.mem.indexOf(u8, allowed.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
365
|
+
|
|
366
|
+
const command_permission = [_][]const u8{security.permission_command};
|
|
367
|
+
const denied = try TestHarness().create(std.testing.allocator, .{});
|
|
368
|
+
defer denied.destroy(std.testing.allocator);
|
|
369
|
+
denied.runtime.options.js_window_api = true;
|
|
370
|
+
denied.runtime.options.security.permissions = &command_permission;
|
|
371
|
+
try denied.start(app_state.app());
|
|
372
|
+
try denied.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
373
|
+
.bytes = "{\"id\":\"denied\",\"command\":\"native-sdk.view.list\",\"payload\":{}}",
|
|
374
|
+
.origin = "zero://inline",
|
|
375
|
+
.window_id = 1,
|
|
376
|
+
} });
|
|
377
|
+
try std.testing.expect(std.mem.indexOf(u8, denied.null_platform.lastBridgeResponse(), "\"permission_denied\"") != null);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
test "runtime returns closed webview info before compacting storage" {
|
|
381
|
+
const TestApp = struct {
|
|
382
|
+
fn app(self: *@This()) App {
|
|
383
|
+
return .{ .context = self, .name = "webview-close-response", .source = platform.WebViewSource.html("<p>WebView</p>") };
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
388
|
+
defer harness.destroy(std.testing.allocator);
|
|
389
|
+
harness.runtime.options.js_window_api = true;
|
|
390
|
+
const webview_origins = [_][]const u8{ "zero://inline", "https://example.com" };
|
|
391
|
+
harness.runtime.options.security.navigation.allowed_origins = &webview_origins;
|
|
392
|
+
var app_state: TestApp = .{};
|
|
393
|
+
try harness.start(app_state.app());
|
|
394
|
+
|
|
395
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
396
|
+
.bytes = "{\"id\":\"first\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"first\",\"url\":\"https://example.com/first\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
397
|
+
.origin = "zero://inline",
|
|
398
|
+
.window_id = 1,
|
|
399
|
+
} });
|
|
400
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
401
|
+
.bytes = "{\"id\":\"second\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"second\",\"url\":\"https://example.com/second\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
402
|
+
.origin = "zero://inline",
|
|
403
|
+
.window_id = 1,
|
|
404
|
+
} });
|
|
405
|
+
|
|
406
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
407
|
+
.bytes = "{\"id\":\"close-first\",\"command\":\"native-sdk.webview.close\",\"payload\":{\"label\":\"first\"}}",
|
|
408
|
+
.origin = "zero://inline",
|
|
409
|
+
.window_id = 1,
|
|
410
|
+
} });
|
|
411
|
+
|
|
412
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"first\"") != null);
|
|
413
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"second\"") == null);
|
|
414
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.webview_count);
|
|
415
|
+
try std.testing.expectEqualStrings("second", harness.null_platform.webviews[0].label);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
test "runtime defaults webview commands to source window" {
|
|
419
|
+
const TestApp = struct {
|
|
420
|
+
fn app(self: *@This()) App {
|
|
421
|
+
return .{ .context = self, .name = "webview-source-window", .source = platform.WebViewSource.html("<p>WebView</p>") };
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
426
|
+
defer harness.destroy(std.testing.allocator);
|
|
427
|
+
harness.runtime.options.js_window_api = true;
|
|
428
|
+
const webview_origins = [_][]const u8{ "zero://inline", "https://example.com" };
|
|
429
|
+
harness.runtime.options.security.navigation.allowed_origins = &webview_origins;
|
|
430
|
+
var app_state: TestApp = .{};
|
|
431
|
+
try harness.start(app_state.app());
|
|
432
|
+
const secondary = try harness.runtime.createWindow(.{ .label = "secondary" });
|
|
433
|
+
|
|
434
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
435
|
+
.bytes = "{\"id\":\"1\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
436
|
+
.origin = "zero://inline",
|
|
437
|
+
.window_id = secondary.id,
|
|
438
|
+
} });
|
|
439
|
+
|
|
440
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
441
|
+
try std.testing.expectEqual(secondary.id, harness.null_platform.webviews[0].window_id);
|
|
442
|
+
try std.testing.expectEqual(secondary.id, harness.null_platform.lastBridgeResponseWindowId());
|
|
443
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"windowId\":2") != null);
|
|
444
|
+
|
|
445
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
446
|
+
.bytes = "{\"id\":\"2\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"windowId\":2,\"label\":\"cross-window\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
447
|
+
.origin = "zero://inline",
|
|
448
|
+
.window_id = 1,
|
|
449
|
+
} });
|
|
450
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "must match the calling window") != null);
|
|
451
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
test "runtime validates webview bridge commands" {
|
|
455
|
+
const TestApp = struct {
|
|
456
|
+
fn app(self: *@This()) App {
|
|
457
|
+
return .{ .context = self, .name = "webview-validation", .source = platform.WebViewSource.html("<p>WebView</p>") };
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
462
|
+
defer harness.destroy(std.testing.allocator);
|
|
463
|
+
harness.runtime.options.js_window_api = true;
|
|
464
|
+
const webview_origins = [_][]const u8{ "zero://inline", "https://example.com", "https://example.org" };
|
|
465
|
+
harness.runtime.options.security.navigation.allowed_origins = &webview_origins;
|
|
466
|
+
var app_state: TestApp = .{};
|
|
467
|
+
try harness.start(app_state.app());
|
|
468
|
+
|
|
469
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
470
|
+
.bytes = "{\"id\":\"missing-url\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
471
|
+
.origin = "zero://inline",
|
|
472
|
+
.window_id = 1,
|
|
473
|
+
} });
|
|
474
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView URL is missing") != null);
|
|
475
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
476
|
+
|
|
477
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
478
|
+
.bytes = "{\"id\":\"invalid-frame\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.com\",\"frame\":{\"width\":0,\"height\":200}}}",
|
|
479
|
+
.origin = "zero://inline",
|
|
480
|
+
.window_id = 1,
|
|
481
|
+
} });
|
|
482
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
483
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
484
|
+
|
|
485
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
486
|
+
.bytes = "{\"id\":\"reserved-label\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"main\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
487
|
+
.origin = "zero://inline",
|
|
488
|
+
.window_id = 1,
|
|
489
|
+
} });
|
|
490
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "reserved") != null);
|
|
491
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
492
|
+
|
|
493
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
494
|
+
.bytes = "{\"id\":\"native-view\",\"command\":\"native-sdk.view.create\",\"payload\":{\"label\":\"native-collision\",\"kind\":\"button\",\"frame\":{\"width\":120,\"height\":32},\"text\":\"Native\"}}",
|
|
495
|
+
.origin = "zero://inline",
|
|
496
|
+
.window_id = 1,
|
|
497
|
+
} });
|
|
498
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
499
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
500
|
+
.bytes = "{\"id\":\"native-collision\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"native-collision\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
501
|
+
.origin = "zero://inline",
|
|
502
|
+
.window_id = 1,
|
|
503
|
+
} });
|
|
504
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "View label already exists") != null);
|
|
505
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
506
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.webview_count);
|
|
507
|
+
|
|
508
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
509
|
+
.bytes = "{\"id\":\"invalid-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"bad-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":1e1000}}",
|
|
510
|
+
.origin = "zero://inline",
|
|
511
|
+
.window_id = 1,
|
|
512
|
+
} });
|
|
513
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
514
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
515
|
+
|
|
516
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
517
|
+
.bytes = "{\"id\":\"max-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"max-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":2147483647}}",
|
|
518
|
+
.origin = "zero://inline",
|
|
519
|
+
.window_id = 1,
|
|
520
|
+
} });
|
|
521
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
522
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"layer\":2147483647") != null);
|
|
523
|
+
|
|
524
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
525
|
+
.bytes = "{\"id\":\"out-of-range-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"bad-layer-range\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":100000000000000000000}}",
|
|
526
|
+
.origin = "zero://inline",
|
|
527
|
+
.window_id = 1,
|
|
528
|
+
} });
|
|
529
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
530
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
531
|
+
|
|
532
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
533
|
+
.bytes = "{\"id\":\"i32-overflow-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"i32-overflow-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":2147483648}}",
|
|
534
|
+
.origin = "zero://inline",
|
|
535
|
+
.window_id = 1,
|
|
536
|
+
} });
|
|
537
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
538
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
539
|
+
|
|
540
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
541
|
+
.bytes = "{\"id\":\"min-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"min-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":-2147483648}}",
|
|
542
|
+
.origin = "zero://inline",
|
|
543
|
+
.window_id = 1,
|
|
544
|
+
} });
|
|
545
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
546
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"layer\":-2147483648") != null);
|
|
547
|
+
|
|
548
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
549
|
+
.bytes = "{\"id\":\"i32-underflow-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"i32-underflow-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":-2147483649}}",
|
|
550
|
+
.origin = "zero://inline",
|
|
551
|
+
.window_id = 1,
|
|
552
|
+
} });
|
|
553
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
554
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
555
|
+
|
|
556
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
557
|
+
.bytes = "{\"id\":\"fractional-layer\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"fractional-layer\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200},\"layer\":1.5}}",
|
|
558
|
+
.origin = "zero://inline",
|
|
559
|
+
.window_id = 1,
|
|
560
|
+
} });
|
|
561
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView options are invalid") != null);
|
|
562
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
563
|
+
|
|
564
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
565
|
+
.bytes = "{\"id\":\"ok\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
566
|
+
.origin = "zero://inline",
|
|
567
|
+
.window_id = 1,
|
|
568
|
+
} });
|
|
569
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
570
|
+
|
|
571
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
572
|
+
.bytes = "{\"id\":\"duplicate\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.org\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
573
|
+
.origin = "zero://inline",
|
|
574
|
+
.window_id = 1,
|
|
575
|
+
} });
|
|
576
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView label already exists") != null);
|
|
577
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
578
|
+
|
|
579
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
580
|
+
.bytes = "{\"id\":\"missing-window\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"windowId\":99,\"label\":\"other\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
581
|
+
.origin = "zero://inline",
|
|
582
|
+
.window_id = 1,
|
|
583
|
+
} });
|
|
584
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "must match the calling window") != null);
|
|
585
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
586
|
+
|
|
587
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
588
|
+
.bytes = "{\"id\":\"bad-window-id\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"windowId\":\"1\",\"label\":\"bad-window-id\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
589
|
+
.origin = "zero://inline",
|
|
590
|
+
.window_id = 1,
|
|
591
|
+
} });
|
|
592
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "windowId must be a non-negative integer") != null);
|
|
593
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
594
|
+
|
|
595
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
596
|
+
.bytes = "{\"id\":\"missing-webview\",\"command\":\"native-sdk.webview.setFrame\",\"payload\":{\"label\":\"missing\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
597
|
+
.origin = "zero://inline",
|
|
598
|
+
.window_id = 1,
|
|
599
|
+
} });
|
|
600
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView was not found") != null);
|
|
601
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
602
|
+
|
|
603
|
+
var long_label = [_]u8{'a'} ** (platform.max_webview_label_bytes + 1);
|
|
604
|
+
var long_label_request_buffer: [512]u8 = undefined;
|
|
605
|
+
const long_label_request = try std.fmt.bufPrint(&long_label_request_buffer, "{{\"id\":\"long-label\",\"command\":\"native-sdk.webview.create\",\"payload\":{{\"label\":\"{s}\",\"url\":\"https://example.com\",\"frame\":{{\"width\":300,\"height\":200}}}}}}", .{&long_label});
|
|
606
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
607
|
+
.bytes = long_label_request,
|
|
608
|
+
.origin = "zero://inline",
|
|
609
|
+
.window_id = 1,
|
|
610
|
+
} });
|
|
611
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView label is too large") != null);
|
|
612
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
613
|
+
|
|
614
|
+
var long_url = [_]u8{'a'} ** (platform.max_webview_url_bytes + 1);
|
|
615
|
+
var long_url_request_buffer: [platform.max_webview_url_bytes + 256]u8 = undefined;
|
|
616
|
+
const long_url_request = try std.fmt.bufPrint(&long_url_request_buffer, "{{\"id\":\"long-url\",\"command\":\"native-sdk.webview.create\",\"payload\":{{\"label\":\"too-long-url\",\"url\":\"{s}\",\"frame\":{{\"width\":300,\"height\":200}}}}}}", .{&long_url});
|
|
617
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
618
|
+
.bytes = long_url_request,
|
|
619
|
+
.origin = "zero://inline",
|
|
620
|
+
.window_id = 1,
|
|
621
|
+
} });
|
|
622
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "WebView URL is too large") != null);
|
|
623
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
624
|
+
|
|
625
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
626
|
+
.bytes = "{\"id\":\"denied-url\",\"command\":\"native-sdk.webview.navigate\",\"payload\":{\"label\":\"preview\",\"url\":\"https://blocked.example\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
627
|
+
.origin = "zero://inline",
|
|
628
|
+
.window_id = 1,
|
|
629
|
+
} });
|
|
630
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
631
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "navigation policy") != null);
|
|
632
|
+
|
|
633
|
+
harness.runtime.options.platform.services.set_webview_zoom_fn = null;
|
|
634
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
635
|
+
.bytes = "{\"id\":\"unsupported-zoom\",\"command\":\"native-sdk.webview.setZoom\",\"payload\":{\"label\":\"preview\",\"zoom\":1.25}}",
|
|
636
|
+
.origin = "zero://inline",
|
|
637
|
+
.window_id = 1,
|
|
638
|
+
} });
|
|
639
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "not available on this platform") != null);
|
|
640
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
641
|
+
|
|
642
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
|
|
643
|
+
.bytes = "{\"id\":\"escaped\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview \\\"quoted\\\"\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
|
|
644
|
+
.origin = "zero://inline",
|
|
645
|
+
.window_id = 1,
|
|
646
|
+
} });
|
|
647
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"preview \\\"quoted\\\"\"") != null);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
test "runtime reports actionable unsupported webview capability errors" {
|
|
651
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.UnsupportedChildWebViews));
|
|
652
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.UnsupportedWebViewBridge));
|
|
653
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.UnsupportedMainWebViewFrame));
|
|
654
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.UnsupportedMainWebViewZoom));
|
|
655
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.UnsupportedMainWebViewLayer));
|
|
656
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.InvalidWindowOptions));
|
|
657
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.DuplicateWindowLabel));
|
|
658
|
+
try std.testing.expectEqual(bridge.ErrorCode.invalid_request, builtinBridgeErrorCode(error.WindowNotFound));
|
|
659
|
+
try std.testing.expectEqualStrings("This backend does not support child WebViews yet", builtinBridgeErrorMessage(error.UnsupportedChildWebViews));
|
|
660
|
+
try std.testing.expectEqualStrings("This backend does not support bridge-enabled child WebViews yet", builtinBridgeErrorMessage(error.UnsupportedWebViewBridge));
|
|
661
|
+
try std.testing.expectEqualStrings("This backend does not support resizing the main WebView yet", builtinBridgeErrorMessage(error.UnsupportedMainWebViewFrame));
|
|
662
|
+
try std.testing.expectEqualStrings("This backend does not support zooming the main WebView yet", builtinBridgeErrorMessage(error.UnsupportedMainWebViewZoom));
|
|
663
|
+
try std.testing.expectEqualStrings("This backend does not support changing the main WebView layer", builtinBridgeErrorMessage(error.UnsupportedMainWebViewLayer));
|
|
664
|
+
}
|