Use TestServer on e2e

jh-changes
Shin'ya UEOKA 5 years ago
parent 4a4b5e1303
commit 1b92be6360
  1. 58
      e2e/blacklist.test.ts
  2. 50
      e2e/clipboard.test.ts
  3. 31
      e2e/command_addbookmark.test.ts
  4. 64
      e2e/command_bdelete.test.ts
  5. 27
      e2e/command_buffer.test.ts
  6. 43
      e2e/command_open.test.ts
  7. 28
      e2e/command_quit.test.ts
  8. 43
      e2e/command_tabopen.test.ts
  9. 43
      e2e/command_winopen.test.ts
  10. 19
      e2e/completion.test.ts
  11. 35
      e2e/completion_buffers.test.ts
  12. 27
      e2e/completion_open.test.ts
  13. 36
      e2e/console.test.ts
  14. 127
      e2e/follow.test.ts
  15. 31
      e2e/follow_properties.test.ts
  16. 39
      e2e/mark.test.ts
  17. 64
      e2e/navigate.test.ts
  18. 31
      e2e/options.test.ts
  19. 28
      e2e/repeat.test.ts
  20. 32
      e2e/scroll.test.ts
  21. 30
      e2e/tab.test.ts

@ -1,49 +1,29 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import * as http from 'http';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (_req, res) => {
res.status(200).send(`<!DOCTYPEhtml>
<html lang="en">
<body style="width:10000px; height:10000px"></body>
</html>`);
});
return app;
};
describe("navigate test", () => {
const port = 12321;
let http: http.Server;
describe("blacklist test", () => {
let server = new TestServer().receiveContent('/*',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
});
await server.start();
after(async() => {
if (lanthan) {
await lanthan.quit();
}
http.close();
});
it('should disable add-on if the URL is in the blacklist', async () => {
let url = server.url('/a').replace('http://', '');
await browser.storage.local.set({
settings: {
source: 'json',
@ -51,24 +31,32 @@ describe("navigate test", () => {
"keymaps": {
"j": { "type": "scroll.vertically", "count": 1 }
},
"blacklist": [ "127.0.0.1:${port}/a" ]
"blacklist": [ "${url}" ]
}`,
},
});
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
});
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a`);
it('should disable add-on if the URL is in the blacklist', async () => {
let page = await Page.navigateTo(webdriver, server.url('/a'));
await page.sendKeys('j')
// not works
let pageYOffset = await webdriver.executeScript(() => window.pageYOffset);
let scrollY = await page.getScrollY();
assert.equal(pageYOffset, 0);
assert.equal(scrollY, 0);
});
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/ab`);
it('should enabled add-on if the URL is not in the blacklist', async () => {
let page = await Page.navigateTo(webdriver, server.url('/ab'));
await page.sendKeys('j');
// works
scrollY = await page.getScrollY();
let scrollY = await page.getScrollY();
assert.equal(scrollY, 64);
});
});

@ -1,8 +1,7 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import * as path from 'path';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import * as clipboard from './lib/clipboard';
import settings from './settings';
@ -10,24 +9,13 @@ import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.status(200).send(`<html lang="en"></html">`);
});
return app;
};
describe("clipboard test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer(12321).receiveContent('/happy', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
@ -38,13 +26,15 @@ describe("clipboard test", () => {
await browser.storage.local.set({
settings,
});
await server.start();
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
http.close();
});
beforeEach(async() => {
@ -55,38 +45,38 @@ describe("clipboard test", () => {
})
it('should copy current URL by y', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/#should_copy_url`);
let page = await Page.navigateTo(webdriver, server.url('/#should_copy_url'));
await page.sendKeys('y');
await eventually(async() => {
let data = await clipboard.read();
assert.equal(data, `http://127.0.0.1:${port}/#should_copy_url`);
assert.equal(data, server.url('/#should_copy_url'));
});
});
it('should open an URL from clipboard by p', async () => {
await clipboard.write(`http://127.0.0.1:${port}/#open_from_clipboard`);
await clipboard.write(server.url('/#open_from_clipboard'));
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys('p');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true });
assert.equal(tabs[0].url, `http://127.0.0.1:${port}/#open_from_clipboard`);
assert.equal(tabs[0].url, server.url('/#open_from_clipboard'));
});
});
it('should open an URL from clipboard to new tab by P', async () => {
await clipboard.write(`http://127.0.0.1:${port}/#open_to_new_tab`);
await clipboard.write(server.url('/#open_to_new_tab'));
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys(Key.SHIFT, 'p');
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/`,
`http://127.0.0.1:${port}/#open_to_new_tab`,
server.url(),
server.url('/#open_to_new_tab'),
]);
});
});
@ -94,26 +84,26 @@ describe("clipboard test", () => {
it('should open search result with keywords in clipboard by p', async () => {
await clipboard.write(`an apple`);
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys(Key.SHIFT, 'p');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true });
assert.equal(tabs[0].url, `http://127.0.0.1:${port}/google?q=an%20apple`);
assert.equal(tabs[0].url, server.url('/google?q=an%20apple'));
});
});
it('should open search result with keywords in clipboard to new tabby P', async () => {
await clipboard.write(`an apple`);
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys(Key.SHIFT, 'p');
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/`,
`http://127.0.0.1:${port}/google?q=an%20apple`,
server.url(),
server.url('/google?q=an%20apple'),
]);
});
});

