Skip to content

Commit 9aa8693

Browse files
authored
webdriver: Add a 10 second timeout for screenshots (servo#40290)
This change adds a 10 second timeout for screenshots. Without this timeout, tests that fail take a screenshot in a reasonable amount of time cause the the WebDriver driver to kill the process leading to a CRASH test result. This causes the results to differ and to obscure what is really a TIMEOUT. This behavior is unspecified, but it's still an improvement, as it properly classifies failures when the WPT is run with WebDriver. Testing: This causes some WPT tests run with WebDriver to have their expected result. Signed-off-by: Martin Robinson <[email protected]>
1 parent 36dc928 commit 9aa8693

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

components/webdriver_server/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use base::id::{BrowsingContextId, WebViewId};
2727
use base64::Engine;
2828
use capabilities::ServoCapabilities;
2929
use cookie::{CookieBuilder, Expiration, SameSite};
30-
use crossbeam_channel::{Receiver, Sender, after, select, unbounded};
30+
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender, after, select, unbounded};
3131
use embedder_traits::{
3232
EventLoopWaker, ImeEvent, InputEvent, JSValue, JavaScriptEvaluationError,
3333
JavaScriptEvaluationResultSerializationError, MouseButton, WebDriverCommandMsg,
@@ -75,7 +75,7 @@ use webdriver::server::{self, Session, SessionTeardownKind, WebDriverHandler};
7575

7676
use crate::actions::{InputSourceState, PointerInputState};
7777
use crate::session::{PageLoadStrategy, WebDriverSession};
78-
use crate::timeout::DEFAULT_PAGE_LOAD_TIMEOUT;
78+
use crate::timeout::{DEFAULT_PAGE_LOAD_TIMEOUT, SCREENSHOT_TIMEOUT};
7979

8080
fn extension_routes() -> Vec<(Method, &'static str, ServoExtensionRoute)> {
8181
vec![
@@ -2307,18 +2307,25 @@ impl Handler {
23072307
"The requested `rect` has zero width and/or height",
23082308
));
23092309
}
2310+
23102311
let webview_id = self.webview_id()?;
23112312
let (sender, receiver) = crossbeam_channel::unbounded();
23122313
self.send_message_to_embedder(WebDriverCommandMsg::TakeScreenshot(
23132314
webview_id, rect, sender,
23142315
))?;
23152316

2316-
let Ok(result) = receiver.recv() else {
2317-
return Err(WebDriverError::new(
2317+
let result = match receiver.recv_timeout(SCREENSHOT_TIMEOUT) {
2318+
Ok(result) => Ok(result),
2319+
Err(RecvTimeoutError::Timeout) => Err(WebDriverError::new(
2320+
ErrorStatus::Timeout,
2321+
"Timed out waiting to take screenshot. Test likely didn't finish.",
2322+
)),
2323+
Err(RecvTimeoutError::Disconnected) => Err(WebDriverError::new(
23182324
ErrorStatus::UnknownError,
2319-
"Failed to receive TakeScreenshot response",
2320-
));
2321-
};
2325+
"Could not take screenshot because channel disconnected.",
2326+
)),
2327+
}?;
2328+
23222329
let image = result.map_err(|error| {
23232330
WebDriverError::new(
23242331
ErrorStatus::UnknownError,

components/webdriver_server/timeout.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5+
use std::time::Duration;
6+
57
use serde_json::Value;
68
use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult};
79

@@ -17,6 +19,11 @@ pub(crate) const DEFAULT_PAGE_LOAD_TIMEOUT: u64 = 300_000;
1719
/// <https://w3c.github.io/webdriver/#dfn-timeouts-configuration>.
1820
pub(crate) const DEFAULT_IMPLICIT_WAIT: u64 = 0;
1921

22+
/// An amount of time to wait before considering that a screenshot has timed out.
23+
/// If after 10 seconds the screenshot cannot be taken, assume that the test has
24+
/// timed out.
25+
pub(crate) const SCREENSHOT_TIMEOUT: Duration = Duration::from_secs(10);
26+
2027
pub(crate) struct TimeoutsConfiguration {
2128
pub(crate) script: Option<u64>,
2229
pub(crate) page_load: Option<u64>,

0 commit comments

Comments
 (0)