mirror of
https://github.com/servo/servo.git
synced 2025-08-17 19:35:33 +01:00
Update web-platform-tests to revision 6856483bcc86322198f10e0c42385a7f9127eb66
This commit is contained in:
parent
b1a2b6b5bf
commit
ff06f1d031
265 changed files with 7539 additions and 988 deletions
|
@ -1,7 +1,7 @@
|
|||
import math
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
from tests.support.helpers import center_point
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
|
@ -12,28 +12,6 @@ def element_click(session, element):
|
|||
element_id=element.id))
|
||||
|
||||
|
||||
def center_point(element):
|
||||
"""Calculates the in-view center point of a web element."""
|
||||
inner_width, inner_height = element.session.execute_script(
|
||||
"return [window.innerWidth, window.innerHeight]")
|
||||
rect = element.rect
|
||||
|
||||
# calculate the intersection of the rect that is inside the viewport
|
||||
visible = {
|
||||
"left": max(0, min(rect["x"], rect["x"] + rect["width"])),
|
||||
"right": min(inner_width, max(rect["x"], rect["x"] + rect["width"])),
|
||||
"top": max(0, min(rect["y"], rect["y"] + rect["height"])),
|
||||
"bottom": min(inner_height, max(rect["y"], rect["y"] + rect["height"])),
|
||||
}
|
||||
|
||||
# arrive at the centre point of the visible rectangle
|
||||
x = (visible["left"] + visible["right"]) / 2.0
|
||||
y = (visible["top"] + visible["bottom"]) / 2.0
|
||||
|
||||
# convert to CSS pixels, as centre point can be float
|
||||
return (math.floor(x), math.floor(y))
|
||||
|
||||
|
||||
def square(size):
|
||||
return inline("""
|
||||
<style>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
from tests.support.helpers import center_point
|
||||
from tests.support.inline import inline
|
||||
|
||||
def element_click(session, element):
|
||||
|
@ -10,6 +11,13 @@ def element_click(session, element):
|
|||
element_id=element.id))
|
||||
|
||||
|
||||
def assert_one_click(session):
|
||||
"""Asserts there has only been one click, and returns that."""
|
||||
clicks = session.execute_script("return window.clicks")
|
||||
assert len(clicks) == 1
|
||||
return tuple(clicks[0])
|
||||
|
||||
|
||||
def test_scroll_into_view(session):
|
||||
session.url = inline("""
|
||||
<input type=text value=Federer
|
||||
|
@ -27,3 +35,39 @@ def test_scroll_into_view(session):
|
|||
(rect["top"] + rect["height"]) <= window.innerHeight &&
|
||||
(rect["left"] + rect["width"]) <= window.innerWidth;
|
||||
""", args=(element,)) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("offset", range(9, 0, -1))
|
||||
def test_partially_visible_does_not_scroll(session, offset):
|
||||
session.url = inline("""
|
||||
<style>
|
||||
body {{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}}
|
||||
|
||||
div {{
|
||||
background: blue;
|
||||
height: 200px;
|
||||
|
||||
/* make N pixels visible in the viewport */
|
||||
margin-top: calc(100vh - {offset}px);
|
||||
}}
|
||||
</style>
|
||||
|
||||
<div></div>
|
||||
|
||||
<script>
|
||||
window.clicks = [];
|
||||
let target = document.querySelector("div");
|
||||
target.addEventListener("click", ({{clientX, clientY}}) => window.clicks.push([clientX, clientY]));
|
||||
</script>
|
||||
""".format(offset=offset))
|
||||
target = session.find.css("div", all=False)
|
||||
assert session.execute_script("return window.scrollY") == 0
|
||||
|
||||
response = element_click(session, target)
|
||||
assert_success(response)
|
||||
assert session.execute_script("return window.scrollY") == 0
|
||||
click_point = assert_one_click(session)
|
||||
assert click_point == center_point(target)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# META: timeout=long
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_success
|
||||
from tests.support.helpers import is_fullscreen
|
||||
|
||||
|
||||
def fullscreen_window(session):
|
||||
return session.transport.send(
|
||||
"POST", "session/{session_id}/window/fullscreen".format(**vars(session)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("i", range(5))
|
||||
def test_stress(session, i):
|
||||
assert not is_fullscreen(session)
|
||||
response = fullscreen_window(session)
|
||||
assert_success(response)
|
||||
assert is_fullscreen(session)
|
|
@ -0,0 +1,42 @@
|
|||
# META: timeout=long
|
||||
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_success
|
||||
from tests.support.helpers import document_hidden
|
||||
|
||||
|
||||
def maximize_window(session):
|
||||
response = session.transport.send(
|
||||
"POST", "session/{session_id}/window/maximize".format(**vars(session)))
|
||||
rect = assert_success(response)
|
||||
return (rect["width"], rect["height"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("i", range(5))
|
||||
def test_stress(session, i):
|
||||
"""
|
||||
Without defining the heuristics of each platform WebDriver runs on,
|
||||
the best we can do is to test that maximization occurs synchronously.
|
||||
|
||||
Not all systems and window managers support maximizing the window,
|
||||
but they are expected to do their best. The minimum requirement
|
||||
is that the maximized window is larger than its original size.
|
||||
|
||||
To ensure the maximization happened synchronously, we test
|
||||
that the size hasn't changed after a short amount of time,
|
||||
using a thread suspend. This is not ideal, but the best we
|
||||
can do given the level of platform ambiguity implied by WebDriver.
|
||||
"""
|
||||
session.window.size = (100, 100)
|
||||
session.window.position = (0, 0)
|
||||
original_size = session.window.size
|
||||
|
||||
size_after_maximize = maximize_window(session)
|
||||
assert size_after_maximize > original_size
|
||||
|
||||
t_end = time.time() + 3
|
||||
while time.time() < t_end:
|
||||
assert session.window.size == size_after_maximize
|
|
@ -0,0 +1,19 @@
|
|||
# META: timeout=long
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_success
|
||||
from tests.support.helpers import document_hidden
|
||||
|
||||
|
||||
def minimize_window(session):
|
||||
return session.transport.send(
|
||||
"POST", "session/{session_id}/window/minimize".format(**vars(session)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("i", range(5))
|
||||
def test_stress(session, i):
|
||||
assert not document_hidden(session)
|
||||
response = minimize_window(session)
|
||||
assert_success(response)
|
||||
assert document_hidden(session)
|
|
@ -5,7 +5,8 @@ import pytest
|
|||
from webdriver.transport import Response
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
from tests.support.helpers import document_hidden, is_fullscreen
|
||||
from tests.support.helpers import (available_screen_size, document_hidden,
|
||||
is_fullscreen, screen_size)
|
||||
|
||||
|
||||
def set_window_rect(session, rect):
|
||||
|
@ -172,38 +173,31 @@ def test_height_width(session):
|
|||
session.window.position = (50, 50)
|
||||
|
||||
original = session.window.rect
|
||||
max = session.execute_script("""
|
||||
return {
|
||||
width: window.screen.availWidth,
|
||||
height: window.screen.availHeight,
|
||||
}""")
|
||||
screen_width, screen_height = screen_size(session)
|
||||
|
||||
response = set_window_rect(session, {
|
||||
"width": max["width"] - 100,
|
||||
"height": max["height"] - 100
|
||||
"width": screen_width - 100,
|
||||
"height": screen_height - 100
|
||||
})
|
||||
assert_success(response, {
|
||||
"x": original["x"],
|
||||
"y": original["y"],
|
||||
"width": max["width"] - 100,
|
||||
"height": max["height"] - 100
|
||||
"width": screen_width - 100,
|
||||
"height": screen_height - 100,
|
||||
})
|
||||
|
||||
|
||||
def test_height_width_larger_than_max(session):
|
||||
max = session.execute_script("""
|
||||
return {
|
||||
width: window.screen.availWidth,
|
||||
height: window.screen.availHeight,
|
||||
}""")
|
||||
screen_width, screen_height = screen_size(session)
|
||||
avail_width, avail_height = available_screen_size(session)
|
||||
|
||||
response = set_window_rect(session, {
|
||||
"width": max["width"] + 100,
|
||||
"height": max["height"] + 100
|
||||
"width": screen_width + 100,
|
||||
"height": screen_height + 100
|
||||
})
|
||||
rect = assert_success(response)
|
||||
assert rect["width"] >= max["width"]
|
||||
assert rect["height"] >= max["height"]
|
||||
assert rect["width"] >= avail_width
|
||||
assert rect["height"] >= avail_height
|
||||
|
||||
|
||||
def test_height_width_as_current(session):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import math
|
||||
import sys
|
||||
|
||||
import webdriver
|
||||
|
@ -107,11 +108,33 @@ def clear_all_cookies(session):
|
|||
|
||||
def document_dimensions(session):
|
||||
return tuple(session.execute_script("""
|
||||
let {width, height} = document.documentElement.getBoundingClientRect();
|
||||
return [width, height];
|
||||
let rect = document.documentElement.getBoundingClientRect();
|
||||
return [rect.width, rect.height];
|
||||
"""))
|
||||
|
||||
|
||||
def center_point(element):
|
||||
"""Calculates the in-view center point of a web element."""
|
||||
inner_width, inner_height = element.session.execute_script(
|
||||
"return [window.innerWidth, window.innerHeight]")
|
||||
rect = element.rect
|
||||
|
||||
# calculate the intersection of the rect that is inside the viewport
|
||||
visible = {
|
||||
"left": max(0, min(rect["x"], rect["x"] + rect["width"])),
|
||||
"right": min(inner_width, max(rect["x"], rect["x"] + rect["width"])),
|
||||
"top": max(0, min(rect["y"], rect["y"] + rect["height"])),
|
||||
"bottom": min(inner_height, max(rect["y"], rect["y"] + rect["height"])),
|
||||
}
|
||||
|
||||
# arrive at the centre point of the visible rectangle
|
||||
x = (visible["left"] + visible["right"]) / 2.0
|
||||
y = (visible["top"] + visible["bottom"]) / 2.0
|
||||
|
||||
# convert to CSS pixels, as centre point can be float
|
||||
return (math.floor(x), math.floor(y))
|
||||
|
||||
|
||||
def document_hidden(session):
|
||||
"""Polls for the document to become hidden."""
|
||||
def hidden(session):
|
||||
|
@ -122,13 +145,13 @@ def document_hidden(session):
|
|||
def element_rect(session, element):
|
||||
return session.execute_script("""
|
||||
let element = arguments[0];
|
||||
let {height, left, top, width} = element.getBoundingClientRect();
|
||||
let rect = element.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
x: left + window.pageXOffset,
|
||||
y: top + window.pageYOffset,
|
||||
width: width,
|
||||
height: height,
|
||||
x: rect.left + window.pageXOffset,
|
||||
y: rect.top + window.pageYOffset,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
};
|
||||
""", args=(element,))
|
||||
|
||||
|
@ -158,3 +181,34 @@ def is_fullscreen(session):
|
|||
return session.execute_script("""
|
||||
return !!(window.fullScreen || document.webkitIsFullScreen)
|
||||
""")
|
||||
|
||||
|
||||
def document_dimensions(session):
|
||||
return tuple(session.execute_script("""
|
||||
let {devicePixelRatio} = window;
|
||||
let {width, height} = document.documentElement.getBoundingClientRect();
|
||||
return [width * devicePixelRatio, height * devicePixelRatio];
|
||||
"""))
|
||||
|
||||
|
||||
def screen_size(session):
|
||||
"""Returns the available width/height size of the screen."""
|
||||
return tuple(session.execute_script("""
|
||||
return [
|
||||
screen.availWidth,
|
||||
screen.availHeight,
|
||||
];
|
||||
"""))
|
||||
|
||||
|
||||
def available_screen_size(session):
|
||||
"""
|
||||
Returns the effective available screen width/height size,
|
||||
excluding any fixed window manager elements.
|
||||
"""
|
||||
return tuple(session.execute_script("""
|
||||
return [
|
||||
screen.availWidth - screen.availLeft,
|
||||
screen.availHeight - screen.availTop,
|
||||
];
|
||||
"""))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
def element_rect(session, element):
|
||||
return session.execute_script("""
|
||||
let {devicePixelRatio} = window;
|
||||
let devicePixelRatio = window.devicePixelRatio;
|
||||
let rect = arguments[0].getBoundingClientRect();
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
def document_dimensions(session):
|
||||
return tuple(session.execute_script("""
|
||||
let {devicePixelRatio} = window;
|
||||
let {width, height} = document.documentElement.getBoundingClientRect();
|
||||
return [Math.floor(width * devicePixelRatio), Math.floor(height * devicePixelRatio)];
|
||||
let devicePixelRatio = window.devicePixelRatio;
|
||||
let rect = document.documentElement.getBoundingClientRect();
|
||||
return [Math.floor(rect.width * devicePixelRatio), Math.floor(rect.height * devicePixelRatio)];
|
||||
"""))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue