diff --git a/.github/workflows/repository-hygiene.yml b/.github/workflows/repository-hygiene.yml index 7eb74d943..1b26b2605 100644 --- a/.github/workflows/repository-hygiene.yml +++ b/.github/workflows/repository-hygiene.yml @@ -325,10 +325,13 @@ jobs: $env:PIIK_CONTACT_PROBE = Join-Path $env:RUNNER_TEMP 'piik-contact.exe' cmd /c "call `"$dev`" -arch=x64 -no_logo && cl /nologo /EHsc /W4 /D_CRT_SECURE_NO_WARNINGS prototype/channel-server/src/app_windows/test_contact.cpp /Fe:`"$env:PIIK_CONTACT_PROBE`" user32.lib" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - $testName = 'app_windows::reveal::menu_tests::native_permission_caption_contact' - cargo +1.91.0 test --locked --manifest-path prototype/channel-server/Cargo.toml --features capture --lib $testName -- --ignored --exact --test-threads=1 --nocapture | Tee-Object -Variable testOutput - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - if ($testOutput -notcontains 'running 1 test') { throw "Expected to run $testName" } + $failed = @() + foreach ($kind in 'touch','pen') { + $testName = "app_windows::reveal::menu_tests::native_permission_caption_$kind" + cargo +1.91.0 test --locked --manifest-path prototype/channel-server/Cargo.toml --features capture --lib $testName -- --ignored --exact --test-threads=1 --nocapture | Tee-Object -Variable testOutput + if ($LASTEXITCODE -ne 0 -or $testOutput -notcontains 'running 1 test') { $failed += $kind } + } + if ($failed.Count) { throw "Permission caption checks failed for $($failed -join ', ')" } - name: Compile the Windows input tests id: compile_windows_input if: ${{ !cancelled() && runner.os == 'Windows' && steps.compile_windows_app.outcome == 'success' }} diff --git a/prototype/channel-server/src/app_page.rs b/prototype/channel-server/src/app_page.rs index 111b7fcc8..bc04e825f 100644 --- a/prototype/channel-server/src/app_page.rs +++ b/prototype/channel-server/src/app_page.rs @@ -198,6 +198,9 @@ pub struct Patch { } impl Patch { pub fn validate(&self) -> Result<()> { + if self.position.is_none() && self.paused.is_none() && self.rate.is_none() { + bail!("invalid_watch_playback"); + } if self.position.is_some_and(|v| !v.is_finite() || v < 0.) || self .rate @@ -1503,15 +1506,33 @@ mod tests { .await .unwrap(); } + #[tokio::test] + async fn page_patch_requires_a_known_change_before_dispatch() { + let (events, _queue) = mpsc::channel(8); + let connection = Connection::new(Some(Arc::new(|command| { + if let Command::Request { operation, reply, .. } = command { + let Operation::PagePatch { patch, .. } = operation else { panic!("wrong operation") }; + assert_eq!(serde_json::to_value(patch).unwrap(), serde_json::json!({"position":1.0})); + reply.send(Ok(Value::Bool(true))).unwrap(); + } + true + })), events); + let id = Uuid::new_v4(); + let operation = |patch: Value| serde_json::from_value(serde_json::json!({ + "type":"page_patch", "pageId":id, "patch":patch + })).unwrap(); + for empty in [serde_json::json!({}), serde_json::json!({"volume":0.5})] { + assert_eq!(connection.request(operation(empty)).await.unwrap_err().to_string(), "invalid_watch_playback"); + } + let change = serde_json::json!({"position":1,"headers":{}}); + assert_eq!(connection.request(operation(change)).await.unwrap(), Value::Bool(true)); + } + #[test] fn page_input_is_media_only() { assert!(valid_url("https://example.com/watch")); assert!(!valid_url("file:///secret")); assert!(!valid_url("https://name:password@example.com/")); - assert!( - serde_json::from_value::(serde_json::json!({"position":1,"headers":{}})) - .is_err() - ); assert!(Patch { position: None, paused: None, diff --git a/prototype/channel-server/src/app_windows/menu_tests.rs b/prototype/channel-server/src/app_windows/menu_tests.rs index 6a94d707a..bc2ac897e 100644 --- a/prototype/channel-server/src/app_windows/menu_tests.rs +++ b/prototype/channel-server/src/app_windows/menu_tests.rs @@ -122,9 +122,7 @@ fn native_system_menu_targets_main_and_permission() { assert!(!unsafe { IsZoomed(owner).as_bool() }); } -#[test] -#[ignore = "injects touch and pen into a prompt on an isolated interactive Windows desktop"] -fn native_permission_caption_contact() { +fn permission_caption_contact(kind: &str) { assert_eq!(std::env::var("PIIK_ISOLATED_WINDOWS_DESKTOP").as_deref(), Ok("1")); let probe = std::env::var_os("PIIK_CONTACT_PROBE").unwrap(); let profile = tempfile::tempdir().unwrap(); @@ -139,41 +137,51 @@ fn native_permission_caption_contact() { let prompt = Prompt::new(&events, events.create_proxy(), &mut context, request, owner.clone(), &Theme::Light, Language::En).unwrap(); let mut ready = false; - for kind in ["touch", "pen"] { - let mut child: Option = None; - let mut status = None; - let mut drags = 0; - let deadline = Instant::now() + Duration::from_secs(15); - events.run_return(|event, _, flow| { - match event { - Event::UserEvent(ServiceEvent::PermissionReady(id)) if id == prompt.id() => { - prompt.show(); - ready = true; - } - Event::UserEvent(ServiceEvent::Caption(id, action @ WindowAction::Drag)) if id == prompt.id() => { - drags += 1; - prompt.window_action(&action); - } - _ => {} + let mut child: Option = None; + let mut status = None; + let mut drags = 0; + let deadline = Instant::now() + Duration::from_secs(15); + events.run_return(|event, _, flow| { + match event { + Event::UserEvent(ServiceEvent::PermissionReady(id)) if id == prompt.id() => { + prompt.show(); + ready = true; } - if ready && child.is_none() { - let hwnd = unsafe { GetWindow(HWND(owner.hwnd() as _), GW_ENABLEDPOPUP).unwrap() }; - let mut rect = RECT::default(); - unsafe { GetWindowRect(hwnd, &mut rect).unwrap() }; - let x = (rect.left + rect.right) / 2; - let y = rect.top + (20.0 * owner.scale_factor()) as i32; - child = Some(std::process::Command::new(&probe) - .args([format!("{}", hwnd.0 as usize), x.to_string(), y.to_string(), kind.into()]) - .spawn().unwrap()); + Event::UserEvent(ServiceEvent::Caption(id, action @ WindowAction::Drag)) if id == prompt.id() => { + drags += 1; + prompt.window_action(&action); } - if let Some(child) = &mut child { status = child.try_wait().unwrap(); } - *flow = if status.is_some() || Instant::now() >= deadline { ControlFlow::Exit } - else { ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(20)) }; - }); - if status.is_none() { - if let Some(mut child) = child { let _ = child.kill(); let _ = child.wait(); } + _ => {} } - assert_eq!(drags, 1, "{kind} prompt drag IPC count"); - assert!(status.is_some_and(|s| s.success()), "{kind} probe {status:?}"); + if ready && child.is_none() { + let hwnd = unsafe { GetWindow(HWND(owner.hwnd() as _), GW_ENABLEDPOPUP).unwrap() }; + let mut rect = RECT::default(); + unsafe { GetWindowRect(hwnd, &mut rect).unwrap() }; + let x = (rect.left + rect.right) / 2; + let y = rect.top + (20.0 * owner.scale_factor()) as i32; + child = Some(std::process::Command::new(&probe) + .args([format!("{}", hwnd.0 as usize), x.to_string(), y.to_string(), kind.into()]) + .spawn().unwrap()); + } + if let Some(child) = &mut child { status = child.try_wait().unwrap(); } + *flow = if status.is_some() || Instant::now() >= deadline { ControlFlow::Exit } + else { ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(20)) }; + }); + if status.is_none() { + if let Some(mut child) = child { let _ = child.kill(); let _ = child.wait(); } } + assert_eq!(drags, 1, "{kind} prompt drag IPC count"); + assert!(status.is_some_and(|s| s.success()), "{kind} probe {status:?}"); +} + +#[test] +#[ignore = "injects touch on an isolated interactive Windows desktop"] +fn native_permission_caption_touch() { + permission_caption_contact("touch"); +} + +#[test] +#[ignore = "injects pen on an isolated interactive Windows desktop"] +fn native_permission_caption_pen() { + permission_caption_contact("pen"); } diff --git a/prototype/channel-server/src/app_windows/page_source_matrix.rs b/prototype/channel-server/src/app_windows/page_source_matrix.rs index 55288704a..90c875713 100644 --- a/prototype/channel-server/src/app_windows/page_source_matrix.rs +++ b/prototype/channel-server/src/app_windows/page_source_matrix.rs @@ -53,6 +53,7 @@ fn playlist_header() -> [(axum::http::HeaderName, HeaderValue); 1] { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[ignore = "opens WebView2 windows on an interactive Windows desktop"] async fn native_source_matrix() { + let _ = rustls::crypto::ring::default_provider().install_default(); let (_fixture, base) = fixture_server(routes(Router::new())); let profile = tempfile::tempdir().unwrap(); let mut target = EventLoopBuilder::::with_user_event() diff --git a/prototype/channel-server/src/app_windows/test_contact.cpp b/prototype/channel-server/src/app_windows/test_contact.cpp index ae1262fe9..73fc2db1f 100644 --- a/prototype/channel-server/src/app_windows/test_contact.cpp +++ b/prototype/channel-server/src/app_windows/test_contact.cpp @@ -26,19 +26,29 @@ int wmain(int argc, wchar_t** argv) { frame.type=kind; auto& info=pen ? frame.penInfo.pointerInfo : frame.touchInfo.pointerInfo; info.pointerType=kind; - info.pointerId=1; + info.pointerId=0; info.ptPixelLocation=point; info.pointerFlags=flags; if (!pen) { frame.touchInfo.touchMask=TOUCH_MASK_CONTACTAREA; frame.touchInfo.rcContact={point.x-2,point.y-2,point.x+2,point.y+2}; } + const char* phase=(flags & POINTER_FLAG_DOWN) ? "DOWN" : (flags & POINTER_FLAG_UP) ? "UP" : "UPDATE"; + if (flags & POINTER_FLAG_DOWN) { + const int left=GetSystemMetrics(SM_XVIRTUALSCREEN), top=GetSystemMetrics(SM_YVIRTUALSCREEN); + const RECT area=pen ? RECT{} : frame.touchInfo.rcContact; + std::fprintf(stderr,"%s DOWN id=%u flags=%#x xy=(%ld,%ld) contact=(%ld,%ld,%ld,%ld) desktop=(%d,%d,%d,%d)\n", + pen ? "pen" : "touch",info.pointerId,flags,point.x,point.y,area.left,area.top,area.right,area.bottom, + left,top,left+GetSystemMetrics(SM_CXVIRTUALSCREEN),top+GetSystemMetrics(SM_CYVIRTUALSCREEN)); + } + DWORD error=ERROR_SUCCESS; for (int attempt=0; attempt<20; ++attempt) { if (pen ? InjectSyntheticPointerInput(device,&frame,1) : InjectTouchInput(1,&frame.touchInfo)) return true; - if (GetLastError()!=ERROR_NOT_READY) break; + error=GetLastError(); + if (error!=ERROR_NOT_READY) break; Sleep(2); } - std::fprintf(stderr,"injection error %lu\n",GetLastError()); + std::fprintf(stderr,"%s injection failed at (%ld,%ld), error=%lu\n",phase,point.x,point.y,error); return false; }; const DWORD contact=POINTER_FLAG_INRANGE|POINTER_FLAG_INCONTACT; @@ -50,9 +60,13 @@ int wmain(int argc, wchar_t** argv) { ok=inject(next,contact|POINTER_FLAG_UPDATE); if (ok) current=next; } - bool tracked=false; + bool tracked=false, measured=false; for (int i=0; ok && i<20; ++i) { - if (!GetWindowRect(window,&during)) break; + if (!GetWindowRect(window,&during)) { + std::fprintf(stderr,"GetWindowRect failed, error=%lu\n",GetLastError()); + break; + } + measured=true; if (during.left-before.left>=70 && during.left-before.left<=120 && abs(during.top-before.top)<=10 && during.right-during.left==before.right-before.left && during.bottom-during.top==before.bottom-before.top) { tracked=true; break; } @@ -61,6 +75,7 @@ int wmain(int argc, wchar_t** argv) { bool released=!down || inject(current,POINTER_FLAG_UP); if (device) DestroySyntheticPointerDevice(device); if (!tracked || !released) PostMessageW(window,WM_CANCELMODE,0,0); - std::printf("held delta=(%ld,%ld), tracked=%d, released=%d\n",during.left-before.left,during.top-before.top,tracked,released); + if (measured) std::printf("held delta=(%ld,%ld), tracked=%d\n",during.left-before.left,during.top-before.top,tracked); + if (down) std::printf("UP succeeded=%d\n",released); return ok && tracked && released ? 0 : 1; } diff --git a/prototype/channel-server/src/runtime_tests.rs b/prototype/channel-server/src/runtime_tests.rs index 5c6751708..82512e7d9 100644 --- a/prototype/channel-server/src/runtime_tests.rs +++ b/prototype/channel-server/src/runtime_tests.rs @@ -281,7 +281,7 @@ fn domain_metadata_requires_owner_and_commits_before_broadcast_then_reopens() { assert!(guest .drain() .iter() - .any(|event| event["code"] == "forbidden")); + .any(|event| event == &json!({"type":"reply","requestId":"metadata","result":{"type":"error","code":"forbidden"}}))); assert_eq!( serde_json::to_value(hub.authority.export_state()).unwrap(), original @@ -292,7 +292,7 @@ fn domain_metadata_requires_owner_and_commits_before_broadcast_then_reopens() { assert!(owner .drain() .iter() - .any(|event| event["code"] == "storage_failed")); + .any(|event| event == &json!({"type":"reply","requestId":"metadata","result":{"type":"error","code":"storage_failed"}}))); assert!( guest.drain().is_empty(), "failed metadata must not broadcast"