@ -1,53 +1,40 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/happy', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<head>
<title>how to be happy</title>
</head>
</html">`);
});
return app;
};
describe('addbookmark command test', () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/happy', `
<!DOCTYPE html>
<html lang="en"><head><title>how to be happy</title></head></html">`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
});
beforeEach(async() => {
await webdriver.navigate().to(`http://127.0.0.1:${port}/happy`);
await webdriver.navigate().to(server.url('/happy'));
});
it('should add a bookmark from the current page', async() => {
@ -58,7 +45,7 @@ describe('addbookmark command test', () => {
await eventually(async() => {
var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' });
assert.equal(bookmarks.length, 1);
assert.equal(bookmarks[0].url, `http://127.0.0.1:${port}/happy`);
assert.equal(bookmarks[0].url, server.url('/happy'));
});
});
});

@ -1,46 +1,30 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<head>
<title>my_${req.path.slice(1)}</title>
</head>
<body><h1>${req.path}</h1></body>
</html">`);
});
return app;
};
describe('bdelete/bdeletes command test', () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/*', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -51,11 +35,11 @@ describe('bdelete/bdeletes command test', () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true });
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site3`, pinned: true })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site4` })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site5` })
await browser.tabs.update(tabs[0].id, { url: server.url('/site1'), pinned: true });
await browser.tabs.create({ url: server.url('/site2'), pinned: true })
await browser.tabs.create({ url: server.url('/site3'), pinned: true })
await browser.tabs.create({ url: server.url('/site4'), })
await browser.tabs.create({ url: server.url('/site5'), })
await eventually(async() => {
let handles = await webdriver.getAllWindowHandles();
@ -72,10 +56,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`,
`http://127.0.0.1:${port}/site2`,
`http://127.0.0.1:${port}/site3`,
`http://127.0.0.1:${port}/site4`,
server.url('/site1'),
server.url('/site2'),
server.url('/site3'),
server.url('/site4'),
])
});
});
@ -121,10 +105,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`,
`http://127.0.0.1:${port}/site2`,
`http://127.0.0.1:${port}/site3`,
`http://127.0.0.1:${port}/site4`,
server.url('/site1'),
server.url('/site2'),
server.url('/site3'),
server.url('/site4'),
])
});
});
@ -137,10 +121,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site2`,
`http://127.0.0.1:${port}/site3`,
`http://127.0.0.1:${port}/site4`,
`http://127.0.0.1:${port}/site5`,
server.url('/site2'),
server.url('/site3'),
server.url('/site4'),
server.url('/site5'),
])
});
});
@ -153,9 +137,9 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => {
let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`,
`http://127.0.0.1:${port}/site2`,
`http://127.0.0.1:${port}/site3`,
server.url('/site1'),
server.url('/site2'),
server.url('/site3'),
])
});
});

@ -1,46 +1,39 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import { Request, Response } from 'express';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
describe('buffer command test', () => {
let server = new TestServer().handle('/*', (req: Request, res: Response) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<title>my_${req.path.slice(1)}</title>
</head>
<body><h1>${req.path}</h1></body>
</html">`);
});
return app;
};
describe('buffer command test', () => {
const port = 12321;
let http: http.Server;
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -51,9 +44,9 @@ describe('buffer command test', () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` });
await browser.tabs.update(tabs[0].id, { url: server.url('/site1') });
for (let i = 2; i <= 5; ++i) {
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`})
await browser.tabs.create({ url: server.url('/site' + i) });
}
await eventually(async() => {

@ -1,37 +1,17 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
app.get('/' + name, (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("open command test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer(12321)
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
@ -44,15 +24,16 @@ describe("open command test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({
settings,
});
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -60,7 +41,7 @@ describe("open command test", () => {
beforeEach(async() => {
await webdriver.switchTo().defaultContent();
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, server.url());
})
it('should open default search for keywords by open command ', async() => {
@ -70,7 +51,7 @@ describe("open command test", () => {
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`)
assert.equal(url.href, server.url('/google?q=an%20apple'))
});
});
@ -81,7 +62,7 @@ describe("open command test", () => {
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`)
assert.equal(url.href, server.url('/yahoo?q=an%20apple'))
});
});
@ -92,7 +73,7 @@ describe("open command test", () => {
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`)
assert.equal(url.href, server.url('/google?q='))
});
});
@ -103,7 +84,7 @@ describe("open command test", () => {
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`)
assert.equal(url.href, server.url('/yahoo?q='))
});
});

@ -1,46 +1,30 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<head>
<title>my_${req.path.slice(1)}</title>
</head>
<body><h1>${req.path}</h1></body>
</html">`);
});
return app;
};
describe('quit/quitall command test', () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/*', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -51,9 +35,9 @@ describe('quit/quitall command test', () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` });
await browser.tabs.update(tabs[0].id, { url: server.url('/site1') });
for (let i = 2; i <= 5; ++i) {
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`})
await browser.tabs.create({ url: server.url('/site' + i) })
}
await eventually(async() => {

@ -1,44 +1,23 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
app.get('/' + name, (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("tabopen command test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer(12321)
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
@ -49,10 +28,12 @@ describe("tabopen command test", () => {
await browser.storage.local.set({
settings,
});
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -64,7 +45,7 @@ describe("tabopen command test", () => {
await browser.tabs.remove(tab.id);
}
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, server.url());
})
it('should open default search for keywords by tabopen command ', async() => {
@ -75,7 +56,7 @@ describe("tabopen command test", () => {
let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`)
assert.equal(url.href, server.url('/google?q=an%20apple') )
});
});
@ -87,7 +68,7 @@ describe("tabopen command test", () => {
let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`)
assert.equal(url.href, server.url('/yahoo?q=an%20apple'))
});
});
@ -99,7 +80,7 @@ describe("tabopen command test", () => {
let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`)
assert.equal(url.href, server.url('/google?q='))
});
});
@ -111,7 +92,7 @@ describe("tabopen command test", () => {
let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`)
assert.equal(url.href, server.url('/yahoo?q='))
});
});

@ -1,44 +1,23 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
app.get('/' + name, (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("winopen command test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer(12321)
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
@ -48,10 +27,12 @@ describe("winopen command test", () => {
await browser.storage.local.set({
settings,
});
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -63,7 +44,7 @@ describe("winopen command test", () => {
await browser.windows.remove(win.id);
}
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/area`);
page = await Page.navigateTo(webdriver, server.url());
})
it('should open default search for keywords by winopen command ', async() => {
@ -76,7 +57,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`)
assert.equal(url.href, server.url('/google?q=an%20apple'))
});
});
@ -90,7 +71,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`)
assert.equal(url.href, server.url('/yahoo?q=an%20apple'))
});
});
@ -104,7 +85,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`)
assert.equal(url.href, server.url('/google?q='))
});
});
@ -118,7 +99,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`)
assert.equal(url.href, server.url('/yahoo?q='))
});
});

@ -1,7 +1,5 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import eventually from './eventually';
import settings from './settings';
@ -9,20 +7,7 @@ import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>ok</body>
</html">`);
});
return app;
};
describe("general completion test", () => {
const port = 12321;
let http: http.Server;
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
@ -35,7 +20,6 @@ describe("general completion test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({
settings,
@ -43,14 +27,13 @@ describe("general completion test", () => {
});
after(async() => {
http.close();
if (lanthan) {
await lanthan.quit();
}
});
beforeEach(async() => {
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, 'about:blank');
});
it('should all commands on empty line', async() => {

@ -1,32 +1,24 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import * as path from 'path';
import { Request, Response } from 'express'
import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
describe("completion on buffer/bdelete/bdeletes", () => {
let server = new TestServer().handle('/*', (req: Request, res: Response) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<title>title_${req.path.slice(1)}</title>
</head>
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("completion on buffer/bdelete/bdeletes", () => {
const port = 12321;
let http: http.Server;
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
@ -39,15 +31,16 @@ describe("completion on buffer/bdelete/bdeletes", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({
settings,
});
await server.start();
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
@ -59,10 +52,10 @@ describe("completion on buffer/bdelete/bdeletes", () => {
await browser.tabs.remove(tab.id);
}
await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true });
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true })
await browser.tabs.update(tabs[0].id, { url: server.url('/site1'), pinned: true });
await browser.tabs.create({ url:server.url('/site2'), pinned: true })
for (let i = 3; i <= 5; ++i) {
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}` })
await browser.tabs.create({ url: server.url('/site' + i) });
}
await eventually(async() => {
@ -102,7 +95,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
assert.ok(items[1].text.startsWith('2:'));
assert.ok(items[1].text.includes('title_site2'));
assert.ok(items[1].text.includes(`http://127.0.0.1:${port}/site2`));
assert.ok(items[1].text.includes(server.url('/site2')));
});
})

@ -1,60 +1,47 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>ok</body>
</html">`);
});
return app;
};
describe("completion on open/tabopen/winopen commands", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/*', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
await server.start();
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({
settings,
});
// Add item into hitories
await webdriver.navigate().to(`https://i-beam.org/404`);
await webdriver.navigate().to(('https://i-beam.org/404'));
});
after(async() => {
http.close();
await server.stop();
if (lanthan) {
await lanthan.quit();
}
});
beforeEach(async() => {
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, server.url());
});
it('should show completions from search engines, bookmarks, and histories by "open" command', async() => {

@ -1,53 +1,37 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<head>
<title>Hello, world!</title>
</head>
</html">`);
});
return app;
};
describe("console test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html">`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let page: Page;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
await server.start();
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
if (http) {
http.close();
}
});
beforeEach(async() => {
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, server.url());
});
it('open console with :', async() => {
@ -65,7 +49,7 @@ describe("console test", () => {
it('open console with open command and current URL by O', async() => {
await page.sendKeys(Key.SHIFT, 'o');
let console = await page.getConsole();
assert.equal(await console.currentValue(), `open http://127.0.0.1:${port}/`);
assert.equal(await console.currentValue(), `open ${server.url()}`);
});
it('open console with tabopen command by t', async() => {
@ -77,7 +61,7 @@ describe("console test", () => {
it('open console with tabopen command and current URL by T', async() => {
await page.sendKeys(Key.SHIFT, 't');
let console = await page.getConsole();
assert.equal(await console.currentValue(), `tabopen http://127.0.0.1:${port}/`);
assert.equal(await console.currentValue(), `tabopen ${server.url()}`);
});
it('open console with winopen command by w', async() => {
@ -89,7 +73,7 @@ describe("console test", () => {
it('open console with winopen command and current URL by W', async() => {
await page.sendKeys(Key.SHIFT, 'W');
let console = await page.getConsole();
assert.equal(await console.currentValue(), `winopen http://127.0.0.1:${port}/`);
assert.equal(await console.currentValue(), `winopen ${server.url()}`);
});
it('open console with buffer command by b', async() => {

@ -1,34 +1,30 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><a href="hello">hello</a></body>
</html">`);
});
app.get('/follow-input', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><input></body>
</html">`);
});
app.get('/area', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>
let server = new TestServer();
server.receiveContent('/', `
<!DOCTYPE html>
<html lang="en"><body>
<a href="hello">hello</a>
</body></html">`);
server.receiveContent('/follow-input', `
<!DOCTYPE html>
<html lang="en"><body>
<input>
</body></html">`);
server.receiveContent('/area', `
<!DOCTYPE html>
<html lang="en"><body>
<img
width="256" height="256" usemap="#map"
src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="
@ -38,9 +34,7 @@ const newApp = () => {
<area shape="rect" coords="64,64,64,64" href="/">
<area shape="rect" coords="128,128,64,64" href="/">
</map>
</body>
</html">`);
});
</body></html">`);
/*
* test case: link2 is out of the viewport
@ -52,16 +46,13 @@ const newApp = () => {
* | |
* +-----------------+
*/
app.get('/test1', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>
server.receiveContent('/test1', `
<!DOCTYPE html>
<html lang="en"><body>
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body>
</html">`);
});
</body></html">`);
/*
* test case 2: link2 and link3 are out of window of the frame
@ -74,22 +65,18 @@ const newApp = () => {
* | |
* +-----------------+
*/
app.get('/test2', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><iframe height="5000" src='/test2-frame'></body>
</html">`);
});
app.get('/test2-frame', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>
server.receiveContent('/test2', `
<!DOCTYPE html>
<html lang="en"><body>
<iframe height="5000" src='/test2-frame'>
</body></html">`);
server.receiveContent('/test2-frame', `
<!DOCTYPE html>
<html lang="en"><body>
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body>
</html">`);
});
</body></html">`);
/* test case 3: link2 is out of window of the frame
* +-----------------+
@ -101,51 +88,43 @@ const newApp = () => {
* | |
* +-----------------+
*/
app.get('/test3', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><iframe src='/test3-frame'></body>
</html">`);
});
app.get('/test3-frame', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>
server.receiveContent('/test3', `
<!DOCTYPE html>
<html lang="en"><body>
<iframe src='/test3-frame'>
</body></html">`);
server.receiveContent('/test3-frame', `
<!DOCTYPE html>
<html lang="en"><body>
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body>
</html">`);
});
</body></html">`);
return app;
return server;
};
describe('follow test', () => {
const port = 12321;
let http: http.Server;
let server = newApp();
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
if (http) {
http.close();
}
});
afterEach(async() => {
@ -156,7 +135,7 @@ describe('follow test', () => {
});
it('should focus an input by f', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/follow-input`);
let page = await Page.navigateTo(webdriver, server.url('/follow-input'));
await page.sendKeys('f');
await page.waitAndGetHints();
await page.sendKeys('a');
@ -166,7 +145,7 @@ describe('follow test', () => {
});
it('should open a link by f', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys('f');
await page.waitAndGetHints();
await page.sendKeys('a');
@ -178,7 +157,7 @@ describe('follow test', () => {
});
it('should focus an input by F', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/follow-input`);
let page = await Page.navigateTo(webdriver, server.url('/follow-input'));
await page.sendKeys(Key.SHIFT, 'f');
await page.waitAndGetHints();
await page.sendKeys('a');
@ -188,7 +167,7 @@ describe('follow test', () => {
});
it('should open a link to new tab by F', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys(Key.SHIFT, 'f');
await page.waitAndGetHints();
await page.sendKeys('a');
@ -202,7 +181,7 @@ describe('follow test', () => {
});
it('should show hints of links in area', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/area`);
let page = await Page.navigateTo(webdriver, server.url('/area'));
await page.sendKeys(Key.SHIFT, 'f');
let hints = await page.waitAndGetHints();
@ -210,7 +189,7 @@ describe('follow test', () => {
});
it('should shows hints only in viewport', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/test1`);
let page = await Page.navigateTo(webdriver, server.url('/test1'));
await page.sendKeys(Key.SHIFT, 'f');
let hints = await page.waitAndGetHints();
@ -218,7 +197,7 @@ describe('follow test', () => {
});
it('should shows hints only in window of the frame', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/test2`);
let page = await Page.navigateTo(webdriver, server.url('/test2'));
await page.sendKeys(Key.SHIFT, 'f');
await webdriver.switchTo().frame(0);
@ -227,7 +206,7 @@ describe('follow test', () => {
});
it('should shows hints only in the frame', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/test3`);
let page = await Page.navigateTo(webdriver, server.url('/test3'));
await page.sendKeys(Key.SHIFT, 'f');
await webdriver.switchTo().frame(0);

@ -1,42 +1,29 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/', (_req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body>
describe('follow properties test', () => {
let server = new TestServer().receiveContent('/', `
<!DOCTYPE html>
<html lang="en"><body>
<a href="/">link1</a>
<a href="/">link2</a>
<a href="/">link3</a>
<a href="/">link4</a>
<a href="/">link5</a>
</body>
</html">`);
});
return app;
};
</body></html">`);
describe('follow properties test', () => {
const port = 12321;
let http: http.Server;
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
@ -62,17 +49,19 @@ describe('follow properties test', () => {
}
}`,
}});
await server.start();
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
http.close();
});
beforeEach(async() => {
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
page = await Page.navigateTo(webdriver, server.url());
});
afterEach(async() => {

@ -1,53 +1,40 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
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("mark test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start()
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
if (http) {
http.close();
}
});
it('should set a local mark and jump to it', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
let page = await Page.navigateTo(webdriver, server.url());
await page.scrollTo(200, 200);
await page.sendKeys('m', 'a');
await page.scrollTo(500, 500);
@ -60,7 +47,7 @@ describe("mark test", () => {
});
it('should set a global mark and jump to it', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}#first`);
let page = await Page.navigateTo(webdriver, server.url('/#first'));
await page.scrollTo(200, 200);
await page.sendKeys('m', 'A');
await page.scrollTo(500, 500);
@ -71,7 +58,7 @@ describe("mark test", () => {
assert.equal(await page.getScrollY(), 200);
});
await browser.tabs.create({ url: `http://127.0.0.1:${port}#second` });
await browser.tabs.create({ url: server.url('/#second') });
page = await Page.currentContext(webdriver);
await page.sendKeys('\'', 'A');
@ -86,12 +73,12 @@ describe("mark test", () => {
});
it('set a global mark and creates new tab from gone', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}#first`);
let page = await Page.navigateTo(webdriver, server.url('/#first'));
await page.scrollTo(500, 500);
await page.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.create({ url: server.url('/#second') });
await browser.tabs.remove(tab.id);
let handles: string[];
@ -101,7 +88,7 @@ describe("mark test", () => {
});
await webdriver.switchTo().window(handles!![0]);
page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}#second`);
page = await Page.navigateTo(webdriver, server.url('/#second'));
await page.sendKeys('\'', 'A');
await eventually(async() => {

@ -1,8 +1,7 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
@ -10,16 +9,19 @@ import { Options as FirefoxOptions } from 'selenium-webdriver/firefox';
import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/pagenation-a/:page', (req, res) => {
let server = new TestServer();
server.handle('/pagenation-a/:page', (req, res) => {
res.status(200).send(`
<!DOCTYPE html>
<html lang="en">
<a href="/pagenation-a/${Number(req.params.page) - 1}">prev</a>
<a href="/pagenation-a/${Number(req.params.page) + 1}">next</a>
</html">`);
});
app.get('/pagenation-link/:page', (req, res) => {
server.handle('/pagenation-link/:page', (req, res) => {
res.status(200).send(`
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="prev" href="/pagenation-link/${Number(req.params.page) - 1}"></link>
@ -27,37 +29,31 @@ const newApp = () => {
</head>
</html">`);
});
app.get('/reload', (_req, res) => {
res.status(200).send(`
server.receiveContent('/reload', `
<!DOCTYPE html>
<html lang="en">
<head>
<script>window.location.hash = Date.now()</script>
</head>
<body style="width:10000px; height:10000px"></body>
</html">`);
});
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
${req.path}
</html">`);
});
return app;
server.receiveContent('/*', `ok`);
return server;
};
describe("navigate test", () => {
const port = 12321;
let http: http.Server;
let server = newApp();
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
await server.start();
let opts = (new FirefoxOptions() as any)
.setPreference('browser.startup.homepage', `http://127.0.0.1:${port}#home`);
http = newApp().listen(port);
.setPreference('browser.startup.homepage', server.url('/#home'));
lanthan = await Builder
.forBrowser('firefox')
.setOptions(opts)
@ -68,10 +64,10 @@ describe("navigate test", () => {
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
http.close();
});
beforeEach(async() => {
@ -82,7 +78,7 @@ describe("navigate test", () => {
})
it('should go to parent path without hash by gu', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c`);
let page = await Page.navigateTo(webdriver, server.url('/a/b/c'));
await page.sendKeys('g', 'u');
await eventually(async() => {
@ -93,7 +89,7 @@ describe("navigate test", () => {
});
it('should remove hash by gu', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c#hash`);
let page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash'));
await page.sendKeys('g', 'u');
await eventually(async() => {
@ -105,7 +101,7 @@ describe("navigate test", () => {
});
it('should go to root path by gU', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c#hash`);
let page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash'));
await page.sendKeys('g', Key.SHIFT, 'u');
await eventually(async() => {
@ -116,8 +112,8 @@ describe("navigate test", () => {
});
it('should go back and forward in history by H and L', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/first`);
await page.navigateTo(`http://127.0.0.1:${port}/second`);
let page = await Page.navigateTo(webdriver, server.url('/first'));
await page.navigateTo(server.url('/second'));
await page.sendKeys(Key.SHIFT, 'h');
await eventually(async() => {
@ -137,7 +133,7 @@ describe("navigate test", () => {
});
it('should go previous and next page in <a> by [[ and ]]', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-a/10`);
let page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10'));
await page.sendKeys('[', '[');
await eventually(async() => {
@ -148,7 +144,7 @@ describe("navigate test", () => {
});
it('should go next page in <a> by ]]', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-a/10`);
let page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10'));
await page.sendKeys(']', ']');
await eventually(async() => {
@ -159,7 +155,7 @@ describe("navigate test", () => {
});
it('should go previous page in <link> by ]]', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-link/10`);
let page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10'));
await page.sendKeys('[', '[');
await eventually(async() => {
@ -170,7 +166,7 @@ describe("navigate test", () => {
});
it('should go next page by in <link> by [[', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-link/10`);
let page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10'));
await page.sendKeys(']', ']');
await eventually(async() => {
@ -181,7 +177,7 @@ describe("navigate test", () => {
});
it('should go to home page into current tab by gh', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys('g', 'h');
await eventually(async() => {
@ -192,7 +188,7 @@ describe("navigate test", () => {
});
it('should go to home page into current tab by gH', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`);
let page = await Page.navigateTo(webdriver, server.url());
await page.sendKeys('g', Key.SHIFT, 'H');
await eventually(async() => {
@ -205,7 +201,7 @@ describe("navigate test", () => {
});
it('should reload current tab by r', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/reload`);
let page = await Page.navigateTo(webdriver, server.url('/reload'));
await page.scrollTo(500, 500);
let before: number;
@ -231,7 +227,7 @@ describe("navigate test", () => {
});
it('should reload current tab without cache by R', async () => {
let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/reload`);
let page = await Page.navigateTo(webdriver, server.url('/reload'));
await page.scrollTo(500, 500);
let before: number;

@ -1,50 +1,37 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import eventually from './eventually';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
import OptionPage from './lib/OptionPage';
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: http.Server;
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await server.start();
});
after(async() => {
if (lanthan) {
await lanthan.quit();
}
if (http) {
http.close();
}
await server.stop();
});
beforeEach(async() => {
@ -78,7 +65,7 @@ describe("options page", () => {
let jsonPage = await optionPage.asJSONOptionPage();
await jsonPage.updateSettings(`{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }`);
await browser.tabs.create({ url: `http://127.0.0.1:${port}`, active: false });
await browser.tabs.create({ url: server.url(), active: false });
await new Promise((resolve) => setTimeout(resolve, 100));
let handles = await webdriver.getAllWindowHandles();
await webdriver.switchTo().window(handles[1]);

@ -1,26 +1,14 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
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: http.Server;
let server = new TestServer().receiveContent('/*', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
@ -32,22 +20,20 @@ describe("tab test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await server.start();
});
after(async() => {
if (http) {
http.close();
}
await server.stop();
if (lanthan) {
await lanthan.quit();
}
});
it('repeats last command', async () => {
let page = await Page.navigateTo(webdriver, url);
let page = await Page.navigateTo(webdriver, server.url());
let console = await page.showConsole();
await console.execCommand(`tabopen ${url}newtab`);
await console.execCommand(`tabopen ${server.url('/newtab')}`);
await eventually(async() => {
let current = await browser.tabs.query({ url: `*://*/newtab` });
@ -65,7 +51,7 @@ describe("tab test", () => {
it('repeats last operation', async () => {
for (let i = 1; i < 5; ++i) {
await browser.tabs.create({ url: `${url}#${i}` });
await browser.tabs.create({ url: server.url('/#' + i) });
}
let before = await browser.tabs.query({});

@ -1,63 +1,49 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
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("scroll test", () => {
const port = 12321;
let http: http.Server;
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
let page: Page;
before(async() => {
http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
await server.start();
});
after(async() => {
await server.stop();
if (lanthan) {
await lanthan.quit();
}
if (http) {
http.close();
}
});
beforeEach(async() => {
await webdriver.navigate().to(`http://127.0.0.1:${port}`);
await webdriver.navigate().to(server.url());
page = await Page.currentContext(webdriver);
});
it('scrolls up by k', async () => {
it('scrolls up by j', async () => {
await page.sendKeys('j');
let scrollY = await page.getScrollY();
assert.equal(scrollY, 64);
});
it('scrolls down by j', async () => {
it('scrolls down by k', async () => {
await webdriver.executeScript(() => window.scrollTo(0, 200));
await page.sendKeys('k');

@ -1,26 +1,14 @@
import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
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: http.Server;
let server = new TestServer().receiveContent('/*', 'ok');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
@ -34,23 +22,21 @@ describe("tab test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await server.start();
});
after(async() => {
if (http) {
http.close();
}
await server.stop();
if (lanthan) {
await lanthan.quit();
}
});
beforeEach(async() => {
win = await browser.windows.create({ url: `${url}#0` });
win = await browser.windows.create({ url: server.url('/#0') });
for (let i = 1; i < 5; ++i) {
await browser.tabs.create({ url: `${url}#${i}`, windowId: win.id });
await webdriver.navigate().to(`${url}#${i}`);
await browser.tabs.create({ url: server.url('/#' + i), windowId: win.id });
await webdriver.navigate().to(server.url('/#' + i));
}
tabs = await browser.tabs.query({ windowId: win.id });
tabs.sort((t1: any, t2: any) => t1.index - t2.index);
@ -219,7 +205,7 @@ describe("tab test", () => {
await eventually(async() => {
let current = await browser.tabs.query({ windowId: win.id });
assert.ok(current.length === tabs.length + 1);
assert.ok(current[current.length - 1].url === `view-source:${url}#0`);
assert.ok(current[current.length - 1].url === `view-source:${server.url('/#0')}`);
});
});
});