aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJim Porter2025-06-17 09:11:55 -0700
committerJim Porter2025-06-25 21:26:04 -0700
commit2bdcf0250acecdb0719203ae711aedf5baad1783 (patch)
tree542289c62c26eab813388a761f823f3f783c6e7a /test
parentfaae9f572ab3027c46800575a12a72c8c0eee7c1 (diff)
downloademacs-2bdcf0250acecdb0719203ae711aedf5baad1783.tar.gz
emacs-2bdcf0250acecdb0719203ae711aedf5baad1783.zip
When making a readable page in EWW, include the <title> and similar tags
* lisp/net/eww.el (eww--walk-readability, eww-readable-dom): New functions. (eww-display-html): Call 'eww-readable-dom'. (eww-readable): Call 'eww-readable-dom'. Don't copy over 'eww-data' properties that our new readable page can handle on its own. (eww-score-readability): Rewrite in terms of 'eww--walk-readability'. Make obsolete. (eww-highest-readability): Make obsolete. * test/lisp/net/eww-tests.el (eww-test--lots-of-words) (eww-test--wordy-page): New variables... (eww-test/readable/toggle-display): ... use them. (eww-test/readable/default-readable): Make sure that the readable page includes the <title> and <link> tags (bug#77299).
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/eww-tests.el35
1 files changed, 22 insertions, 13 deletions
diff --git a/test/lisp/net/eww-tests.el b/test/lisp/net/eww-tests.el
index e7c5a29ecd4..18cbd272991 100644
--- a/test/lisp/net/eww-tests.el
+++ b/test/lisp/net/eww-tests.el
@@ -29,6 +29,21 @@
29The default just returns an empty list of headers and the URL as the 29The default just returns an empty list of headers and the URL as the
30body.") 30body.")
31 31
32(defvar eww-test--lots-of-words
33 (string-join (make-list 20 "All work and no play makes Jack a dull boy.")
34 " ")
35 "A long enough run of words to satisfy EWW's readable mode cutoff.")
36
37(defvar eww-test--wordy-page
38 (concat "<html>"
39 "<head>"
40 "<title>Welcome to my home page</title>"
41 "<link rel=\"home\" href=\"somewhere.invalid\">"
42 "</head><body>"
43 "<a>This is an uninteresting sentence.</a>"
44 "<div>" eww-test--lots-of-words "</div>"
45 "</body></html>"))
46
32(defmacro eww-test--with-mock-retrieve (&rest body) 47(defmacro eww-test--with-mock-retrieve (&rest body)
33 "Evaluate BODY with a mock implementation of `eww-retrieve'. 48 "Evaluate BODY with a mock implementation of `eww-retrieve'.
34This avoids network requests during our tests. Additionally, prepare a 49This avoids network requests during our tests. Additionally, prepare a
@@ -201,19 +216,10 @@ This sets `eww-before-browse-history-function' to
201 (eww-test--with-mock-retrieve 216 (eww-test--with-mock-retrieve
202 (let* ((shr-width most-positive-fixnum) 217 (let* ((shr-width most-positive-fixnum)
203 (shr-use-fonts nil) 218 (shr-use-fonts nil)
204 (words (string-join
205 (make-list
206 20 "All work and no play makes Jack a dull boy.")
207 " "))
208 (eww-test--response-function 219 (eww-test--response-function
209 (lambda (_url) 220 (lambda (_url)
210 (concat "Content-Type: text/html\n\n" 221 (concat "Content-Type: text/html\n\n"
211 "<html><body>" 222 eww-test--wordy-page))))
212 "<a>This is an uninteresting sentence.</a>"
213 "<div>"
214 words
215 "</div>"
216 "</body></html>"))))
217 (eww "example.invalid") 223 (eww "example.invalid")
218 ;; Make sure EWW renders the whole document. 224 ;; Make sure EWW renders the whole document.
219 (should-not (plist-get eww-data :readable)) 225 (should-not (plist-get eww-data :readable))
@@ -224,7 +230,7 @@ This sets `eww-before-browse-history-function' to
224 ;; Now, EWW should render just the "readable" parts. 230 ;; Now, EWW should render just the "readable" parts.
225 (should (plist-get eww-data :readable)) 231 (should (plist-get eww-data :readable))
226 (should (string-match-p 232 (should (string-match-p
227 (concat "\\`" (regexp-quote words) "\n*\\'") 233 (concat "\\`" (regexp-quote eww-test--lots-of-words) "\n*\\'")
228 (buffer-substring-no-properties (point-min) (point-max)))) 234 (buffer-substring-no-properties (point-min) (point-max))))
229 (eww-readable 'toggle) 235 (eww-readable 'toggle)
230 ;; Finally, EWW should render the whole document again. 236 ;; Finally, EWW should render the whole document again.
@@ -240,11 +246,14 @@ This sets `eww-before-browse-history-function' to
240 (let* ((eww-test--response-function 246 (let* ((eww-test--response-function
241 (lambda (_url) 247 (lambda (_url)
242 (concat "Content-Type: text/html\n\n" 248 (concat "Content-Type: text/html\n\n"
243 "<html><body>Hello there</body></html>"))) 249 eww-test--wordy-page)))
244 (eww-readable-urls '("://example\\.invalid/"))) 250 (eww-readable-urls '("://example\\.invalid/")))
245 (eww "example.invalid") 251 (eww "example.invalid")
246 ;; Make sure EWW uses "readable" mode. 252 ;; Make sure EWW uses "readable" mode.
247 (should (plist-get eww-data :readable))))) 253 (should (plist-get eww-data :readable))
254 ;; Make sure the page include the <title> and <link> nodes.
255 (should (equal (plist-get eww-data :title) "Welcome to my home page"))
256 (should (equal (plist-get eww-data :home) "somewhere.invalid")))))
248 257
249(provide 'eww-tests) 258(provide 'eww-tests)
250;; eww-tests.el ends here 259;; eww-tests.el ends here