A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
99 lines
2.9 KiB
5 years ago
|
import express from 'express';
|
||
|
import * as path from 'path';
|
||
|
import * as assert from 'assert';
|
||
|
import * as http from 'http';
|
||
|
|
||
|
import { Builder, Lanthan } from 'lanthan';
|
||
|
import { WebDriver, By } from 'selenium-webdriver';
|
||
5 years ago
|
|
||
5 years ago
|
const newApp = () => {
|
||
|
let app = express();
|
||
5 years ago
|
app.get('/', (_req, res) => {
|
||
5 years ago
|
res.send(`<!DOCTYPEhtml>
|
||
|
<html lang="en">
|
||
|
<body style="width:10000px; height:10000px"></body>
|
||
|
</html">`);
|
||
|
});
|
||
|
return app;
|
||
|
};
|
||
|
|
||
5 years ago
|
describe("options page", () => {
|
||
5 years ago
|
const port = 12321;
|
||
5 years ago
|
let http: http.Server;
|
||
|
let lanthan: Lanthan;
|
||
|
let webdriver: WebDriver;
|
||
|
let browser: any;
|
||
5 years ago
|
|
||
|
before(async() => {
|
||
5 years ago
|
http = newApp().listen(port);
|
||
|
|
||
5 years ago
|
lanthan = await Builder
|
||
|
.forBrowser('firefox')
|
||
|
.spyAddon(path.join(__dirname, '..'))
|
||
|
.build();
|
||
|
webdriver = lanthan.getWebDriver();
|
||
|
browser = lanthan.getWebExtBrowser();
|
||
5 years ago
|
});
|
||
|
|
||
|
after(async() => {
|
||
5 years ago
|
if (lanthan) {
|
||
|
await lanthan.quit();
|
||
|
}
|
||
|
if (http) {
|
||
|
http.close();
|
||
5 years ago
|
}
|
||
|
});
|
||
|
|
||
|
beforeEach(async() => {
|
||
|
let tabs = await browser.tabs.query({});
|
||
|
for (let tab of tabs.slice(1)) {
|
||
|
await browser.tabs.remove(tab.id);
|
||
|
}
|
||
|
})
|
||
|
|
||
5 years ago
|
const updateTextarea = async(value: string) => {
|
||
5 years ago
|
let textarea = await webdriver.findElement(By.css('textarea'));
|
||
|
await webdriver.executeScript(`document.querySelector('textarea').value = '${value}'`)
|
||
5 years ago
|
await textarea.sendKeys(' ');
|
||
5 years ago
|
await webdriver.executeScript(() => document.querySelector('textarea')!!.blur());
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
it('saves current config on blur', async () => {
|
||
|
let url = await browser.runtime.getURL("build/settings.html")
|
||
5 years ago
|
await webdriver.navigate().to(url);
|
||
5 years ago
|
|
||
|
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" ] } ')
|
||
|
|
||
5 years ago
|
let error = await webdriver.findElement(By.css('.settings-ui-input-error'));
|
||
5 years ago
|
let text = await error.getText();
|
||
|
assert.ok(text.startsWith('SyntaxError:'))
|
||
|
});
|
||
|
|
||
5 years ago
|
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")
|
||
5 years ago
|
await webdriver.navigate().to(url);
|
||
5 years ago
|
|
||
|
await updateTextarea(`{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }`);
|
||
|
|
||
5 years ago
|
let handles = await webdriver.getAllWindowHandles();
|
||
|
await webdriver.switchTo().window(handles[1]);
|
||
5 years ago
|
|
||
5 years ago
|
let body = await webdriver.findElement(By.css('body'));
|
||
5 years ago
|
await body.sendKeys('zz')
|
||
|
|
||
5 years ago
|
let y = await webdriver.executeScript(() => window.pageYOffset);
|
||
5 years ago
|
assert.equal(y, 640);
|
||
|
})
|
||
|
});
|