1--- Basic async test functions.
2--
3-- @copyright 2017 Aidan Holm <aidanholm@gmail.com>
4
5local T = {}
6local test = require "tests.lib"
7local assert = require("luassert")
8local spy = require 'luassert.spy'
9local match = require("luassert.match")
10
11uris = {"about:blank"}
12require "config.rc"
13
14local window = require "window"
15local w = assert(select(2, next(window.bywidget)))
16
17T.test_undo_close_works = function ()
18 -- Load page in new tab
19 local uri = test.http_server() .. "undoclose_page.html"
20 w:new_tab(uri)
21 assert(w.tabs:current() == 2)
22 test.wait_for_view(w.view)
23
24 -- Try to open the menu
25 local notify_spy = spy.on(window.methods, "notify")
26 w:run_cmd(":undolist")
27 assert.spy(notify_spy).was.called_with(match._, "No closed tabs to display")
28 assert(w:is_mode("normal"))
29
30 -- Close the tab
31 w:close_tab()
32 assert(w.tabs:current() == 1)
33
34 -- Try to open the menu again
35 notify_spy = spy.on(window.methods, "notify")
36 w:run_cmd(":undolist")
37 assert.spy(notify_spy).was_not_called_with(match._, "No closed tabs to display")
38 assert(w:is_mode("undolist"))
39 w:set_mode("normal")
40
41 -- Undo-close the tab
42 w:undo_close_tab(1)
43 assert(w.tabs:current() == 2)
44 test.wait_for_view(w.view)
45 test.wait_for_signal(w.view, "property::title", 2000)
46
47 assert(w.view.uri == uri)
48 assert(w.view.title == "undoclose_page")
49
50 -- Restore to initial state
51 w:close_tab()
52 assert(w.tabs:current() == 1)
53 assert(w.view.uri == "about:blank")
54end
55
56T.test_undo_close_restores_tab_history = function ()
57 -- Load page in new tab
58 local uri = test.http_server() .. "undoclose_page.html"
59 w:new_tab(uri)
60 assert.is_equal(w.tabs:current(), 2)
61 test.wait_for_view(w.view)
62
63 -- Navigate to about:blank
64 w.view.uri = "about:blank"
65 test.wait_for_view(w.view)
66
67 -- Close and undo-close
68 w:close_tab()
69 w:undo_close_tab()
70 test.wait_for_view(w.view)
71 assert.is_equal(w.tabs:current(), 2)
72 assert.is_equal(w.view.uri, 'about:blank')
73
74 -- Navigate back
75 w:back(1)
…lines 76–88 unchanged (13 lines)