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.
127 lines
4.0 KiB
127 lines
4.0 KiB
5 years ago
|
import express from 'express';
|
||
|
import * as path from 'path';
|
||
|
import * as assert from 'assert';
|
||
|
import * as http from 'http';
|
||
|
|
||
|
import eventually from './eventually';
|
||
|
import { Builder, Lanthan } from 'lanthan';
|
||
|
import { WebDriver, By } from 'selenium-webdriver';
|
||
6 years ago
|
|
||
|
const newApp = () => {
|
||
|
let app = express();
|
||
5 years ago
|
app.get('/', (_req, res) => {
|
||
6 years ago
|
res.send(`<!DOCTYPEhtml>
|
||
|
<html lang="en">
|
||
|
<body style="width:10000px; height:10000px"></body>
|
||
|
</html">`);
|
||
|
});
|
||
|
return app;
|
||
|
};
|
||
|
|
||
|
describe("mark test", () => {
|
||
|
const port = 12321;
|
||
5 years ago
|
let http: http.Server;
|
||
|
let lanthan: Lanthan;
|
||
|
let webdriver: WebDriver;
|
||
|
let browser: any;
|
||
6 years ago
|
|
||
|
before(async() => {
|
||
|
http = newApp().listen(port);
|
||
|
|
||
5 years ago
|
lanthan = await Builder
|
||
|
.forBrowser('firefox')
|
||
|
.spyAddon(path.join(__dirname, '..'))
|
||
|
.build();
|
||
|
webdriver = lanthan.getWebDriver();
|
||
|
browser = lanthan.getWebExtBrowser();
|
||
6 years ago
|
});
|
||
|
|
||
|
after(async() => {
|
||
5 years ago
|
if (lanthan) {
|
||
|
await lanthan.quit();
|
||
|
}
|
||
|
if (http) {
|
||
|
http.close();
|
||
6 years ago
|
}
|
||
|
});
|
||
|
|
||
|
it('should set a local mark and jump to it', async () => {
|
||
5 years ago
|
await webdriver.navigate().to(`http://127.0.0.1:${port}`);
|
||
|
let body = await webdriver.findElement(By.css('body'));
|
||
6 years ago
|
|
||
5 years ago
|
await webdriver.executeScript(() => window.scrollTo(200, 200));
|
||
6 years ago
|
await body.sendKeys('m', 'a');
|
||
5 years ago
|
await webdriver.executeScript(() => window.scrollTo(500, 500));
|
||
6 years ago
|
await body.sendKeys('\'', 'a');
|
||
|
|
||
|
await eventually(async() => {
|
||
5 years ago
|
let pageXOffset = await webdriver.executeScript(() => window.pageXOffset);
|
||
|
let pageYOffset = await webdriver.executeScript(() => window.pageYOffset);
|
||
6 years ago
|
assert.equal(pageXOffset, 200);
|
||
|
assert.equal(pageYOffset, 200);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should set a global mark and jump to it', async () => {
|
||
5 years ago
|
await webdriver.navigate().to(`http://127.0.0.1:${port}#first`);
|
||
|
let body = await webdriver.findElement(By.css('body'));
|
||
6 years ago
|
|
||
5 years ago
|
await webdriver.executeScript(() => window.scrollTo(200, 200));
|
||
6 years ago
|
await body.sendKeys('m', 'A');
|
||
5 years ago
|
await webdriver.executeScript(() => window.scrollTo(500, 500));
|
||
6 years ago
|
await body.sendKeys('\'', 'A');
|
||
|
|
||
|
await eventually(async() => {
|
||
5 years ago
|
let pageXOffset = await webdriver.executeScript(() => window.pageXOffset);
|
||
|
let pageYOffset = await webdriver.executeScript(() => window.pageYOffset);
|
||
6 years ago
|
assert.equal(pageXOffset, 200);
|
||
|
assert.equal(pageYOffset, 200);
|
||
|
});
|
||
|
|
||
|
await browser.tabs.create({ url: `http://127.0.0.1:${port}#second` });
|
||
5 years ago
|
body = await webdriver.findElement(By.css('body'));
|
||
6 years ago
|
await body.sendKeys('\'', 'A');
|
||
|
|
||
|
await eventually(async() => {
|
||
|
let tab = (await browser.tabs.query({ active: true }))[0];
|
||
|
let url = new URL(tab.url);
|
||
|
assert.equal(url.hash, '#first');
|
||
|
|
||
5 years ago
|
let pageXOffset = await webdriver.executeScript(() => window.pageXOffset);
|
||
|
let pageYOffset = await webdriver.executeScript(() => window.pageYOffset);
|
||
6 years ago
|
assert.equal(pageXOffset, 200);
|
||
|
assert.equal(pageYOffset, 200);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('set a global mark and creates new tab from gone', async () => {
|
||
5 years ago
|
await webdriver.navigate().to(`http://127.0.0.1:${port}#first`);
|
||
|
await webdriver.executeScript(() => window.scrollTo(500, 500));
|
||
|
let body = await webdriver.findElement(By.css('body'));
|
||
6 years ago
|
await body.sendKeys('m', 'A');
|
||
|
|
||
|
let tab = (await browser.tabs.query({ active: true }))[0];
|
||
|
await browser.tabs.create({ url: `http://127.0.0.1:${port}#second` });
|
||
|
await browser.tabs.remove(tab.id);
|
||
|
|
||
5 years ago
|
let handles: string[];
|
||
6 years ago
|
await eventually(async() => {
|
||
5 years ago
|
handles = await webdriver.getAllWindowHandles();
|
||
5 years ago
|
await webdriver.getAllWindowHandles
|
||
6 years ago
|
assert.equal(handles.length, 2);
|
||
|
});
|
||
5 years ago
|
await webdriver.switchTo().window(handles!![0]);
|
||
5 years ago
|
await webdriver.navigate().to(`http://127.0.0.1:${port}#second`);
|
||
|
body = await webdriver.findElement(By.css('body'));
|
||
6 years ago
|
await body.sendKeys('\'', 'A');
|
||
|
|
||
|
await eventually(async() => {
|
||
|
let tab = (await browser.tabs.query({ active: true }))[0];
|
||
|
let url = new URL(tab.url);
|
||
|
assert.equal(url.hash, '#first');
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
|