Verify protected documents disable Print before opening the dialog

This commit is contained in:
Codex committed 2026-12-03 01:19:56 +01:00
1 parent 0de75e1642
commit d231907ce3
1 file changed
+11 -22
+11 -22
View File
@@ -95,13 +95,6 @@ def choose_print(driver, selected=None):
subprocess.run(["xdotool", "mousemove", "1080", "996", "click", "1"], check=True)
def recognize(image):
encoded = io.BytesIO()
image.save(encoded, format="PNG")
return subprocess.check_output(
["tesseract", "stdin", "stdout", "--psm", "11"], input=encoded.getvalue()).decode()
def preview(name, color):
deadline = time.monotonic() + 55
while True:
@@ -165,21 +158,17 @@ def verify_pdf(path):
def denied_print(driver):
choose_print(driver)
deadline = time.monotonic() + 15
while True:
screenshot = ImageGrab.grab()
words = recognize(screenshot).replace("’", "'")
if "don't allow printing" in " ".join(words.lower().split()):
screenshot.save(RESULTS / "print-denied.png")
(RESULTS / "print-denied.txt").write_text(words)
assert not driver.execute_script("return !!document.querySelector('iframe[srcdoc]')")
assert len(pdf_files()) == 1
print("PdfCraft reported that the document's security settings don't allow printing", flush=True)
return
if time.monotonic() > deadline:
raise TimeoutError(words)
time.sleep(0.35)
state = result(driver, "ui.state")
assert any(doc["active"] and doc["name"] == "none.pdf" and doc["pages"] == 3 for doc in state["documents"]), state
before = pdf_files()
assert len(before) == 1
refusal = command(driver, "ui.command", {"id": "print.dialog"})
assert not refusal["ok"] and "print.dialog is disabled" in refusal["error"], refusal
(RESULTS / "print-denied.json").write_text(json.dumps(refusal, indent=2))
assert not driver.execute_script("return !!document.querySelector('iframe[srcdoc]')")
assert pdf_files() == before
ImageGrab.grab().save(RESULTS / "print-denied.png")
print("Print was disabled for the open three-page document that permits no printing", flush=True)
def main():