Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gecko Bug 1555704] webdriver: add simple cross-origin WPT tests #17141

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions webdriver/tests/support/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ def current_session():

@pytest.fixture
def url(server_config):
def inner(path, protocol="http", query="", fragment=""):
def inner(path, protocol="http", subdomain="", query="", fragment=""):
domain = server_config["domains"][""][subdomain]
port = server_config["ports"][protocol][0]
host = "%s:%s" % (server_config["browser_host"], port)
host = "%s:%s" % (domain, port)
return urlparse.urlunsplit((protocol, host, path, query, fragment))

inner.__name__ = "url"
Expand Down
9 changes: 9 additions & 0 deletions webdriver/tests/support/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ def hidden(session):
return Poll(session, timeout=3, raises=None).until(hidden)


def document_location(session):
"""
Unlike ``webdriver.Session#url``, which always returns
the top-level browsing context's URL, this returns
the current browsing context's active document's URL.
"""
return session.execute_script("return document.location.href")


def element_rect(session, element):
return session.execute_script("""
let element = arguments[0];
Expand Down
11 changes: 7 additions & 4 deletions webdriver/tests/support/inline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import urllib


def inline(doc, doctype="html", mime="text/html;charset=utf-8", protocol="http"):
def inline(doc,
doctype="html",
mime="text/html;charset=utf-8",
**kwargs):
from .fixtures import server_config, url
build_url = url(server_config())

Expand Down Expand Up @@ -30,11 +33,11 @@ def inline(doc, doctype="html", mime="text/html;charset=utf-8", protocol="http")

return build_url("/webdriver/tests/support/inline.py",
query=urllib.urlencode(query),
protocol=protocol)
**kwargs)


def iframe(doc):
return "<iframe src='%s'></iframe>" % inline(doc)
def iframe(doc, **kwargs):
return "<iframe src='%s'></iframe>" % inline(doc, **kwargs)


def main(request, response):
Expand Down
60 changes: 60 additions & 0 deletions webdriver/tests/switch_to_frame/cross_origin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import webdriver.protocol as protocol

from tests.support.asserts import assert_success
from tests.support.helpers import document_location
from tests.support.inline import (
iframe,
inline,
)


"""
Tests that WebDriver can transcend site origins.

Many modern browsers impose strict cross-origin checks,
and WebDriver should be able to transcend these.

Although an implementation detail, certain browsers
also enforce process isolation based on site origin.
This is known to sometimes cause problems for WebDriver implementations.
"""


def switch_to_frame(session, frame):
return session.transport.send(
"POST", "/session/{session_id}/frame".format(**vars(session)),
{"id": frame},
encoder=protocol.Encoder, decoder=protocol.Decoder,
session=session)


def test_cross_origin_iframe(session, server_config):
session.url = inline(iframe("", subdomain="www"))
frame_element = session.find.css("iframe", all=False)

response = switch_to_frame(session, frame_element)
value = assert_success(response)
assert document_location(session).startswith(
"http://www.{}".format(server_config["browser_host"]))


def test_nested_cross_origin_iframe(session, server_config):
frame2 = iframe("", subdomain="www.www")
frame1 = iframe(frame2, subdomain="www")
top_doc = inline(frame1, subdomain="")

session.url = top_doc
assert document_location(session).startswith(
"http://{}".format(server_config["browser_host"]))

frame1_el = session.find.css("iframe", all=False)
response = switch_to_frame(session, frame1_el)
value = assert_success(response)
assert document_location(session).startswith(
"http://www.{}".format(server_config["browser_host"]))

frame2_el = session.find.css("iframe", all=False)
response = switch_to_frame(session, frame2_el)
value = assert_success(response)
assert document_location(session).startswith(
"http://www.www.{}".format(server_config["browser_host"]))