diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 14:40:03 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 14:40:03 -0500 |
| commit | 2cc430ffa0cd3597589c6fdedfced0a76b7da255 (patch) | |
| tree | b3105065d9ee93d3ce9437fc57e12e4c3e8354b2 /tests/test-eww-config-user-agent-advice.el | |
| parent | 5affa7a867c5b0999216b32a7d1f441b52889a0d (diff) | |
| download | dotemacs-2cc430ffa0cd3597589c6fdedfced0a76b7da255.tar.gz dotemacs-2cc430ffa0cd3597589c6fdedfced0a76b7da255.zip | |
fix(elfeed): bound and clean up the synchronous YouTube fetch
cj/youtube-to-elfeed-feed-format called url-retrieve-synchronously with no timeout, so a hung YouTube request would block Emacs indefinitely, and it only killed the temporary URL buffer when an ID was successfully extracted — a page without the expected markers leaked the buffer.
Passed cj/elfeed-url-fetch-timeout (10s) to the synchronous fetch, and moved the fetch+parse into an unwind-protect that always kills the temp buffer (live-p guarded), including the parse-failure path. Tests mock the network boundary and cover a normal channel parse, that a timeout is passed, and that the buffer is not leaked when parsing fails.
Also added tests for the EWW user-agent advice (no code change): it already injects the desktop UA only from eww-mode buffers, so package.el and other non-EWW url callers pass through untouched — the tests pin that scoping and the replace-not-duplicate header behavior.
Diffstat (limited to 'tests/test-eww-config-user-agent-advice.el')
| -rw-r--r-- | tests/test-eww-config-user-agent-advice.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-eww-config-user-agent-advice.el b/tests/test-eww-config-user-agent-advice.el new file mode 100644 index 000000000..c045a5034 --- /dev/null +++ b/tests/test-eww-config-user-agent-advice.el @@ -0,0 +1,56 @@ +;;; test-eww-config-user-agent-advice.el --- Tests for EWW user-agent advice -*- lexical-binding: t; -*- + +;;; Commentary: +;; my-eww--inject-user-agent is an :around advice on url-retrieve(-synchronously) +;; that adds a desktop User-Agent only for requests originating in an EWW +;; buffer. These tests pin that scoping: package.el and other non-EWW URL +;; callers must pass through untouched, so the advice can't change how the +;; rest of Emacs fetches URLs. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'eww) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'eww-config) + +;;; Normal Cases + +(ert-deftest test-eww-ua-injected-in-eww-buffer () + "Normal: in an eww-mode buffer the advice adds the configured User-Agent." + (with-temp-buffer + (setq major-mode 'eww-mode) + (let (seen) + (my-eww--inject-user-agent + (lambda (&rest _) (setq seen (assoc "User-Agent" url-request-extra-headers)))) + (should seen) + (should (equal (cdr seen) my-eww-user-agent))))) + +;;; Boundary Cases + +(ert-deftest test-eww-ua-not-injected-outside-eww () + "Boundary: outside eww-mode (package.el, normal url fetches) no UA is added." + (with-temp-buffer + (fundamental-mode) + (let ((url-request-extra-headers nil) captured) + (my-eww--inject-user-agent + (lambda (&rest _) (setq captured url-request-extra-headers))) + (should (null (assoc "User-Agent" captured)))))) + +(ert-deftest test-eww-ua-replaces-existing-and-keeps-other-headers () + "Boundary: an existing User-Agent is replaced (not duplicated) and other +headers survive, when the request comes from EWW." + (with-temp-buffer + (setq major-mode 'eww-mode) + (let ((url-request-extra-headers '(("User-Agent" . "old") ("Accept" . "x"))) + seen) + (my-eww--inject-user-agent + (lambda (&rest _) (setq seen url-request-extra-headers))) + (should (= 1 (cl-count "User-Agent" seen :key #'car :test #'string-equal))) + (should (equal (cdr (assoc "User-Agent" seen)) my-eww-user-agent)) + (should (assoc "Accept" seen))))) + +(provide 'test-eww-config-user-agent-advice) +;;; test-eww-config-user-agent-advice.el ends here |
