Skip to content

Commit

Permalink
[wdspec] Fix /webdriver/tests/classic/new_window/new_tab.py | test_fo…
Browse files Browse the repository at this point in the history
…cus_content.

Depends on D163946

Differential Revision: https://phabricator.services.mozilla.com/D204698

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1807868
gecko-commit: e16d9cb7c4a99d8c2f9442fda2e0a3c53d864b14
gecko-reviewers: webdriver-reviewers, jdescottes
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Mar 15, 2024
1 parent cea69e3 commit 9bb9caf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
26 changes: 17 additions & 9 deletions webdriver/tests/classic/new_window/new_tab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tests.support.asserts import assert_success
from tests.support.sync import Poll

from . import opener, window_name

Expand Down Expand Up @@ -63,27 +64,34 @@ def test_sets_no_opener(session):
assert opener(session) is None


def test_focus_content(session, inline):
def test_initial_selection_for_contenteditable(session, inline):
response = new_window(session, type_hint="tab")
value = assert_success(response)
assert value["type"] == "tab"

session.window_handle = value["handle"]

session.url = inline("""
<span contenteditable="true"> abc </span>
<div contenteditable>abc</div>
<script>
const selection = getSelection();
window.onload = async() => {
const initial = document.querySelector("span");
initial.focus();
const initial = document.querySelector("div");
document.onselectionchange = () => {
const selection = document.getSelection();
initial.setAttribute(
"_focused",
selection.anchorNode == initial.firstChild
);
}
};
initial.focus();
</script>
""")

elem = session.find.css("span", all=False)
assert elem.attribute("_focused") == "true"
elem = session.find.css("div", all=False)

wait = Poll(
session,
timeout=5,
message="Initial selection for contenteditable not set")
wait.until(lambda _: elem.attribute("_focused") == "true")
26 changes: 17 additions & 9 deletions webdriver/tests/classic/new_window/new_window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tests.support.asserts import assert_success
from tests.support.sync import Poll

from . import opener, window_name

Expand Down Expand Up @@ -65,26 +66,33 @@ def test_sets_no_opener(session):
assert opener(session) is None


def test_focus_content(session, inline):
def test_initial_selection_for_contenteditable(session, inline):
response = new_window(session, type_hint="window")
value = assert_success(response)

session.window_handle = value["handle"]

session.url = inline("""
<span contenteditable="true"> abc </span>
<div contenteditable>abc</div>
<script>
const selection = getSelection();
window.onload = async() => {
const initial = document.querySelector("span");
initial.focus();
const initial = document.querySelector("div");
document.onselectionchange = () => {
const selection = document.getSelection();
initial.setAttribute(
"_focused",
selection.anchorNode == initial.firstChild
);
}
};
initial.focus();
</script>
""")

elem = session.find.css("span", all=False)
assert elem.attribute("_focused") == "true"
elem = session.find.css("div", all=False)

wait = Poll(
session,
timeout=5,
message="Initial selection for contenteditable not set")
wait.until(lambda _: elem.attribute("_focused") == "true")

0 comments on commit 9bb9caf

Please sign in to comment.