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
|
const express = require('express');
const lanthan = require('lanthan');
const path = require('path');
const assert = require('assert');
const eventually = require('./eventually');
const newApp = () => {
let app = express();
app.get('/', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body style="width:10000px; height:10000px"></body>
</html">`);
});
return app;
};
describe("options page", () => {
const port = 12321;
let http;
let firefox;
let session;
let browser;
before(async() => {
http = newApp().listen(port);
firefox = await lanthan.firefox({
spy: path.join(__dirname, '..'),
builderf: (builder) => {
builder.addFile('build/settings.js');
builder.addFile('build/settings.html');
},
});
await firefox.session.installAddonFromPath(path.join(__dirname, '..'));
session = firefox.session;
browser = firefox.browser;
});
after(async() => {
if (firefox) {
await firefox.close();
}
http.close();
});
beforeEach(async() => {
let tabs = await browser.tabs.query({});
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
})
const updateTextarea = async(value) => {
let textarea = await session.findElementByCSS('textarea');
await session.executeScript(`document.querySelector('textarea').value = '${value}'`)
await textarea.sendKeys(' ');
await session.executeScript(() => document.querySelector('textarea').blur());
}
it('saves current config on blur', async () => {
let url = await browser.runtime.getURL("build/settings.html")
await session.navigateTo(url);
await updateTextarea(`{ "blacklist": [ "https://example.com" ] }`);
let { settings } = await browser.storage.local.get('settings');
assert.equal(settings.source, 'json')
assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ')
await updateTextarea(`invalid json`);
settings = (await browser.storage.local.get('settings')).settings;
assert.equal(settings.source, 'json')
assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ')
let error = await session.findElementByCSS('.settings-ui-input-error');
let text = await error.getText();
assert.ok(text.startsWith('SyntaxError:'))
});
it('updates keymaps without reloading', async () => {
await browser.tabs.create({ url: `http://127.0.0.1:${port}`, active: false });
let url = await browser.runtime.getURL("build/settings.html")
await session.navigateTo(url);
let handles = await session.getWindowHandles();
await updateTextarea(`{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }`);
await session.switchToWindow(handles[1]);
let body = await session.findElementByCSS('body');
await body.sendKeys('zz')
let y = await session.executeScript(() => window.pageYOffset);
assert.equal(y, 640);
})
});
|