зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1660426 - [wdspec] Improve tests for "Get Title" and add site-isolation test. r=maja_zf,marionette-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D88016
This commit is contained in:
Родитель
e7ca7c2a3f
Коммит
f1954e832e
|
@ -15,6 +15,7 @@ from marionette_driver.marionette import Alert
|
|||
from marionette_harness import (
|
||||
MarionetteTestCase,
|
||||
run_if_manage_instance,
|
||||
skip,
|
||||
WindowManagerMixin,
|
||||
)
|
||||
|
||||
|
@ -163,6 +164,23 @@ class TestNavigate(BaseNavigationTestCase):
|
|||
self.marionette.navigate(self.test_page_frameset)
|
||||
self.marionette.find_element(By.NAME, "third")
|
||||
|
||||
@skip("https://bugzilla.mozilla.org/show_bug.cgi?id=1255946")
|
||||
def test_navigate_top_frame_from_nested_context(self):
|
||||
self.marionette.navigate(inline("""<title>foo</title>
|
||||
<iframe src="{}">""".format(inline("""<title>bar</title>
|
||||
<a href="{}" target=_top>consume top frame</a>""".format(inline("<title>baz</title>"))))))
|
||||
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
bar = self.marionette.find_element(By.TAG_NAME, "iframe")
|
||||
self.marionette.switch_to_frame(bar)
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
consume = self.marionette.find_element(By.TAG_NAME, "a")
|
||||
consume.click()
|
||||
|
||||
self.assertEqual("baz", self.marionette.title)
|
||||
|
||||
def test_invalid_url(self):
|
||||
with self.assertRaises(errors.MarionetteException):
|
||||
self.marionette.navigate("foo")
|
||||
|
|
|
@ -6,8 +6,7 @@ from __future__ import absolute_import
|
|||
|
||||
from six.moves.urllib.parse import quote
|
||||
|
||||
from marionette_driver.by import By
|
||||
from marionette_harness import MarionetteTestCase, skip
|
||||
from marionette_harness import MarionetteTestCase
|
||||
|
||||
|
||||
def inline(doc):
|
||||
|
@ -15,49 +14,6 @@ def inline(doc):
|
|||
|
||||
|
||||
class TestTitle(MarionetteTestCase):
|
||||
def test_title_from_top(self):
|
||||
def test_basic(self):
|
||||
self.marionette.navigate(inline("<title>foo</title>"))
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
def test_title_from_frame(self):
|
||||
self.marionette.navigate(inline("""<title>foo</title>
|
||||
<iframe src="{}">""".format(inline("<title>bar</title>"))))
|
||||
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
bar = self.marionette.find_element(By.TAG_NAME, "iframe")
|
||||
self.marionette.switch_to_frame(bar)
|
||||
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
def test_title_from_nested_frame(self):
|
||||
self.marionette.navigate(inline("""<title>foo</title>
|
||||
<iframe id=bar src="{}">""".format(inline("""<title>bar</title>
|
||||
<iframe id=baz src="{}">""".format(inline("<title>baz</title>"))))))
|
||||
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
bar = self.marionette.find_element(By.ID, "bar")
|
||||
self.marionette.switch_to_frame(bar)
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
baz = self.marionette.find_element(By.ID, "baz")
|
||||
self.marionette.switch_to_frame(baz)
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
@skip("https://bugzilla.mozilla.org/show_bug.cgi?id=1255946")
|
||||
def test_navigate_top_frame_from_nested_context(self):
|
||||
self.marionette.navigate(inline("""<title>foo</title>
|
||||
<iframe src="{}">""".format(inline("""<title>bar</title>
|
||||
<a href="{}" target=_top>consume top frame</a>""".format(inline("<title>baz</title>"))))))
|
||||
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
bar = self.marionette.find_element(By.TAG_NAME, "iframe")
|
||||
self.marionette.switch_to_frame(bar)
|
||||
self.assertEqual("foo", self.marionette.title)
|
||||
|
||||
consume = self.marionette.find_element(By.TAG_NAME, "a")
|
||||
consume.click()
|
||||
|
||||
self.assertEqual("baz", self.marionette.title)
|
||||
self.assertEqual(self.marionette.title, "foo")
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[iframe.py]
|
||||
expected:
|
||||
if fission: TIMEOUT
|
||||
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1580699
|
|
@ -1,10 +1,7 @@
|
|||
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):
|
||||
|
@ -12,56 +9,44 @@ def get_title(session):
|
|||
"GET", "session/{session_id}/title".format(**vars(session)))
|
||||
|
||||
|
||||
def test_payload(session):
|
||||
session.start()
|
||||
|
||||
response = get_title(session)
|
||||
value = assert_success(response)
|
||||
assert isinstance(value, text_type)
|
||||
|
||||
|
||||
def test_no_browsing_context(session, closed_window):
|
||||
response = get_title(session)
|
||||
assert_error(response, "no such window")
|
||||
|
||||
|
||||
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_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")
|
||||
|
|
|
@ -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")
|
Загрузка…
Ссылка в новой задаче