Files
playwright/tests/test_goto_to_the_same_url_e2e.py
Federico Elia 0d3a710c02 Release 0.58.0: invisible-core 68.80.0 on firefox-68 (the security state of a retail profile) (#552)
* security state: fetch has the engine generate it, every launch gives the core its engine, and CI launches with a fixed ready directory

The core replaced the intermediates list with the security state (intermediates, OneCRL and the CRLite filters, generated by the engine and copied into every profile). The CLI's fetch calls update_security_state(engine=<the binary it installed>); server.py's one write_user_js passes engine=<the executable of the launch> (no engine_argv: a generation is its own headless run, the core's default line). STEALTHFOX_SECURITY_STATE replaces STEALTHFOX_INTERMEDIATES in every workflow that launches the browser (scripts/ci_lab_security_state.py, ci/security-state/ with a result and no data, pinned by sha256); the unit tests' conftest patches ensure_security_state.

Tests: tests/test_cli.py (fetch), tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py, tests/test_ci_lab_security_state.py, tests/test_ci_workflows_set_the_security_state.py, each red on the code of main.

* e2e: the engine's security state - generation, a normal launch, a certificate revoked in a CRLite delta refused at the first navigation, a launch with no state

wrapper.e2e.securitystate, both legs, in the candidate's wrapper-e2e job: the engine launched directly in its generate mode (exit, the contract's keys, the hashes are the sha256 of the files, the bytes of security_state/) and through the core's generate; a normal launch writes no security-state pref and re-imports nothing; with Mozilla's CRLite test filters and a CA on Mozilla's default test key, a leaf with the serial and SCTs of revoked-in-delta.example.com is refused with SEC_ERROR_REVOKED_CERTIFICATE at the first navigation, a valid one loads, and the revoked one loads with no state; a launch with no or an empty state starts. Red on firefox-67 (no generate mode); the last test is a guard.

* ci: the required list only grows, so the two test files of the intermediates lab keep their names and guard that the old road stays gone

The judge of main refused the list of the branch: wrapper.unit.all.* lost tests/test_ci_lab_intermediates.py and tests/test_ci_workflows_set_the_intermediates_list.py. Both files come back with tests that the lab's files and steps are gone and that every leg that had the step sets the security state (red on main, 5 of 5). The unit suites count what the candidate collected (2183 and 2184) plus these 5: 2188 on Linux, 2189 on Windows.

* ci: the unit rows count what the candidate's gate collected (2168 linux, 2169 windows)

* Release 0.58.0: invisible-core 68.80.0 on firefox-68 (the security state of a retail profile)

* test: the frames of a goto are counted once all are announced, within the goto's own deadline

With Fission the innermost frame of a-b-a lives in a third process and its
announcement may reach the client after the top document's load (2 of 3
frames 0.22 s after the goto, run 44888497316). A frame that never comes
is still red.
2026-11-21 11:12:31 +01:00

186 lines
7.5 KiB
Python

