mirror of
https://github.com/servo/servo.git
synced 2025-10-19 01:39:16 +01:00
webdriver: Report error instead of panic for invalid WebElement
&ShadowRoot
reference (#39976)
It is possible that the reference of `WebElement` and `ShadowRoot` in the request is not String. Instead of panic, we should return "invalid argument" same as the `WebWindow` and `WebFrame`. Testing: Added 4 new subtests. There was only tests for `WebWindow` and `WebFrame` somehow. --------- Signed-off-by: Euclid <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
fa0ba55fde
commit
bf42488da8
4 changed files with 8 additions and 8 deletions
|
@ -49,7 +49,7 @@ impl Handler {
|
|||
// Step 2. Let reference be the result of getting the web element identifier property from object.
|
||||
let element_ref = match element {
|
||||
Value::String(string) => string.clone(),
|
||||
_ => unreachable!(),
|
||||
_ => return Err(WebDriverError::new(ErrorStatus::InvalidArgument, "")),
|
||||
};
|
||||
|
||||
// Step 3. Let element be the result of trying to get a known element with session and reference.
|
||||
|
@ -71,7 +71,7 @@ impl Handler {
|
|||
// Step 2. Let reference be the result of getting the shadow root identifier property from object.
|
||||
let shadow_root_ref = match shadow_root {
|
||||
Value::String(string) => string.clone(),
|
||||
_ => unreachable!(),
|
||||
_ => return Err(WebDriverError::new(ErrorStatus::InvalidArgument, "")),
|
||||
};
|
||||
|
||||
// Step 3. Let element be the result of trying to get a known element with session and reference.
|
||||
|
|
4
tests/wpt/meta/MANIFEST.json
vendored
4
tests/wpt/meta/MANIFEST.json
vendored
|
@ -957696,7 +957696,7 @@
|
|||
},
|
||||
"execute_async_script": {
|
||||
"arguments.py": [
|
||||
"a8c69345755499737e2d7e61b66e56bcc4c5886f",
|
||||
"edf36a1f94536f85a638c2bf2892597f5078deba",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
|
@ -957770,7 +957770,7 @@
|
|||
},
|
||||
"execute_script": {
|
||||
"arguments.py": [
|
||||
"e00459c791c05e2ac86209d211dc3693d8ccdf66",
|
||||
"a851c36713a5d6b7290813983c35f3fae5d014a3",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
|
|
|
@ -162,9 +162,9 @@ def test_stale_element_reference(session, stale_element, as_frame):
|
|||
assert_error(result, "stale element reference")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", [WebFrame, WebWindow], ids=["frame", "window"])
|
||||
@pytest.mark.parametrize("type", [WebFrame, WebWindow, WebElement, ShadowRoot], ids=["frame", "window", "element", "shadow_root"])
|
||||
@pytest.mark.parametrize("value", [None, False, 42, [], {}])
|
||||
def test_invalid_argument_for_window_with_invalid_type(session, type, value):
|
||||
def test_invalid_argument_for_reference_with_invalid_type(session, type, value):
|
||||
reference = type(session, value)
|
||||
|
||||
result = execute_async_script(session, "arguments[1](true)", args=(reference,))
|
||||
|
|
|
@ -150,9 +150,9 @@ def test_stale_element_reference(session, stale_element, as_frame):
|
|||
assert_error(result, "stale element reference")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", [WebFrame, WebWindow], ids=["frame", "window"])
|
||||
@pytest.mark.parametrize("type", [WebFrame, WebWindow, WebElement, ShadowRoot], ids=["frame", "window", "element", "shadow_root"])
|
||||
@pytest.mark.parametrize("value", [None, False, 42, [], {}])
|
||||
def test_invalid_argument_for_window_with_invalid_type(session, type, value):
|
||||
def test_invalid_argument_for_reference_with_invalid_type(session, type, value):
|
||||
reference = type(session, value)
|
||||
|
||||
result = execute_script(session, "return true", args=(reference,))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue