mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +01:00
Update web-platform-tests to revision d3cf77a7b8c20c678b725238eaa8a72eca3787ae
This commit is contained in:
parent
880f3b8b7a
commit
efca990ffe
541 changed files with 8000 additions and 2276 deletions
|
@ -101,13 +101,13 @@ def test_add_cookie_for_ip(session, url, server_config, configuration):
|
|||
|
||||
|
||||
def test_add_non_session_cookie(session, url):
|
||||
a_year_from_now = int(
|
||||
(datetime.utcnow() + timedelta(days=365) - datetime.utcfromtimestamp(0)).total_seconds())
|
||||
a_day_from_now = int(
|
||||
(datetime.utcnow() + timedelta(days=1) - datetime.utcfromtimestamp(0)).total_seconds())
|
||||
|
||||
new_cookie = {
|
||||
"name": "hello",
|
||||
"value": "world",
|
||||
"expiry": a_year_from_now
|
||||
"expiry": a_day_from_now
|
||||
}
|
||||
|
||||
session.url = url("/common/blank.html")
|
||||
|
@ -126,7 +126,7 @@ def test_add_non_session_cookie(session, url):
|
|||
|
||||
assert cookie["name"] == "hello"
|
||||
assert cookie["value"] == "world"
|
||||
assert cookie["expiry"] == a_year_from_now
|
||||
assert cookie["expiry"] == a_day_from_now
|
||||
|
||||
|
||||
def test_add_session_cookie(session, url):
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_async_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST", "/session/{session_id}/execute/async".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_content_attribute(session):
|
||||
session.url = inline("<input value=foobar>")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.value);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute(session):
|
||||
session.url = inline("""
|
||||
<input>
|
||||
<script>
|
||||
const input = document.querySelector("input");
|
||||
input.value = "foobar";
|
||||
</script>
|
||||
""")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.value);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute_element(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
|
||||
<script>
|
||||
const [foo, bar] = document.querySelectorAll("p");
|
||||
foo.bar = bar;
|
||||
</script>
|
||||
""")
|
||||
_foo, bar = session.find.css("p")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const foo = document.querySelector("p");
|
||||
resolve(foo.bar);
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert_same_element(session, bar, value)
|
||||
|
||||
|
||||
def test_script_defining_property(session):
|
||||
session.url = inline("<input>")
|
||||
session.execute_script("""
|
||||
const input = document.querySelector("input");
|
||||
input.foobar = "foobar";
|
||||
""")
|
||||
response = execute_async_script(session, """
|
||||
const [resolve] = arguments;
|
||||
const input = document.querySelector("input");
|
||||
resolve(input.foobar);
|
||||
""")
|
||||
assert_success(response, "foobar")
|
|
@ -0,0 +1,67 @@
|
|||
from tests.support.asserts import assert_same_element, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def execute_script(session, script, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
body = {"script": script, "args": args}
|
||||
return session.transport.send(
|
||||
"POST", "/session/{session_id}/execute/sync".format(**vars(session)),
|
||||
body)
|
||||
|
||||
|
||||
def test_content_attribute(session):
|
||||
session.url = inline("<input value=foobar>")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.value;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute(session):
|
||||
session.url = inline("""
|
||||
<input>
|
||||
<script>
|
||||
const input = document.querySelector("input");
|
||||
input.value = "foobar";
|
||||
</script>
|
||||
""")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.value;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute_element(session):
|
||||
session.url = inline("""
|
||||
<p>foo
|
||||
<p>bar
|
||||
|
||||
<script>
|
||||
const [foo, bar] = document.querySelectorAll("p");
|
||||
foo.bar = bar;
|
||||
</script>
|
||||
""")
|
||||
_foo, bar = session.find.css("p")
|
||||
response = execute_script(session, """
|
||||
const foo = document.querySelector("p");
|
||||
return foo.bar;
|
||||
""")
|
||||
value = assert_success(response)
|
||||
assert_same_element(session, bar, value)
|
||||
|
||||
|
||||
def test_script_defining_property(session):
|
||||
session.url = inline("<input>")
|
||||
execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
input.foobar = "foobar";
|
||||
""")
|
||||
response = execute_script(session, """
|
||||
const input = document.querySelector("input");
|
||||
return input.foobar;
|
||||
""")
|
||||
assert_success(response, "foobar")
|
|
@ -1,8 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
from tests.support.inline import inline
|
||||
|
||||
_input = inline("<input id=i1>")
|
||||
|
||||
|
||||
def get_element_property(session, element_id, prop):
|
||||
return session.transport.send(
|
||||
|
@ -18,35 +18,90 @@ def test_no_browsing_context(session, closed_window):
|
|||
|
||||
|
||||
def test_element_not_found(session):
|
||||
# 13.3 Step 3
|
||||
result = get_element_property(session, "foo", "id")
|
||||
assert_error(result, "no such element")
|
||||
response = get_element_property(session, "foo", "id")
|
||||
assert_error(response, "no such element")
|
||||
|
||||
|
||||
def test_element_stale(session):
|
||||
session.url = _input
|
||||
session.url = inline("<input id=foobar>")
|
||||
element = session.find.css("input", all=False)
|
||||
session.refresh()
|
||||
|
||||
result = get_element_property(session, element.id, "id")
|
||||
assert_error(result, "stale element reference")
|
||||
response = get_element_property(session, element.id, "id")
|
||||
assert_error(response, "stale element reference")
|
||||
|
||||
|
||||
def test_property_non_existent(session):
|
||||
session.url = _input
|
||||
session.url = inline("<input>")
|
||||
element = session.find.css("input", all=False)
|
||||
|
||||
result = get_element_property(session, element.id, "foo")
|
||||
assert_success(result, None)
|
||||
|
||||
assert session.execute_script("return arguments[0].foo", args=[element]) is None
|
||||
response = get_element_property(session, element.id, "foo")
|
||||
assert_success(response, None)
|
||||
assert session.execute_script("return arguments[0].foo", args=(element,)) is None
|
||||
|
||||
|
||||
def test_element(session):
|
||||
def test_content_attribute(session):
|
||||
session.url = inline("<input value=foobar>")
|
||||
element = session.find.css("input", all=False)
|
||||
|
||||
response = get_element_property(session, element.id, "value")
|
||||
assert_success(response, "foobar")
|
||||
|
||||
|
||||
def test_idl_attribute(session):
|
||||
session.url = inline("<input value=foo>")
|
||||
element = session.find.css("input", all=False)
|
||||
session.execute_script("""arguments[0].value = "bar";""", args=(element,))
|
||||
|
||||
response = get_element_property(session, element.id, "value")
|
||||
assert_success(response, "bar")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("js_primitive,py_primitive", [
|
||||
("\"foobar\"", "foobar"),
|
||||
(42, 42),
|
||||
([], []),
|
||||
({}, {}),
|
||||
("null", None),
|
||||
("undefined", None),
|
||||
])
|
||||
def test_primitives(session, js_primitive, py_primitive):
|
||||
session.url = inline("""
|
||||
<input>
|
||||
|
||||
<script>
|
||||
const input = document.querySelector("input");
|
||||
input.foobar = {js_primitive};
|
||||
</script>
|
||||
""".format(js_primitive=js_primitive))
|
||||
element = session.find.css("input", all=False)
|
||||
|
||||
response = get_element_property(session, element.id, "foobar")
|
||||
assert_success(response, py_primitive)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("js_primitive,py_primitive", [
|
||||
("\"foobar\"", "foobar"),
|
||||
(42, 42),
|
||||
([], []),
|
||||
({}, {}),
|
||||
("null", None),
|
||||
("undefined", None),
|
||||
])
|
||||
def test_primitives_set_by_execute_script(session, js_primitive, py_primitive):
|
||||
session.url = inline("<input>")
|
||||
element = session.find.css("input", all=False)
|
||||
session.execute_script("arguments[0].foobar = {}".format(js_primitive), args=(element,))
|
||||
|
||||
response = get_element_property(session, element.id, "foobar")
|
||||
assert_success(response, py_primitive)
|
||||
|
||||
|
||||
def test_mutated_element(session):
|
||||
session.url = inline("<input type=checkbox>")
|
||||
element = session.find.css("input", all=False)
|
||||
element.click()
|
||||
assert session.execute_script("return arguments[0].hasAttribute('checked')", args=(element,)) is False
|
||||
|
||||
result = get_element_property(session, element.id, "checked")
|
||||
assert_success(result, True)
|
||||
response = get_element_property(session, element.id, "checked")
|
||||
assert_success(response, True)
|
||||
|
|
|
@ -52,8 +52,8 @@ def test_get_named_cookie(session, url):
|
|||
|
||||
# same formatting as Date.toUTCString() in javascript
|
||||
utc_string_format = "%a, %d %b %Y %H:%M:%S"
|
||||
a_year_from_now = (datetime.utcnow() + timedelta(days=365)).strftime(utc_string_format)
|
||||
session.execute_script("document.cookie = 'foo=bar;expires=%s'" % a_year_from_now)
|
||||
a_day_from_now = (datetime.utcnow() + timedelta(days=1)).strftime(utc_string_format)
|
||||
session.execute_script("document.cookie = 'foo=bar;expires=%s'" % a_day_from_now)
|
||||
|
||||
result = get_named_cookie(session, "foo")
|
||||
cookie = assert_success(result)
|
||||
|
@ -70,7 +70,7 @@ def test_get_named_cookie(session, url):
|
|||
assert cookie["value"] == "bar"
|
||||
# convert from seconds since epoch
|
||||
assert datetime.utcfromtimestamp(
|
||||
cookie["expiry"]).strftime(utc_string_format) == a_year_from_now
|
||||
cookie["expiry"]).strftime(utc_string_format) == a_day_from_now
|
||||
|
||||
|
||||
def test_duplicated_cookie(session, url, server_config):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue