Skip to content

Commit

Permalink
[wdspec] Improve tests for "Get Title" and add site-isolation test.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D88016

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1660426
gecko-commit: 81666c6d64bf17651ddc3445e6629ca652dcbb7d
gecko-integration-branch: autoland
gecko-reviewers: maja_zf, marionette-reviewers
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Aug 26, 2020
1 parent bd12dae commit a7f851a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 34 deletions.
53 changes: 19 additions & 34 deletions webdriver/tests/get_title/get.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,52 @@
from six import text_type

from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
from tests.support.sync import Poll


def read_global(session, name):
return session.execute_script("return %s;" % name)


def get_title(session):
return session.transport.send(
"GET", "session/{session_id}/title".format(**vars(session)))


def test_no_browsing_context(session, closed_window):
response = get_title(session)
assert_error(response, "no such window")
def test_payload(session):
session.start()

response = get_title(session)
value = assert_success(response)
assert isinstance(value, text_type)

def test_title_from_top_context(session):
session.url = inline("<title>Foobar</title><h2>Hello</h2>")

result = get_title(session)
assert_success(result, read_global(session, "document.title"))
def test_no_browsing_context(session, closed_window):
response = get_title(session)
assert_error(response, "no such window")


def test_title_with_duplicate_element(session):
def test_with_duplicated_title(session):
session.url = inline("<title>First</title><title>Second</title>")

result = get_title(session)
assert_success(result, read_global(session, "document.title"))
assert_success(result, "First")


def test_title_without_element(session):
def test_without_title(session):
session.url = inline("<h2>Hello</h2>")

result = get_title(session)
assert_success(result, read_global(session, "document.title"))

assert_success(result, "")

def test_title_after_modification(session):
def title():
return read_global(session, "document.title")

def test_after_modification(session):
session.url = inline("<title>Initial</title><h2>Hello</h2>")
session.execute_script("document.title = 'Updated'")

wait = Poll(session, message='Document title does not match "{}"'.format(title()))
wait.until(lambda s: assert_success(get_title(s)) == title())
result = get_title(session)
assert_success(result, "Updated")


def test_title_strip_and_collapse(session):
def test_strip_and_collapse(session):
document = "<title> a b\tc\nd\t \n e\t\n </title><h2>Hello</h2>"
session.url = inline(document)

result = get_title(session)
assert_success(result, read_global(session, "document.title"))


def test_title_from_frame(session, create_frame):
session.url = inline("<title>Parent</title>parent")

session.switch_frame(create_frame())
session.switch_frame(create_frame())

result = get_title(session)
assert_success(result, "Parent")
assert_success(result, "a b c d e")
70 changes: 70 additions & 0 deletions webdriver/tests/get_title/iframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

from tests.support.asserts import assert_success
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.
"""

frame_doc = inline("<title>cheese</title><p>frame")
one_frame_doc = inline("<title>bar</title><iframe src='%s'></iframe>" % frame_doc)
nested_frames_doc = inline("<title>foo</title><iframe src='%s'></iframe>" % one_frame_doc)


def get_title(session):
return session.transport.send(
"GET", "session/{session_id}/title".format(**vars(session)))


def test_no_iframe(session):
session.url = inline("<title>Foobar</title><h2>Hello</h2>")

result = get_title(session)
assert_success(result, "Foobar")


def test_iframe(session):
session.url = one_frame_doc

frame = session.find.css("iframe", all=False)
session.switch_frame(frame)
session.find.css("p", all=False)

response = get_title(session)
assert_success(response, "bar")


def test_nested_iframe(session):
session.url = nested_frames_doc

outer_frame = session.find.css("iframe", all=False)
session.switch_frame(outer_frame)

inner_frame = session.find.css("iframe", all=False)
session.switch_frame(inner_frame)
session.find.css("p", all=False)

response = get_title(session)
assert_success(response, "foo")


@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
def test_origin(session, domain, url):
session.url = inline("<title>foo</title>{}".format(
iframe("<title>bar</title><p>frame", domain=domain)))

frame = session.find.css("iframe", all=False)
session.switch_frame(frame)
session.find.css("p", all=False)

response = get_title(session)
assert_success(response, "foo")

0 comments on commit a7f851a

Please sign in to comment.