"""A goto to the address the page is at ends, whatever the page is made of (firefox-62, sites isolated: strategy 1).
With sites isolated an iframe of another site is born in the process of its page and goes to the process of its site.
A goto to the address the page is already at replaces the document in the same process, and the children of the
document it replaces are detached when the new one is inserted. The page world of such an iframe is its
WindowProxy, which is a remote one by then: the Debugger refused to remove it ("argument is not a global object"),
the detach threw, and the new document was never told to the parent. The goto then ended with "load not reached in 45s
(our navigation nav-N started and has neither committed nor been aborted)", on pages of every size and header
(MDN, css-tricks, cnn), while a goto to another address, a reload and a fragment were fine.
Each goto here must end, with the response, the address and the frames it has: 20 in a row, on the kinds of page below
(a plain one, a big one, one revalidated with a 304, one fresh in the cache, one that is never stored, a page with a
frame of its own site, one with a frame of another site, one with that frame revalidated, and a -> b -> a). Hosts
`a.test`, `b.test` and `c.test` are three sites on one server (`network.dns.localDomains`).
"""
from __future__ import annotations
import asyncio
import hashlib
import threading
import time
from http.server import BaseHTTPRequestHandler
import pytest
from _servers import LocalServer
from _waits import awatch
pytestmark = pytest.mark.e2e
FISSION_ON = {
"fission.autostart": True,
"fission.webContentIsolationStrategy": 1,
"dom.ipc.processCount.webIsolated": 4,
"network.dns.localDomains": "a.test,b.test,c.test",
}
GOTOS = 20
BIG = "<p>" + ("lorem ipsum dolor sit amet " * 40) + "</p>\n"
def _body(kind, port):
"""(html, how many frames the page has, the title)."""
frame = '<iframe src="http://%s:%d/%s"></iframe>'
if kind == "plain":
return "<p>plain</p>", 1
if kind == "big":
return BIG * 1200, 1 # about 1.3 MB
if kind in ("etag", "fresh", "nostore"):
return "<p>%s</p>" % kind, 1
if kind == "same-site-frame":
return "<p>top</p>" + frame % ("a.test", port, "plain"), 2
if kind == "other-site-frame":
return "<p>top</p>" + frame % ("b.test", port, "plain"), 2
if kind == "other-site-frame-etag":
return "<p>top</p>" + frame % ("b.test", port, "etag"), 2
if kind == "a-b-a":
return "<p>top</p>" + frame % ("b.test", port, "mid"), 3
if kind == "mid":
return "<p>mid</p>" + frame % ("a.test", port, "plain"), 2
raise AssertionError(kind)
KINDS = ["plain", "big", "etag", "fresh", "nostore", "same-site-frame", "other-site-frame",
"other-site-frame-etag", "a-b-a"]
@pytest.fixture
def site():
class Handler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
timeout = 10
def log_message(self, *args):
pass
def do_GET(self):
kind = self.path.split("?")[0].strip("/")
port = self.server.server_address[1]
if kind == "favicon.ico":
self.send_response(404)
self.send_header("Content-Length", "0")
self.end_headers()
return
html, _ = _body(kind, port)
body = ("<!doctype html><title>%s</title>%s" % (kind, html)).encode()
headers = {"Content-Type": "text/html"}
if kind.endswith("etag"):
tag = '"%s"' % hashlib.md5(body).hexdigest()
headers["ETag"] = tag
headers["Cache-Control"] = "max-age=0, must-revalidate"
if self.headers.get("If-None-Match") == tag:
self.send_response(304)
for name, value in headers.items():
self.send_header(name, value)
self.send_header("Content-Length", "0")
self.end_headers()
return
elif kind == "fresh":
headers["Cache-Control"] = "max-age=3600"
elif kind == "nostore":
headers["Cache-Control"] = "no-store"
try:
self.send_response(200)
for name, value in headers.items():
self.send_header(name, value)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
except OSError:
pass
server = LocalServer(("127.0.0.1", 0), Handler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
yield server.server_address[1]
server.shutdown()
server.server_close()
thread.join()
async def _pump():
await asyncio.sleep(0.05)
def _run(firefox_binary, scenario):
from invisible_playwright.async_api import InvisiblePlaywright
async def go():
async with InvisiblePlaywright(seed=42, binary_path=firefox_binary, humanize=False, headless=True,
extra_prefs=FISSION_ON) as browser:
page = await browser.new_page()
return await scenario(page)
return asyncio.run(go())
@pytest.mark.parametrize("kind", KINDS)
def test_a_goto_to_the_address_the_page_is_at_ends_every_time(firefox_binary, site, kind):
port = site
url = "http://a.test:%d/%s" % (port, kind)
_, frames = _body(kind, port)
async def scenario(page):
await page.goto(url, timeout=30000)
seen = []
for i in range(GOTOS):
began = time.monotonic()
response = await page.goto(url, timeout=30000)
took = time.monotonic() - began
title = await page.title()
# The frames are counted once they have all been announced, within the goto's own 30 s: with Fission the innermost frame of a-b-a lives
# in a third process, and its announcement may reach the client after the top document's load (measured: 2 of 3 after 0.22 s, run
# 44888497316). A frame that never comes is still red below.
frames_seen = await awatch(lambda: len(page.frames), lambda n: n >= frames, 30, _pump)
seen.append((i, response.status if response else None, page.url, title, frames_seen.history[-1][1], round(took, 2)))
return seen
seen = _run(firefox_binary, scenario)
assert len(seen) == GOTOS
answers = (200, 304) if kind.endswith("etag") else (200,) # a revalidated page is answered 304, and says so
for i, status, address, title, count, took in seen:
assert status in answers, seen[i]
assert address == url, seen[i]
assert title == kind, seen[i]
assert count == frames, seen[i]
# No bound on `took` here: a goto that did not end is the one that raised at its own timeout (30 s), above.
def test_a_goto_to_the_same_address_with_a_query_ends_the_second_time_too(firefox_binary, site):
"""The query is another address once, and the same one after: MDN's `?x=1` twice."""
port = site
url = "http://a.test:%d/other-site-frame?x=1" % port
async def scenario(page):
await page.goto("http://a.test:%d/other-site-frame" % port, timeout=30000)
out = []
for _ in range(3):
response = await page.goto(url, timeout=30000)
out.append((response.status if response else None, page.url, len(page.frames)))
return out
out = _run(firefox_binary, scenario)
assert out == [(200, url, 2)] * 3, out