Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cee36bf79a | ||
|
|
57c2e55188 | ||
|
|
4f204f6d6b |
No files matched your search
@@ -0,0 +1,106 @@
|
||||
# popups-windows-hunt.yml - hunt scaffolding, never merged. Runs only on a push to a `hunt/popups-windows**` branch.
|
||||
#
|
||||
# tests/test_popups_reach_the_client_e2e.py is collected by the required suite wrapper.e2e.page on Windows too. Its process case
|
||||
# now has a browser that starts no content process by itself (no pool, no preloaded New Tab page), and the count between two
|
||||
# reads is the popup's. This job runs the whole file twenty times on Windows, four workers, on the Windows engine a run of the
|
||||
# series repository built, with the core and the wrapper package that run was judged with; the tests are this branch's.
|
||||
name: popups windows hunt
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['hunt/popups-windows**']
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
ENGINE_RUN_ID: '43188313516'
|
||||
ENGINE_REPO: feder-cr/firefox_antidetect_patch
|
||||
CORE_REF: candidate/core-63-r5
|
||||
WRAPPER_REF: udp/wrapper-r5
|
||||
SEAL_TAG: firefox-63-candidate
|
||||
INVISIBLE_CORE_AUTOFIX: 'off'
|
||||
INVISIBLE_CORE_PIN: allow
|
||||
|
||||
jobs:
|
||||
hunt:
|
||||
name: popups x20 (windows-2022, engine of run 43188313516)
|
||||
runs-on: windows-2022
|
||||
timeout-minutes: 90
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
with: { fetch-depth: 1 }
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
||||
with: { python-version: '3.11' }
|
||||
- name: The core of the run, the wrapper package of the run, this branch's tests
|
||||
run: |
|
||||
CORE_GIT="git+https://github.com/feder-cr/invisible_core@$CORE_REF"
|
||||
python -m pip install --quiet --upgrade pip
|
||||
python -m pip install --quiet "$CORE_GIT"
|
||||
python -m pip install --quiet ".[dev]"
|
||||
python -m pip install --quiet --force-reinstall --no-deps "git+https://github.com/feder-cr/invisible_playwright@$WRAPPER_REF"
|
||||
python -m pip install --quiet --force-reinstall "$CORE_GIT"
|
||||
python -m pip install --quiet "playwright==$(cat scripts/playwright_pin.txt)"
|
||||
python -c "import importlib.metadata as m; print('installed: invisible-playwright', m.version('invisible-playwright'), '| invisible-core', m.version('invisible-core'))"
|
||||
- name: The Windows engine of the run
|
||||
run: |
|
||||
set -e
|
||||
mkdir -p art ff
|
||||
gh run download "$ENGINE_RUN_ID" --repo "$ENGINE_REPO" --name asset-win-x86_64 --dir art
|
||||
set -- art/firefox-*-stealth-win-x86_64.*
|
||||
[ "$#" -eq 1 ] && [ -e "$1" ] || { echo "expected one firefox-*-stealth-win-x86_64 archive in art/, found: $*"; exit 1; }
|
||||
python -c "import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall('ff')" "$1"
|
||||
[ -e ff/firefox.exe ] || { echo "no ff/firefox.exe"; exit 1; }
|
||||
python -m invisible_core seal --binary "$PWD/ff/firefox.exe" --tag "$SEAL_TAG" -o "$PWD/seal.json"
|
||||
echo "FF_EXE=$PWD/ff/firefox.exe" >> "$GITHUB_ENV"
|
||||
echo "INVISIBLE_SEAL_FILE=$PWD/seal.json" >> "$GITHUB_ENV"
|
||||
- name: The popup file, twenty times, four workers
|
||||
env:
|
||||
PYTHONUNBUFFERED: "1"
|
||||
run: |
|
||||
export INVPW_BINARY_PATH="$FF_EXE" STEALTHFOX_E2E_BINARY="$FF_EXE"
|
||||
mkdir -p evidence
|
||||
pass=0; fail=0
|
||||
for n in $(seq 1 20); do
|
||||
log="evidence/run_$(printf '%02d' "$n").log"
|
||||
set +e
|
||||
python -m pytest tests/test_popups_reach_the_client_e2e.py -m e2e -o addopts= -p no:cacheprovider \
|
||||
-n 4 --dist loadfile --timeout 420 -q -rA > "$log" 2>&1
|
||||
code=$?
|
||||
set -e
|
||||
collected=$(grep -cE "^(PASSED|FAILED|ERROR|SKIPPED) " "$log" || true)
|
||||
skipped=$(grep -cE "^SKIPPED " "$log" || true)
|
||||
if [ "$code" = "0" ] && [ "$skipped" = "0" ]; then pass=$((pass+1)); else fail=$((fail+1)); fi
|
||||
echo "run $n: exit=$code results=$collected skipped=$skipped $(tail -1 "$log")"
|
||||
done
|
||||
{
|
||||
echo "## popups x20 on windows-2022 (engine of run $ENGINE_RUN_ID, core $CORE_REF, wrapper package $WRAPPER_REF, tests $GITHUB_SHA)"
|
||||
echo
|
||||
echo "| runs green with no skip | runs red |"
|
||||
echo "|---|---|"
|
||||
echo "| $pass | $fail |"
|
||||
echo
|
||||
echo '```'
|
||||
grep -hE "^(FAILED|ERROR|SKIPPED) " evidence/run_*.log | sort | uniq -c | sort -rn | head -40
|
||||
grep -hE "test_the_other_site_popup_runs_in_another_process" evidence/run_*.log | grep -E "^(PASSED|FAILED|ERROR|SKIPPED) " | sort | uniq -c
|
||||
echo '```'
|
||||
} | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
- name: Close every Firefox left
|
||||
if: always()
|
||||
shell: pwsh
|
||||
run: |
|
||||
Get-Process firefox -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
"left: " + @(Get-Process firefox -ErrorAction SilentlyContinue).Count
|
||||
- name: Upload all the evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
||||
with:
|
||||
name: popups-windows-hunt-${{ github.run_id }}
|
||||
path: evidence
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- The end-to-end tests that look at content processes ask for the processes of a site by its name and no longer
|
||||
compare two counts. The browser starts processes of its own (the pool refill, and a process for a Mozilla site that the
|
||||
New Tab page starts about a second after its own), and under load one of them arrived between the two reads and
|
||||
looked like the effect of the frame under test: 14 of 30 runs of the whole suite were red on the same-site control.
|
||||
The tests turn on `fission.processSiteNames` (test-only, never the product's) so that a process is named by its
|
||||
site. Linux only; elsewhere these tests skip.
|
||||
|
||||
## [0.50.1] - 2026-11-12
|
||||
|
||||
0.50.0 was tagged and never published: its end-to-end gate was red on two tests that counted processes.
|
||||
|
||||
+54
-21
@@ -1,16 +1,26 @@
|
||||
"""Which of the engine's processes host a site: what the e2e tests that count processes read.
|
||||
"""Which of the engine's processes host a site, told by the name of the site: what the e2e tests that look at processes read.
|
||||
|
||||
A content process is not a site's by being new. The engine keeps preallocated content processes
|
||||
(`dom.ipc.processPrelaunch.fission.number`, 3), hands one to a site when a site needs a process, and starts
|
||||
another to refill the pool whenever it gets to it, so a pid that appears between two reads is often that refill.
|
||||
On Linux the process says which it is: `ContentChild::SetProcessName` names it by its remote type with
|
||||
`prctl(PR_SET_NAME)` (ipc/glue/ProcessUtils_linux.cpp), "Isolated Web Co" once it hosts a site of strategy 1
|
||||
(`webIsolated=<site>`), "Web Content" while it is preallocated. Windows names no process
|
||||
(ProcessUtils_none.cpp): a test that counts sites skips there and says so.
|
||||
Counting processes between two reads does not tell a site's process from the browser's own. The browser starts
|
||||
content processes for itself: it refills the pool of preallocated ones (`dom.ipc.processPrelaunch.fission.number`)
|
||||
whenever it gets to it, and the New Tab page starts a process for a Mozilla site of its own (remote type
|
||||
`webIsolated=https://mozgcp.net`, born about a second after the process of the New Tab page, with any page, even
|
||||
about:blank). Under load that process arrives after the first read of a test, and "the set of processes changed"
|
||||
read it as the effect of the frame under test: the same-site control was red in 14 of 30 runs of the whole e2e suite
|
||||
(`[P] -> [P, P2]`), and "at least one new process" for a cross-site frame was satisfied by that process alone.
|
||||
|
||||
Measured on firefox-62 (Linux): a cross-site frame renames one preallocated process and a new "Web Content"
|
||||
refills the pool; a same-site frame changes neither; a closed context leaves no "Isolated Web Co", while the
|
||||
pool of "Web Content" fills up behind it in about half the runs.
|
||||
So a test asks for the processes of ONE site, by name. With the pref `fission.processSiteNames` on (`NAMED_BY_SITE`,
|
||||
test-only: the product never sets it) a content process that hosts a site is named by that site
|
||||
(`ContentChild::SetProcessName`, dom/ipc/ContentChild.cpp: a leading `https://` is dropped), and on Linux
|
||||
`prctl(PR_SET_NAME)` keeps 15 characters (ipc/glue/ProcessUtils_linux.cpp). Measured on firefox-62 (Linux):
|
||||
|
||||
- the process of `http://a.test` in a Playwright context is named `http://a.test^u`: the site, then the start of
|
||||
`^userContextId=N`, cut at 15 characters;
|
||||
- the process the New Tab page starts is named `mozgcp.net`;
|
||||
- a process with no site keeps its type: `Web Content`, `Privileged Cont`, `WebExtensions`.
|
||||
|
||||
The process gets its name before any document loads in it, so when a page of the site has run, its process already
|
||||
answers to the site. Windows names no process (ProcessUtils_none.cpp): a test that looks at sites skips there and
|
||||
says so.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -19,14 +29,37 @@ import sys
|
||||
|
||||
import pytest
|
||||
|
||||
#: The name a content process of strategy 1 takes once it hosts a site (PR_SET_NAME keeps 15 characters of
|
||||
#: "Isolated Web Content"). A preallocated one is "Web Content" until a site is given to it.
|
||||
SITE_PROCESS_NAME = "Isolated Web Co"
|
||||
#: The pref overlay that names a content process by the site it hosts. Test-only.
|
||||
NAMED_BY_SITE = {"fission.processSiteNames": True}
|
||||
|
||||
#: What PR_SET_NAME keeps of a process name on Linux.
|
||||
NAME_LENGTH = 15
|
||||
|
||||
|
||||
def site_pids(processes, engine_dir=None):
|
||||
"""The pids, among `processes` (psutil-like), of the content processes that host a site; with `engine_dir`,
|
||||
only those of the engine in that directory."""
|
||||
def name_of_site(site):
|
||||
"""What the process name of `site` starts with: the site without a leading `https://`, cut at 15 characters."""
|
||||
if site.startswith("https://"):
|
||||
site = site[len("https://"):]
|
||||
return site[:NAME_LENGTH]
|
||||
|
||||
|
||||
def hosts_site(name, site):
|
||||
"""True when a process called `name` is a process of `site`.
|
||||
|
||||
The name is the prefix itself, or the prefix followed by `^` (the start of `^userContextId=N`). When the prefix is
|
||||
shorter than 15 characters the next character has to be `^`, so `http://a.test` does not match a process of
|
||||
`http://a.testing.example`."""
|
||||
prefix = name_of_site(site)
|
||||
if name == prefix:
|
||||
return True
|
||||
if not name.startswith(prefix):
|
||||
return False
|
||||
return len(prefix) >= NAME_LENGTH or name[len(prefix)] == "^"
|
||||
|
||||
|
||||
def site_pids(processes, site, engine_dir=None):
|
||||
"""The pids, among `processes` (psutil-like), of the content processes (`-contentproc ... tab`) that host `site`;
|
||||
with `engine_dir`, only those of the engine in that directory."""
|
||||
import psutil
|
||||
|
||||
pids = set()
|
||||
@@ -37,13 +70,13 @@ def site_pids(processes, engine_dir=None):
|
||||
name, cmd = proc.name(), proc.cmdline()
|
||||
except psutil.Error:
|
||||
continue
|
||||
if "-contentproc" in cmd and cmd and cmd[-1] == "tab" and name == SITE_PROCESS_NAME:
|
||||
if "-contentproc" in cmd and cmd and cmd[-1] == "tab" and hosts_site(name, site):
|
||||
pids.add(proc.pid)
|
||||
return pids
|
||||
|
||||
|
||||
def site_processes_below(root_pid, engine_dir=None):
|
||||
"""The pids of the processes below `root_pid` that host a site. Off Linux the test skips: no name says it."""
|
||||
def site_processes_below(root_pid, site, engine_dir=None):
|
||||
"""The pids of the processes below `root_pid` that host `site`. Off Linux the test skips: no name says it."""
|
||||
import psutil
|
||||
|
||||
if not sys.platform.startswith("linux"):
|
||||
@@ -52,4 +85,4 @@ def site_processes_below(root_pid, engine_dir=None):
|
||||
children = psutil.Process(root_pid).children(recursive=True)
|
||||
except psutil.Error:
|
||||
return set()
|
||||
return site_pids(children, engine_dir)
|
||||
return site_pids(children, site, engine_dir)
|
||||
@@ -10,10 +10,13 @@ ones that stay.
|
||||
The test closes five such contexts in a row. While each page is open it counts the processes that host a site
|
||||
(at least one: the page's, or the count would prove nothing), and once `close` has answered it waits a few
|
||||
seconds for them to be gone: none may be left (on the old engine every context leaves its own, one more each
|
||||
time). Only the processes that host a site are counted (tests/_processes.py): the engine refills its pool of
|
||||
preallocated content processes behind a closed context, in about half the runs, and counting every content
|
||||
process read that refill as a leak ([2, 2, 2, 5, 5] on the e2e of the 0.50.0 commit, three "Web Content" and no
|
||||
site left). Off Linux the test skips: no other system names the process.
|
||||
time). Only the processes of the page's site are counted, asked for by name (tests/_processes.py): the browser is
|
||||
launched with `fission.processSiteNames`, which names a content process by the site it hosts (the page is served
|
||||
from `http://127.0.0.1:<port>`; a site never includes the port). The browser starts processes of its own, and
|
||||
counting every content process, or every one that hosts any site, read them as a leak ([2, 2, 2, 5, 5] on the e2e
|
||||
of the 0.50.0 commit, three "Web Content" and no site left; a process for a Mozilla site started by the New Tab
|
||||
page). If the name were not what the test expects, the count while the page is open would be 0 and the first assert
|
||||
says so. Off Linux the test skips: no other system names the process.
|
||||
|
||||
The engine that does it is not published when this file is written: `engine_at_least` makes the test wait for
|
||||
it, and on an older engine it is skipped, never passed.
|
||||
@@ -30,12 +33,13 @@ import pytest
|
||||
pytest.importorskip("websockets")
|
||||
from websockets.asyncio.client import connect # noqa: E402
|
||||
|
||||
from _processes import site_processes_below # noqa: E402
|
||||
from _processes import NAMED_BY_SITE, site_processes_below # noqa: E402
|
||||
from _servers import LocalServer # noqa: E402
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
ENGINE_WITH_THE_FIX = "firefox-61"
|
||||
SITE = "http://127.0.0.1" # the site of the served page; a site never includes the port
|
||||
|
||||
PAGE = (b"<!doctype html><title>sw</title><script>"
|
||||
b"navigator.serviceWorker.register('/sw.js').catch(e => { document.title = 'ERR ' + e; });</script>")
|
||||
@@ -98,10 +102,11 @@ def test_closed_contexts_with_a_never_stopping_service_worker_leave_no_process(f
|
||||
|
||||
server, base = _serve()
|
||||
launched = launch_server(host="127.0.0.1", port=0, headless=True, virtual_display=False, humanize=False,
|
||||
seed=4266, binary_path=firefox_binary, launch_timeout_ms=180_000)
|
||||
seed=4266, binary_path=firefox_binary, launch_timeout_ms=180_000,
|
||||
extra_prefs=NAMED_BY_SITE)
|
||||
|
||||
def sites():
|
||||
return site_processes_below(launched.process.pid)
|
||||
return site_processes_below(launched.process.pid, SITE)
|
||||
|
||||
async def drive():
|
||||
opened, left = [], []
|
||||
|
||||
@@ -21,10 +21,14 @@ test says what the product does not do yet and the step that makes it green:
|
||||
9 named world after the OOP frame step 1a + 2b
|
||||
10 console of the OOP frame step 1a
|
||||
|
||||
The oracle for "another process" is the set of the engine's processes that host a site, below the test
|
||||
(tests/_processes.py says how a site's process is told from a preallocated one): a cross-site frame adds at
|
||||
least one, a same-site one changes nothing. The set is read once it is quiet. Off Linux the two tests that
|
||||
count processes skip: no other system names the process.
|
||||
The oracle for "another process" is the name of the site (tests/_processes.py): with `fission.processSiteNames`
|
||||
on, the engine's process that hosts `http://a.test` is named after it, and the two tests that look at processes
|
||||
ask for the processes of one site and never compare two counts. Counting was wrong because the browser starts
|
||||
processes of its own: in every run, a second isolated process (remote type `webIsolated=https://mozgcp.net`) is
|
||||
born about a second after the process of the New Tab page, with any page, and under load it arrived between the
|
||||
two reads (red in 14 of 30 runs of the whole e2e suite, `[P] -> [P, P2]`). A cross-site frame gives a process
|
||||
for the frame's site; a same-site one leaves the page's site in its single process. Off Linux the two tests
|
||||
skip: no other system names the process.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -38,14 +42,18 @@ from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
import pytest
|
||||
|
||||
from _processes import site_processes_below
|
||||
from _processes import NAMED_BY_SITE, site_processes_below
|
||||
from _servers import LocalServer
|
||||
|
||||
SITE_A = "http://a.test"
|
||||
SITE_B = "http://b.test"
|
||||
|
||||
FISSION_ON = {
|
||||
"fission.autostart": True,
|
||||
"fission.webContentIsolationStrategy": 1, # IsolateEverything: site-origin
|
||||
"dom.ipc.processCount.webIsolated": 4, # the desktop default
|
||||
"network.dns.localDomains": "a.test,b.test,c.test",
|
||||
**NAMED_BY_SITE, # test-only: a process is named by its site (tests/_processes.py)
|
||||
}
|
||||
|
||||
|
||||
@@ -127,23 +135,9 @@ def engine_dir(firefox_binary):
|
||||
return str(Path(firefox_binary).resolve().parent)
|
||||
|
||||
|
||||
def site_processes(engine_dir):
|
||||
"""The pids of the engine's processes below this test that host a site (tests/_processes.py)."""
|
||||
return site_processes_below(os.getpid(), engine_dir)
|
||||
|
||||
|
||||
def quiet(engine_dir, seconds=3.0, limit=30.0):
|
||||
"""The set of the processes that host a site, once it has not changed for `seconds`."""
|
||||
end = time.time() + limit
|
||||
last, since = site_processes(engine_dir), time.time()
|
||||
while time.time() < end:
|
||||
time.sleep(0.25)
|
||||
now = site_processes(engine_dir)
|
||||
if now != last:
|
||||
last, since = now, time.time()
|
||||
elif time.time() - since >= seconds:
|
||||
break
|
||||
return last
|
||||
def processes_of(site, engine_dir):
|
||||
"""The pids of the engine's processes below this test that host `site` (named by it, tests/_processes.py)."""
|
||||
return site_processes_below(os.getpid(), site, engine_dir)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -163,21 +157,6 @@ def page(browser):
|
||||
return page
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_without_a_pool(firefox_binary):
|
||||
"""A page of a browser that keeps NO preallocated content processes (`dom.ipc.processPrelaunch.fission.number` 0): a process of a
|
||||
site then appears only because a site needed one. The default pool hands a preallocated process to a site whenever it gets to it, so
|
||||
a test that counts the processes of the sites between two reads sees the hand-out of the pool as if the frame had asked for it."""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with InvisiblePlaywright(seed=42, binary_path=firefox_binary, humanize=False, headless=True,
|
||||
extra_prefs=dict(FISSION_ON, **{"dom.ipc.processPrelaunch.fission.number": 0})) as browser:
|
||||
page = browser.new_context().new_page()
|
||||
page.set_default_timeout(3000)
|
||||
page.set_default_navigation_timeout(20000)
|
||||
yield page
|
||||
|
||||
|
||||
def wait_for(page, predicate, seconds=8.0):
|
||||
"""Until `predicate()`, with the client's events being read: the sync client takes the engine's events
|
||||
only inside its own calls, so a plain sleep would never see a frame arrive."""
|
||||
@@ -216,41 +195,52 @@ def frame_with_origin(page, origin):
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_cross_site_iframe_gets_its_own_process(page, cross_site_loop, engine_dir):
|
||||
"""Green today: it says the bench separates sites. Two sites in the frame tree add at least one process."""
|
||||
"""Green today: it says the bench separates sites. A frame of b.test in a page of a.test has a process of its own.
|
||||
|
||||
The processes are asked for by the name of their site, never counted between two reads (tests/_processes.py): the
|
||||
page of a.test has exactly one, nobody has b.test; once the top has loaded, b.test has one, and a.test still has
|
||||
one (the a.test leaf inside the b.test frame is in the top's process). The pid of a.test is not compared across
|
||||
the navigation: a top-level navigation may land in another process of the same site (`mReplaceBrowsingContext`,
|
||||
dom/ipc/ProcessIsolation.cpp, see the control below)."""
|
||||
page.goto(cross_site_loop["plain"])
|
||||
before = quiet(engine_dir)
|
||||
here = processes_of(SITE_A, engine_dir)
|
||||
assert len(here) == 1, "the page of a.test must have one process of its site: %s" % sorted(here)
|
||||
assert not processes_of(SITE_B, engine_dir), "a process for b.test before any page of it"
|
||||
page.goto(cross_site_loop["top"], wait_until="load")
|
||||
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["host"] == "a.test" and
|
||||
r["query"]["path"] == ["/leaf"] for r in cross_site_loop["reports"]))
|
||||
after = quiet(engine_dir)
|
||||
assert len(after - before) >= 1, "no new process for a site: before %s, after %s" % (sorted(before), sorted(after))
|
||||
framed = processes_of(SITE_B, engine_dir)
|
||||
assert len(framed) >= 1, "no process for the site of the frame (b.test)"
|
||||
tops = processes_of(SITE_A, engine_dir)
|
||||
assert len(tops) == 1, "the processes of a.test must still be one: %s" % sorted(tops)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_same_site_other_port_stays_in_process(page_without_a_pool, cross_site_loop, engine_dir):
|
||||
"""Green today, the control: a frame of the page's own site adds no process for a site.
|
||||
def test_same_site_other_port_stays_in_process(page, cross_site_loop, engine_dir):
|
||||
"""Green today, the control: a frame of the page's own site gets no process, and none for another site.
|
||||
|
||||
The browser here keeps NO preallocated processes (`page_without_a_pool`): with the default pool of three the count of the processes of
|
||||
the sites moved between two reads without the frame having asked for anything - a preallocated process handed to a site later than
|
||||
the first read ([63248] -> [63248, 63386] on a four-worker runner, the third time in a row that this control was red there for the
|
||||
pool and not for the frame: 5402da4, ff2123e, fef0bc5). The frame is in the page's own origin (`a.test/leaf` in `a.test/plain`).
|
||||
The processes of a.test are asked for by name before and after the frame is added: one pid, the same pid. Nothing
|
||||
else is looked at: the browser starts processes of its own (the pool refill, a process for a Mozilla site started
|
||||
by the New Tab page, `webIsolated=https://mozgcp.net`, there in every run and under load born after the first
|
||||
read), and counting every process between two reads took them for the frame's (red in 14 of 30 runs). The frame
|
||||
has run in its process when it reports, and that process got its name before any document loaded in it, so no
|
||||
waiting for quiet is needed. The frame is in the page's own origin (`a.test/leaf` in `a.test/plain`).
|
||||
|
||||
The frame is put in the page that is already shown, not reached by a navigation of the top. A top-level
|
||||
navigation whose old document may enter the back-forward cache replaces the browsing context
|
||||
(`mReplaceBrowsingContext`, dom/ipc/ProcessIsolation.cpp), and the new one may land in another process of
|
||||
the same site (`dom.ipc.processCount.webIsolated` is 4): seen once on the e2e of #451, [10878] -> [10878,
|
||||
11208] after a.test/plain -> a.test/same-site, never in 87 local runs. That is the top's process, not the
|
||||
frame's; a frame of the page's site stays in the page's process."""
|
||||
page = page_without_a_pool
|
||||
the same site (`dom.ipc.processCount.webIsolated` is 4). That is the top's process, not the frame's; a frame of
|
||||
the page's site stays in the page's process."""
|
||||
page.goto(cross_site_loop["plain"])
|
||||
before = quiet(engine_dir)
|
||||
assert len(before) >= 1, "the page of a site has no process of its own to compare with: %s" % sorted(before)
|
||||
before = processes_of(SITE_A, engine_dir)
|
||||
assert len(before) == 1, "the page of a.test must have one process of its site: %s" % sorted(before)
|
||||
page.evaluate("(u) => { const f = document.createElement('iframe'); f.id = 's'; f.src = u;"
|
||||
" document.body.appendChild(f); }", cross_site_loop["leaf"])
|
||||
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["query"]["path"] == ["/leaf"]
|
||||
for r in cross_site_loop["reports"]))
|
||||
after = quiet(engine_dir)
|
||||
assert after == before, "a same-site frame changed the processes of the sites: %s -> %s" % (sorted(before), sorted(after))
|
||||
after = processes_of(SITE_A, engine_dir)
|
||||
assert after == before, "a same-site frame changed the processes of a.test: %s -> %s" % (sorted(before), sorted(after))
|
||||
assert not processes_of(SITE_B, engine_dir), "a process for b.test, which no page here belongs to"
|
||||
|
||||
|
||||
# ── 3 .. 10: what the product does not do yet ──────────────────────────────────
|
||||
|
||||
@@ -15,12 +15,19 @@ opener (`page.opener()`). Stock Firefox (Playwright 1.62) gives an opener in all
|
||||
asserted for all four; if the engine ever returns None for a noopener kind the test says so.
|
||||
|
||||
One extra case proves that the other-site target is really in another process, so that the matrix cannot quietly become a
|
||||
same-site test: opening it adds a content process below the test; the same-site target does not.
|
||||
same-site test: opening it adds a content process below the test; the same-site target does not. That case has a browser
|
||||
of its own that starts no content process by itself (`QUIET_PREFS`, test-only): a browser as shipped preallocates content
|
||||
processes and refills its pool whenever it gets to it, and its preloaded New Tab page starts a process of its own and, in
|
||||
some countries, one more for a Mozilla site, about a second later and with any page. Counted between two reads, any of
|
||||
those was taken for the popup's doing. Where the system names a process by its site (Linux, `NAMED_BY_SITE`), the case
|
||||
also asks by name: the other-site popup's process is the process of `http://localhost`. It runs on Windows too: there is
|
||||
no skip, so the count stays the same on every system.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
@@ -28,9 +35,15 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from _processes import NAMED_BY_SITE, site_pids
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
OWN, OTHER = "127.0.0.1", "localhost"
|
||||
|
||||
#: The browser of the process case starts no content process by itself: no pool of preallocated processes, and no
|
||||
#: preloaded New Tab page (which starts a process of its own and, in some countries, one for a Mozilla site). Test-only.
|
||||
QUIET_PREFS = dict(NAMED_BY_SITE, **{"dom.ipc.processPrelaunch.fission.number": 0, "browser.newtab.preload": False})
|
||||
KINDS = {
|
||||
"a-blank": "a1",
|
||||
"a-noopener": "a2",
|
||||
@@ -102,6 +115,35 @@ def browser(request, firefox_binary):
|
||||
server.close()
|
||||
|
||||
|
||||
@pytest.fixture(params=["in-process", "stock-client"])
|
||||
def quiet_browser(request, firefox_binary):
|
||||
"""A browser of its own for the process case, on each transport, that starts no content process by itself."""
|
||||
if request.param == "in-process":
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with InvisiblePlaywright(binary_path=firefox_binary, headless=True, extra_prefs=QUIET_PREFS) as b:
|
||||
yield b
|
||||
return
|
||||
try:
|
||||
sync_playwright = importlib.import_module("playwright.sync_api").sync_playwright
|
||||
except ImportError as exc:
|
||||
pytest.fail("the stock Playwright client is missing (%s): install the wrapper with its dev extra" % exc,
|
||||
pytrace=False)
|
||||
from invisible_playwright._juggler.remote import launch_server
|
||||
|
||||
server = launch_server(headless=True, binary_path=firefox_binary, locale="en-US", timezone="Europe/Rome",
|
||||
extra_prefs=QUIET_PREFS)
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
b = p.firefox.connect(server.ws_endpoint)
|
||||
try:
|
||||
yield b
|
||||
finally:
|
||||
b.close()
|
||||
finally:
|
||||
server.close()
|
||||
|
||||
|
||||
def _route(context):
|
||||
context.route("**/*", lambda route: route.abort() if route.request.resource_type in ("image", "media")
|
||||
else route.continue_())
|
||||
@@ -163,10 +205,12 @@ def _quiet(engine_dir, seconds=3.0, limit=30.0):
|
||||
return last
|
||||
|
||||
|
||||
def test_the_other_site_popup_runs_in_another_process(browser, firefox_binary, site):
|
||||
def test_the_other_site_popup_runs_in_another_process(quiet_browser, firefox_binary, site):
|
||||
"""The control of the matrix above: the popup to `localhost` adds a content process, the one to `127.0.0.1` does not."""
|
||||
import psutil
|
||||
|
||||
engine_dir = str(Path(firefox_binary).resolve().parent)
|
||||
context = browser.new_context()
|
||||
context = quiet_browser.new_context()
|
||||
page = context.new_page()
|
||||
page.goto("http://%s:%d/main" % (OWN, site))
|
||||
before = _quiet(engine_dir)
|
||||
@@ -184,3 +228,7 @@ def test_the_other_site_popup_runs_in_another_process(browser, firefox_binary, s
|
||||
assert not (same - before), "a popup to the opener's own site started a process: %s" % sorted(same - before)
|
||||
assert len(other - base) >= 1, "the other-site popup added no content process: %s -> %s" % (
|
||||
sorted(base), sorted(other))
|
||||
if sys.platform.startswith("linux"): # only Linux names a process by its site; elsewhere the count above is the proof
|
||||
children = psutil.Process(os.getpid()).children(recursive=True)
|
||||
assert site_pids(children, "http://" + OTHER, engine_dir) & (other - base), (
|
||||
"none of the new processes is the process of %s: %s" % (OTHER, sorted(other - base)))
|
||||
@@ -1,10 +1,10 @@
|
||||
"""The e2e tests that count processes count the ones that host a site, not every new content process. No browser.
|
||||
"""The e2e tests that look at processes ask for the processes of a site by its name. No browser.
|
||||
|
||||
The engine keeps preallocated content processes and starts one to refill the pool after it hands one to a site,
|
||||
whenever it gets to it. The bench counted every `-contentproc ... tab` pid, so a refill that landed between its
|
||||
two reads was "a process the same-site frame started" (test_same_site_other_port_stays_in_process, red on the
|
||||
e2e of the commit of 0.50.0: `[13443]`). The processes below are the ones measured on firefox-62 (Linux):
|
||||
names and command lines as /proc gives them.
|
||||
With `fission.processSiteNames` on, a content process that hosts a site is named by that site, and on Linux the name
|
||||
is cut at 15 characters. The browser starts processes of its own (the pool refill, a process for a Mozilla site
|
||||
started by the New Tab page), so a test that compared two counts of processes read them as the effect of the frame
|
||||
under test (test_same_site_other_port_stays_in_process, red in 14 of 30 runs of the e2e suite). The names below are
|
||||
the ones measured on firefox-62 (Linux), with command lines as /proc gives them.
|
||||
"""
|
||||
import _processes
|
||||
import pytest
|
||||
@@ -13,10 +13,11 @@ pytestmark = pytest.mark.unit
|
||||
|
||||
ENGINE = "/cache/firefox-62/firefox"
|
||||
DIR = "/cache/firefox-62"
|
||||
A, B = "http://a.test", "http://b.test"
|
||||
|
||||
|
||||
class _Proc:
|
||||
def __init__(self, pid, name, kind, exe=ENGINE):
|
||||
def __init__(self, pid, name, kind="tab", exe=ENGINE):
|
||||
self.pid, self._name, self._exe = pid, name, exe
|
||||
self._cmd = [exe, "-contentproc", "-isForBrowser", "-prefsLen", "1", "-parentBuildID", "20261111073531",
|
||||
"-appDir", DIR + "/browser", str(pid), kind]
|
||||
@@ -31,35 +32,57 @@ class _Proc:
|
||||
return self._cmd
|
||||
|
||||
|
||||
def _engine_at_plain():
|
||||
"""a.test/plain shown: one process for the site, three preallocated, and the engine's other children."""
|
||||
return [_Proc(184, "Socket Process", "socket"), _Proc(200, "WebExtensions", "tab"),
|
||||
_Proc(334, "Isolated Web Co", "tab"), _Proc(377, "Privileged Cont", "tab"),
|
||||
_Proc(433, "Web Content", "tab"), _Proc(438, "Web Content", "tab"), _Proc(460, "Web Content", "tab")]
|
||||
def _engine_at_a():
|
||||
"""a.test shown: its process, the one the New Tab page started, and the engine's other children."""
|
||||
return [_Proc(184, "Socket Process", "socket"), _Proc(200, "WebExtensions"), _Proc(334, "http://a.test^u"),
|
||||
_Proc(377, "Privileged Cont"), _Proc(410, "mozgcp.net"), _Proc(433, "Web Content"),
|
||||
_Proc(438, "Web Content")]
|
||||
|
||||
|
||||
def test_a_preallocated_process_that_arrives_is_not_a_site():
|
||||
before = _processes.site_pids(_engine_at_plain(), DIR)
|
||||
after = _processes.site_pids(_engine_at_plain() + [_Proc(549, "Web Content", "tab")], DIR)
|
||||
def test_a_process_named_by_the_site_is_the_sites():
|
||||
assert _processes.site_pids(_engine_at_a(), A, DIR) == {334}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["mozgcp.net", "Web Content", "Privileged Cont", "WebExtensions", "Isolated Web Co"])
|
||||
def test_a_process_with_another_name_is_not_the_sites(name):
|
||||
assert _processes.site_pids([_Proc(1, name)], A) == set()
|
||||
|
||||
|
||||
def test_the_process_of_another_site_is_not_the_sites():
|
||||
assert _processes.site_pids([_Proc(1, "http://b.test^u")], A) == set()
|
||||
assert _processes.site_pids([_Proc(1, "http://b.test^u")], B) == {1}
|
||||
|
||||
|
||||
def test_the_process_the_browser_starts_for_itself_does_not_move_the_sites():
|
||||
"""The measured flaw: a second isolated process (mozgcp.net) arriving between two reads changed the old count."""
|
||||
before = _processes.site_pids(_engine_at_a(), A, DIR)
|
||||
after = _processes.site_pids(_engine_at_a() + [_Proc(549, "mozgcp.net"), _Proc(550, "Web Content")], A, DIR)
|
||||
assert before == after == {334}
|
||||
|
||||
|
||||
def test_a_preallocated_process_given_to_a_site_is_a_new_site_process():
|
||||
"""A cross-site frame: 433 leaves the pool for b.test (and is renamed), 549 refills the pool."""
|
||||
procs = [p for p in _engine_at_plain() if p.pid != 433]
|
||||
procs += [_Proc(433, "Isolated Web Co", "tab"), _Proc(549, "Web Content", "tab")]
|
||||
assert _processes.site_pids(procs, DIR) - _processes.site_pids(_engine_at_plain(), DIR) == {433}
|
||||
def test_https_is_dropped_from_the_site():
|
||||
assert _processes.name_of_site("https://example.com") == "example.com"
|
||||
assert _processes.hosts_site("example.com", "https://example.com")
|
||||
assert _processes.hosts_site("example.com^use", "https://example.com")
|
||||
|
||||
|
||||
def test_a_site_longer_than_the_name_matches_on_its_first_15_characters():
|
||||
site = "http://a-very-long-site.example"
|
||||
assert _processes.name_of_site(site) == "http://a-very-l"
|
||||
assert _processes.hosts_site("http://a-very-l", site)
|
||||
assert not _processes.hosts_site("http://a-very-x", site)
|
||||
|
||||
|
||||
def test_a_site_that_starts_like_another_is_not_the_other():
|
||||
assert not _processes.hosts_site("http://a.testin", A)
|
||||
assert not _processes.hosts_site("http://a.testing.example", A)
|
||||
assert _processes.hosts_site("http://a.test^u", A)
|
||||
|
||||
|
||||
def test_a_process_of_another_firefox_is_not_counted():
|
||||
other = _Proc(900, "Isolated Web Co", "tab", exe="/usr/lib/firefox/firefox")
|
||||
assert _processes.site_pids(_engine_at_plain() + [other], DIR) == {334}
|
||||
other = _Proc(900, "http://a.test^u", exe="/usr/lib/firefox/firefox")
|
||||
assert _processes.site_pids(_engine_at_a() + [other], A, DIR) == {334}
|
||||
|
||||
|
||||
def test_the_pool_refilled_behind_a_closed_context_is_not_a_process_left():
|
||||
"""After the fourth closed context of test_a_context_that_ends_leaves_no_process_e2e, as measured: three
|
||||
preallocated processes and no site. Counting every content process said 5 ([2, 2, 2, 5, 5])."""
|
||||
left = [_Proc(1219, "WebExtensions", "tab"), _Proc(1382, "Privileged Cont", "tab"),
|
||||
_Proc(1739, "Web Content", "tab"), _Proc(1744, "Web Content", "tab"), _Proc(1821, "Web Content", "tab")]
|
||||
assert _processes.site_pids(left) == set()
|
||||
assert _processes.site_pids(left + [_Proc(1900, "Isolated Web Co", "tab")]) == {1900}
|
||||
def test_a_process_that_is_not_a_tab_is_not_counted():
|
||||
assert _processes.site_pids([_Proc(1, "http://a.test^u", kind="gpu")], A) == set()
|
||||
Reference in new issue
Block a user