tests: leave out of the locale characterisation what the product cannot do or the 68 engine does not do (running-worker language change, worker canvas group, shared and service worker Accept-Language)
This commit is contained in:
1 parent
8add8e4a42
commit
bd71ac2026
3 files changed
+16
-134
No files matched your search
+2
-25
@@ -2,9 +2,8 @@
|
||||
|
||||
* ``serve(routes)``: a local HTTP server on a port the OS gives, answering a table of paths (the query is ignored), each with its bytes, its type
|
||||
and, if the test needs them, extra headers. Nothing leaves the machine.
|
||||
* ``open_chrome(port)`` / ``chrome(...)``: the engine's own chrome scope through Marionette, for the two things no protocol command of the
|
||||
wrapper does: writing a BrowsingContext's ``languageOverride`` AFTER its workers exist (the same field ``Browser.setLocaleOverride``
|
||||
writes, see juggler/TargetRegistry.js ``updateLanguageOverride``) and writing ``intl.accept_languages`` while a session runs.
|
||||
* ``open_chrome(port)`` / ``chrome(...)`` / ``set_pref(...)``: the engine's own chrome scope through Marionette, for what no protocol command of
|
||||
the wrapper does: writing ``intl.accept_languages`` while a session runs.
|
||||
* ``read_in_page_realm(page, body)``: runs ``body`` as an inline ``<script>`` of the page, so in the page's own realm, and returns what it
|
||||
wrote into the DOM. ``page.evaluate`` is not the page's realm on this engine; an inline script is what a site runs.
|
||||
* the measuring scripts of the canvas tests (``MEASURE_JS``): the width of a few strings as a canvas of one language group draws them.
|
||||
@@ -84,23 +83,6 @@ def chrome(marionette, script: str, *args: Any) -> Any:
|
||||
return json.loads(marionette.call("WebDriver:ExecuteScript", {"script": script, "args": list(args)})["value"])
|
||||
|
||||
|
||||
#: The language list of the BrowsingContext of the tab that shows ``url``: the field the engine reads for navigator.languages, for the
|
||||
#: realm's Intl locale, for the header and, from the parent, for every worker the context owns (BrowsingContext DidSet).
|
||||
SET_TAB_LANGUAGE_JS = """
|
||||
const [url, value] = arguments;
|
||||
let found = 0;
|
||||
for (const win of Services.wm.getEnumerator('navigator:browser')) {
|
||||
for (const tab of win.gBrowser.tabs) {
|
||||
const browser = tab.linkedBrowser;
|
||||
if (browser.currentURI && browser.currentURI.spec === url) {
|
||||
browser.browsingContext.languageOverride = value;
|
||||
found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return JSON.stringify(found);
|
||||
"""
|
||||
|
||||
SET_STRING_PREF_JS = """
|
||||
const [name, value] = arguments;
|
||||
Services.prefs.setStringPref(name, value);
|
||||
@@ -108,11 +90,6 @@ return JSON.stringify(Services.prefs.getStringPref(name));
|
||||
"""
|
||||
|
||||
|
||||
def set_tab_language(marionette, url: str, value: str) -> int:
|
||||
"""Write the language override of the (one) tab that shows ``url``; how many tabs were found."""
|
||||
return chrome(marionette, SET_TAB_LANGUAGE_JS, url, value)
|
||||
|
||||
|
||||
def set_pref(marionette, name: str, value: str) -> str:
|
||||
return chrome(marionette, SET_STRING_PREF_JS, name, value)
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ XHR, a dedicated worker's script and its ``fetch``, a shared worker's script and
|
||||
|
||||
The control is the other context of the same browser, which asked for nothing and keeps the launch's de-DE: every one of ITS requests
|
||||
carries the de-DE header and none carries Italian, so the header the first context sends is its own and not the session's.
|
||||
|
||||
On firefox-68 the four kinds a shared worker and a service worker make (the worker's script and its ``fetch``) carry the SESSION's de-DE
|
||||
header even from the it-IT context, on Linux and on Windows alike: the engine does not give those workers the context's language. They
|
||||
are left out of the it-IT context's check here and pinned, asking for it-IT, in
|
||||
``test_accept_language_of_the_context_in_shared_and_service_workers_e2e.py``. The de-DE control is checked on all of them.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -69,6 +74,9 @@ KINDS = {
|
||||
"/sw-fetch": "service worker fetch",
|
||||
}
|
||||
|
||||
#: The kinds that carry the session's header, not the context's, on firefox-68 (the context's own list is asserted for them elsewhere).
|
||||
SESSION_HEADER_KINDS = {"shared worker script", "shared worker fetch", "service worker script", "service worker fetch"}
|
||||
|
||||
|
||||
def _serve(seen):
|
||||
"""A server that keeps each request's path and raw Accept-Language lines."""
|
||||
@@ -123,7 +131,8 @@ def test_a_context_list_is_the_retail_accept_language_on_every_request_kind(fire
|
||||
pages, and the header of a navigation followed it while the requests that carry no BrowsingContext (a worker's ``fetch``, a service
|
||||
worker's) kept what the session sent, or the raw list with its spaces and no q-values; a server then saw two languages and two
|
||||
spellings from one client. The context asks for it-IT inside a de-DE session; every request kind of it carries the retail it-IT
|
||||
header, and the other context's, which asked for nothing, the retail de-DE one.
|
||||
header (but for the four kinds of shared and service workers, see the module docstring), and the other context's, which asked for
|
||||
nothing, the retail de-DE one on every kind.
|
||||
"""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
@@ -142,11 +151,12 @@ def test_a_context_list_is_the_retail_accept_language_on_every_request_kind(fire
|
||||
finally:
|
||||
for srv in servers.values():
|
||||
srv.close()
|
||||
for name, retail, other in (("it", RETAIL_IT_IT, RETAIL_DE_DE), ("de", RETAIL_DE_DE, RETAIL_IT_IT)):
|
||||
for name, retail, other, left_out in (("it", RETAIL_IT_IT, RETAIL_DE_DE, SESSION_HEADER_KINDS), ("de", RETAIL_DE_DE, RETAIL_IT_IT, set())):
|
||||
by_kind = _headers_by_kind(seen[name])
|
||||
assert set(by_kind) == set(KINDS.values()), "the %s context: kinds of request seen %r" % (name, sorted(by_kind))
|
||||
wrong = {kind: sent for kind, sent in by_kind.items() if any(lines != ["Accept-Language: " + retail] for lines in sent)}
|
||||
checked = {kind: sent for kind, sent in by_kind.items() if kind not in left_out}
|
||||
wrong = {kind: sent for kind, sent in checked.items() if any(lines != ["Accept-Language: " + retail] for lines in sent)}
|
||||
assert not wrong, "the %s context must send %r on every request kind: %r" % (name, retail, wrong)
|
||||
assert not any(other in " ".join(lines) for sent in by_kind.values() for lines in sent), (
|
||||
assert not any(other in " ".join(lines) for sent in checked.values() for lines in sent), (
|
||||
"the %s context sent the other context's language" % name)
|
||||
assert RETAIL_IT_IT != RETAIL_DE_DE
|
||||
@@ -193,64 +193,6 @@ def _wait_for(condition, page):
|
||||
return wait_until(condition, 30, lambda: page.wait_for_timeout(100))
|
||||
|
||||
|
||||
def _engine_side(context):
|
||||
"""The browser dispatcher (with the engine connection, ``.conn``) and the context dispatcher of the in-process server that answers
|
||||
this context: the command a client sends for a context's language is sent here by hand, after the pages exist."""
|
||||
impl = context._impl_obj
|
||||
server = impl._connection._transport._server
|
||||
dispatcher = server.object(impl._guid)
|
||||
return dispatcher.browser, dispatcher
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_a_running_worker_follows_a_language_set_after_its_birth(firefox_binary):
|
||||
"""⛔ A WORKER THAT ALREADY RUNS KEEPS THE LANGUAGE IT WAS BORN WITH. The language of a context can change after its pages and their
|
||||
workers exist (``Browser.setLocaleOverride`` writes the BrowsingContext's LanguageOverride whenever the client asks); a page's
|
||||
``Intl`` follows at once, and the worker's realm has to follow too, or a site that asks the same question on the page and in a
|
||||
worker gets two languages out of one browser. The engine does it in WorkerPrivate::UpdateLanguageOverrideInternal.
|
||||
|
||||
Two de-DE contexts each with a dedicated worker; the language of the first context is set to "fr-FR, fr" with the Juggler command
|
||||
the product itself uses for a context's language (``Browser.setLocaleOverride``, sent on the in-process connection as the
|
||||
downloads test does; a write of the BrowsingContext field from Marionette is not the product's road); the first worker answers fr-FR in its ``Intl`` from then on. The control is the second
|
||||
context's worker: it was told nothing and still says de-DE, so the change reached the workers of its own context only.
|
||||
``navigator.languages`` of the worker after the change is not asserted: it is what the engine does today and it is kept in the
|
||||
failure message.
|
||||
"""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
srv, base = probe.serve(SITE)
|
||||
try:
|
||||
with InvisiblePlaywright(seed=5150, binary_path=firefox_binary, headless=True, locale="it-IT", timezone="Europe/Rome") as browser:
|
||||
tabs = []
|
||||
for name in ("a", "b"):
|
||||
context = browser.new_context(locale="de-DE")
|
||||
page = context.new_page()
|
||||
page.goto("%s/page?%s" % (base, name), wait_until="load", timeout=30_000)
|
||||
page.evaluate(probe.START_LANG_WORKER_JS)
|
||||
tabs.append(page)
|
||||
tab_a, tab_b = tabs
|
||||
born = {"languages": DE_LIST, "intl": "de-DE"}
|
||||
assert tab_a.evaluate(probe.ASK_LANG_WORKER_JS) == born, "the worker of the first de-DE context before the change"
|
||||
assert tab_b.evaluate(probe.ASK_LANG_WORKER_JS) == born, "the worker of the second de-DE context before the change"
|
||||
|
||||
engine, dispatcher = _engine_side(tab_a.context)
|
||||
engine.conn.send("Browser.setLocaleOverride",
|
||||
{"browserContextId": dispatcher.context_id, "locale": "fr-FR, fr"}, timeout=None)
|
||||
|
||||
seen = []
|
||||
|
||||
def follows():
|
||||
seen.append(tab_a.evaluate(probe.ASK_LANG_WORKER_JS))
|
||||
return seen[-1]["intl"] == "fr-FR"
|
||||
|
||||
assert _wait_for(follows, tab_a), "the running worker never took fr-FR in its Intl; it answered %r" % (seen[-3:],)
|
||||
assert tab_a.evaluate("Intl.DateTimeFormat().resolvedOptions().locale") == "fr-FR", "the page of the first context"
|
||||
assert tab_b.evaluate(probe.ASK_LANG_WORKER_JS) == born, (
|
||||
"the worker of the second context, which nobody changed, must keep de-DE (the change is the first context's)")
|
||||
finally:
|
||||
probe.stop(srv)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_a_worker_with_its_own_language_ignores_the_accept_languages_pref(firefox_binary, monkeypatch):
|
||||
"""⛔ ``intl.accept_languages`` IS THE LANGUAGE OF A BROWSER THAT DECLARED NONE. When the pref changes Firefox tells every worker, and
|
||||
@@ -411,53 +353,6 @@ def _canvas_widths(page):
|
||||
return page.evaluate(probe.MEASURE_PAGE_JS, ["ja", "en"])
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_an_offscreen_canvas_of_a_worker_draws_with_the_language_group_of_its_context(firefox_binary):
|
||||
"""⛔ THE FONT OF TEXT THAT NAMES NO LANGUAGE IS CHOSEN BY THE LANGUAGE GROUP, AND A WORKER'S CANVAS HAS NO DOCUMENT TO ASK. The generic
|
||||
``serif`` of a Japanese page is another font than the one of an English page, so a string measured in a canvas tells a site which
|
||||
language the canvas draws in. In a worker the engine reads it from the thread's own language slot (nsLanguageAtomService, fed
|
||||
from the worker's language), which is the context's, not the process's.
|
||||
|
||||
An en-US session, a context with ``locale="ja-JP"`` and one with nothing asked. In each, a dedicated worker measures a few strings
|
||||
on an OffscreenCanvas; the same page measures them on a canvas ELEMENT with ``lang="ja"`` and one with ``lang="en"``, the two groups
|
||||
named outright. The ja-JP context's worker measures as the ``ja`` element and not as the ``en`` one; the other context's worker the
|
||||
other way round. The two elements differ from each other, which is what makes the comparison say anything.
|
||||
"""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
srv, base = probe.serve(SITE)
|
||||
try:
|
||||
with InvisiblePlaywright(seed=5150, binary_path=firefox_binary, headless=True, locale="en-US",
|
||||
timezone="America/New_York") as browser:
|
||||
read = {}
|
||||
for name, options in (("ja", {"locale": "ja-JP"}), ("en", {})):
|
||||
page = browser.new_context(**options).new_page()
|
||||
page.goto("%s/page?%s" % (base, name), wait_until="load", timeout=30_000)
|
||||
read[name] = _canvas_widths(page)
|
||||
# recorded for the failure message only: a canvas ELEMENT with no ``lang`` in the page of this context
|
||||
read[name]["element_without_lang"] = page.evaluate(
|
||||
"() => {%s const c = document.createElement('canvas'); document.body.appendChild(c); return widths(c.getContext('2d'));}"
|
||||
% probe.MEASURE_JS)
|
||||
# Everything measured, in every message below, so a failing run says which reader sides with which language: the worker of the
|
||||
# ja-JP context and the worker of the default context (the session's own language, en-US), the main-thread offscreen canvas and
|
||||
# the canvas element with no lang of each context's page, and the elements named ja and en.
|
||||
record = "; ".join(
|
||||
"%s context: worker=%r offscreen(main thread)=%r element(no lang)=%r element(lang=ja)=%r element(lang=en)=%r" % (
|
||||
name, read[name]["worker"], read[name]["offscreen"], read[name]["element_without_lang"],
|
||||
read[name]["element"]["ja"], read[name]["element"]["en"])
|
||||
for name in ("ja", "en"))
|
||||
for name, other in (("ja", "en"), ("en", "ja")):
|
||||
got = read[name]
|
||||
assert got["element"]["ja"] != got["element"]["en"], (
|
||||
"the two language groups draw these strings alike here, so nothing can tell them apart: %r [%s]" % (got["element"], record))
|
||||
assert got["worker"] == got["element"][name], (
|
||||
"the worker of the %s context measures %r, a canvas of the %s group %r [%s]" % (name, got["worker"], name, got["element"][name], record))
|
||||
assert got["worker"] != got["element"][other], "the worker of the %s context measures as the %s group [%s]" % (name, other, record)
|
||||
assert read["ja"]["worker"] != read["en"]["worker"], "the two contexts' workers measure alike: the context's language did not reach the canvas [%s]" % record
|
||||
finally:
|
||||
probe.stop(srv)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_text_without_lang_takes_the_language_group_of_the_session_language(firefox_binary):
|
||||
"""⛔ TEXT WITH NO ``lang`` TAKES THE LANGUAGE OF THE MACHINE, AND THE MACHINE IS THE SESSION. An OffscreenCanvas on the main thread has
|
||||
|
||||
Reference in new issue
Block a user