Skip to content

Commit

Permalink
fix: Make the Windows subclassing test more robust (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell authored Nov 4, 2023
1 parent 4eb21ff commit 0078f79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion platforms/windows/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl Scope {
}

// It's not safe to run these UI-related tests concurrently.
static MUTEX: Mutex<()> = Mutex::new(());
pub(crate) static MUTEX: Mutex<()> = Mutex::new(());

pub(crate) fn scope<F>(
window_title: &str,
Expand Down
10 changes: 5 additions & 5 deletions platforms/windows/src/tests/subclassed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use winit::{
window::WindowBuilder,
};

use super::MUTEX;
use crate::SubclassingAdapter;

const WINDOW_TITLE: &str = "Simple test";
Expand Down Expand Up @@ -63,17 +64,16 @@ impl ActionHandler for NullActionHandler {
fn has_native_uia() {
// This test is simple enough that we know it's fine to run entirely
// on one thread, so we don't need a full multithreaded test harness.
// Still, we must prevent this test from running concurrently with other
// tests, especially the focus test.
let _lock_guard = MUTEX.lock().unwrap();
let event_loop = EventLoopBuilder::<()>::new().with_any_thread(true).build();
let window = WindowBuilder::new()
.with_title(WINDOW_TITLE)
.with_visible(false)
.build(&event_loop)
.unwrap();
let hwnd = HWND(window.hwnd());
assert!(!unsafe { UiaHasServerSideProvider(hwnd) }.as_bool());
let adapter = SubclassingAdapter::new(hwnd, get_initial_state, Box::new(NullActionHandler {}));
assert!(unsafe { UiaHasServerSideProvider(hwnd) }.as_bool());
drop(adapter);
assert!(!unsafe { UiaHasServerSideProvider(hwnd) }.as_bool());
let adapter = SubclassingAdapter::new(hwnd, get_initial_state, Box::new(NullActionHandler {}));
assert!(unsafe { UiaHasServerSideProvider(hwnd) }.as_bool());
drop(window);
Expand Down

0 comments on commit 0078f79

Please sign in to comment.