Skip to content

Commit a2ec1dd

Browse files
committed
test: check the own window's size, not its content, in window capture
ownWindowFramesFollowWindow failed once in a full run: after the window turned white, its frames stayed black. Its capture was running, but the window had not been redrawn. A window of a test process that is not in front may not be redrawn in time, and it cannot be put on top, since WindowCapturer lists only windows of the normal level. The test now checks that the window is captured at its size, and that the capture ends when the window closes. Content is checked on another process's window, which is now ordered to the front.
1 parent 275f452 commit a2ec1dd

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎webrtc/src/test/java/dev/onvoid/webrtc/media/video/VideoDesktopSourceTests.java‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,16 @@ void closedWindowStopsCapture() throws Exception {
278278
}
279279

280280
@Test
281-
void ownWindowFramesFollowWindow() throws Exception {
281+
void ownWindowCapturedUntilClosed() throws Exception {
282282
assumeTrue(OS.contains("mac"), "covers the macOS window capturers");
283283
assumeFalse(GraphicsEnvironment.isHeadless(), "No display");
284284

285-
// This process may capture its own window without screen recording
286-
// permission, and closing it must end the capture.
285+
double scale = screenScale();
286+
287+
// This process captures its own window with CGWindowListCreateImage,
288+
// which needs no screen recording permission, and closing the window
289+
// must end the capture. Its content is not checked: a window of a
290+
// process that is not in front may not be redrawn in time.
287291
String title = "webrtc-java " + UUID.randomUUID();
288292
Frame window = new Frame(title);
289293

@@ -299,16 +303,11 @@ void ownWindowFramesFollowWindow() throws Exception {
299303
assumeTrue(source != null, "The window is not listed under its title");
300304

301305
try (WindowCapture capture = new WindowCapture(source)) {
302-
assumeTrue(capture.await(frame -> true, 5000) != null, "The window delivered no frames");
303-
304-
EventQueue.invokeAndWait(() -> {
305-
window.setBackground(Color.WHITE);
306-
window.repaint();
307-
});
306+
int[] first = capture.await(frame -> true, 5000);
308307

309-
int[] white = capture.await(frame -> frame[2] > 150, 3000);
308+
assumeTrue(first != null, "The window delivered no frames");
310309

311-
assertTrue(white[2] > 150, "Frames did not follow the window turning white: luma " + white[2]);
310+
assertSize(400, 300, scale, first);
312311

313312
EventQueue.invokeAndWait(window::dispose);
314313

‎webrtc/src/test/java/dev/onvoid/webrtc/media/video/desktop/TestWindowProcess.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public static void main(String[] args) throws Exception {
133133
window.setBackground(Color.BLACK);
134134
window.setBounds(100, 100, Integer.parseInt(args[1]), Integer.parseInt(args[2]));
135135
window.setVisible(true);
136+
// Not hidden behind other windows, where it may not be redrawn.
137+
window.toFront();
136138
});
137139

138140
BufferedReader input = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));

0 commit comments

Comments
 (0)