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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
const express = require('express');
const lanthan = require('lanthan');
const path = require('path');
const assert = require('assert');
const eventually = require('./eventually');
const Key = lanthan.Key;
const newApp = () => {
let app = express();
app.get('/', (req, res) => {
res.send('ok');
});
return app;
};
describe("tab test", () => {
const port = 12321;
const url = `http://127.0.0.1:${port}/`;
let http;
let firefox;
let session;
let browser;
let win;
let tabs;
before(async() => {
firefox = await lanthan.firefox();
await firefox.session.installAddonFromPath(path.join(__dirname, '..'));
session = firefox.session;
browser = firefox.browser;
http = newApp().listen(port);
});
after(async() => {
http.close();
if (firefox) {
await firefox.close();
}
});
beforeEach(async() => {
win = await browser.windows.create({ url: `${url}#0` });
for (let i = 1; i < 5; ++i) {
await browser.tabs.create({ url: `${url}#${i}`, windowId: win.id });
await session.navigateTo(`${url}#${i}`);
}
tabs = await browser.tabs.query({ windowId: win.id });
tabs.sort((t1, t2) => t1.index - t2.index);
});
afterEach(async() => {
await browser.windows.remove(win.id);
});
it('deletes tab by d', async () => {
let body = await session.findElementByCSS('body');
await body.sendKeys('d');
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === tabs.length - 1);
});
it('deletes tabs to the right by D', async () => {
await browser.tabs.update(tabs[1].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Shift, 'd');
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === 2);
});
it('duplicates tab by zd', async () => {
await browser.tabs.update(tabs[0].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('z', 'd');
await eventually(async() => {
let current = await browser.tabs.query({ windowId: win.id });
current.sort((t1, t2) => t1.index - t2.index);
assert(current.length === tabs.length + 1);
assert(current[0].url === current[1].url);
});
});
it('makes pinned by zp', async () => {
await browser.tabs.update(tabs[0].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('z', 'p');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[0].pinned);
});
it('selects previous tab by K', async () => {
await browser.tabs.update(tabs[2].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Shift, 'K');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[1].active);
});
it('selects previous tab by K rotatory', async () => {
await browser.tabs.update(tabs[0].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Shift, 'K');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[current.length - 1].active)
});
it('selects next tab by J', async () => {
await browser.tabs.update(tabs[2].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Shift, 'J');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[3].active);
});
it('selects previous tab by J rotatory', async () => {
await browser.tabs.update(tabs[tabs.length - 1].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Shift, 'J');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[0].active)
});
it('selects first tab by g0', async () => {
await browser.tabs.update(tabs[2].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('g', '0');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[0].active)
});
it('selects last tab by g$', async () => {
await browser.tabs.update(tabs[2].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('g', '$');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[current.length - 1].active)
});
it('selects last selected tab by <C-6>', async () => {
await browser.tabs.update(tabs[1].id, { active: true });
await browser.tabs.update(tabs[4].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys(Key.Control, '6');
let current = await browser.tabs.query({ windowId: win.id });
assert(current[1].active)
});
// browser.sessions.getRecentlyClosed() sometime throws "An unexpected error occurred"
// This might be a bug in Firefox.
it.skip('reopen tab by u', async () => {
await browser.tabs.remove(tabs[1].id);
let body = await session.findElementByCSS('body');
await body.sendKeys('u');
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === tabs.length);
});
it('does not delete pinned tab by d', async () => {
await browser.tabs.update(tabs[0].id, { active: true, pinned: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('d');
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === tabs.length);
});
it('deletes pinned tab by !d', async () => {
await browser.tabs.update(tabs[0].id, { active: true, pinned: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('!', 'd');
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === tabs.length - 1);
});
it('opens view-source by gf', async () => {
await browser.tabs.update(tabs[0].id, { active: true });
let body = await session.findElementByCSS('body');
await body.sendKeys('g', 'f');
await eventually(async() => {
let current = await browser.tabs.query({ windowId: win.id });
assert(current.length === tabs.length + 1);
assert(current[current.length - 1].url === `view-source:${url}#0`);
});
});
});
|