unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 9febaa33193f1454b2545d52a062fdb0b2f750be 3919 bytes (raw)
name: test/lisp/net/eww-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
 
;;; eww-tests.el --- tests for eww.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'ert)
(require 'eww)

(defmacro eww-test--with-mock-retrieve (&rest body)
  "Evaluate BODY with a mock implementation of `eww-retrieve'.
This avoids network requests during our tests.  Additionally, prepare a
temporary EWW buffer for our tests."
  (declare (indent 0))
    `(cl-letf (((symbol-function 'eww-retrieve)
                (lambda (url callback args)
                  (with-temp-buffer
                    ;; Write out an empty list of headers and the URL
                    ;; as our body.
                    (insert "\n" url)
                    (apply callback nil args)))))
       (with-temp-buffer
         (eww-mode)
         ,@body)))

(defun eww-test--history-urls ()
  (mapcar (lambda (elem) (plist-get elem :url)) eww-history))

;;; Tests:

(ert-deftest eww-test/history/new-page ()
  "Test that when visiting a new page, the previous one goes into the history."
  (eww-test--with-mock-retrieve
    (eww "one.invalid")
    (eww "two.invalid")
    (should (equal (eww-test--history-urls)
                   '("http://one.invalid/")))
    (eww "three.invalid")
    (should (equal (eww-test--history-urls)
                   '("http://two.invalid/"
                     "http://one.invalid/")))))

(ert-deftest eww-test/history/back-forward ()
  "Test that navigating through history just changes our history position.
See bug#69232."
  (eww-test--with-mock-retrieve
    (eww "one.invalid")
    (eww "two.invalid")
    (eww "three.invalid")
    (let ((url-history '("http://three.invalid/"
                         "http://two.invalid/"
                         "http://one.invalid/")))
      ;; Go back one page.  This should add "three.invalid" to the
      ;; history, making our position in the list 2.
      (eww-back-url)
      (should (equal (eww-test--history-urls) url-history))
      (should (= eww-history-position 2))
      ;; Go back again.
      (eww-back-url)
      (should (equal (eww-test--history-urls) url-history))
      (should (= eww-history-position 3))
      ;; At the beginning of the history, so trying to go back should
      ;; signal an error.
      (should-error (eww-back-url))
      ;; Go forward once.
      (eww-forward-url)
      (should (equal (eww-test--history-urls) url-history))
      (should (= eww-history-position 2))
      ;; Go forward again.
      (eww-forward-url)
      (should (equal (eww-test--history-urls) url-history))
      (should (= eww-history-position 1))
      ;; At the end of the history, so trying to go forward should
      ;; signal an error.
      (should-error (eww-forward-url)))))

(ert-deftest eww-test/history/clear-future ()
  "Test that going to a new page from a historical one clears future history.
See bug#69232."
  (eww-test--with-mock-retrieve
    (eww "one.invalid")
    (eww "two.invalid")
    (eww "three.invalid")
    (eww-back-url)
    (eww "four.invalid")
    (should (equal (eww-test--history-urls) '("http://two.invalid/"
                                              "http://one.invalid/")))
    (should (= eww-history-position 0))))

(provide 'eww-tests)
;; eww-tests.el ends here

debug log:

solving 9febaa33193 ...
found 9febaa33193 in https://yhetil.org/emacs-bugs/10a0d839-24f6-b521-1504-a5ca568b3dcc@gmail.com/

applying [1/1] https://yhetil.org/emacs-bugs/10a0d839-24f6-b521-1504-a5ca568b3dcc@gmail.com/
diff --git a/test/lisp/net/eww-tests.el b/test/lisp/net/eww-tests.el
new file mode 100644
index 00000000000..9febaa33193

Checking patch test/lisp/net/eww-tests.el...
Applied patch test/lisp/net/eww-tests.el cleanly.

index at:
100644 9febaa33193f1454b2545d52a062fdb0b2f750be	test/lisp/net/eww-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).