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. 37
      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. 45
      e2e/completion_buffers.test.ts
  12. 27
      e2e/completion_open.test.ts
  13. 36
      e2e/console.test.ts
  14. 165
      e2e/follow.test.ts
  15. 41
      e2e/follow_properties.test.ts
  16. 39
      e2e/mark.test.ts
  17. 100
      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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import * as http from 'http';
import Page from './lib/Page'; import Page from './lib/Page';
const newApp = () => { describe("blacklist test", () => {
let app = express(); let server = new TestServer().receiveContent('/*',
app.get('/*', (_req, res) => { `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
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;
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
}); await server.start();
after(async() => { let url = server.url('/a').replace('http://', '');
if (lanthan) {
await lanthan.quit();
}
http.close();
});
it('should disable add-on if the URL is in the blacklist', async () => {
await browser.storage.local.set({ await browser.storage.local.set({
settings: { settings: {
source: 'json', source: 'json',
@ -51,24 +31,32 @@ describe("navigate test", () => {
"keymaps": { "keymaps": {
"j": { "type": "scroll.vertically", "count": 1 } "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') await page.sendKeys('j')
// not works
let pageYOffset = await webdriver.executeScript(() => window.pageYOffset);
let scrollY = await page.getScrollY(); 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'); await page.sendKeys('j');
// works let scrollY = await page.getScrollY();
scrollY = await page.getScrollY();
assert.equal(scrollY, 64); assert.equal(scrollY, 64);
}); });
}); });

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

@ -1,53 +1,40 @@
import express from 'express';
import * as path from 'path'; import * as path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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', () => { describe('addbookmark command test', () => {
const port = 12321; let server = new TestServer().receiveContent('/happy', `
let http: http.Server; <!DOCTYPE html>
<html lang="en"><head><title>how to be happy</title></head></html">`,
);
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
}); });
beforeEach(async() => { 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() => { it('should add a bookmark from the current page', async() => {
@ -58,7 +45,7 @@ describe('addbookmark command test', () => {
await eventually(async() => { await eventually(async() => {
var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' }); var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' });
assert.equal(bookmarks.length, 1); 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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', () => { describe('bdelete/bdeletes command test', () => {
const port = 12321; let server = new TestServer().receiveContent('/*', 'ok');
let http: http.Server;
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -51,11 +35,11 @@ describe('bdelete/bdeletes command test', () => {
for (let tab of tabs.slice(1)) { for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id); 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.update(tabs[0].id, { url: server.url('/site1'), pinned: true });
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) await browser.tabs.create({ url: server.url('/site2'), pinned: true })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site3`, pinned: true }) await browser.tabs.create({ url: server.url('/site3'), pinned: true })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site4` }) await browser.tabs.create({ url: server.url('/site4'), })
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site5` }) await browser.tabs.create({ url: server.url('/site5'), })
await eventually(async() => { await eventually(async() => {
let handles = await webdriver.getAllWindowHandles(); let handles = await webdriver.getAllWindowHandles();
@ -72,10 +56,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => { await eventually(async() => {
let tabs = await browser.tabs.query({}); let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [ assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`, server.url('/site1'),
`http://127.0.0.1:${port}/site2`, server.url('/site2'),
`http://127.0.0.1:${port}/site3`, server.url('/site3'),
`http://127.0.0.1:${port}/site4`, server.url('/site4'),
]) ])
}); });
}); });
@ -121,10 +105,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => { await eventually(async() => {
let tabs = await browser.tabs.query({}); let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [ assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`, server.url('/site1'),
`http://127.0.0.1:${port}/site2`, server.url('/site2'),
`http://127.0.0.1:${port}/site3`, server.url('/site3'),
`http://127.0.0.1:${port}/site4`, server.url('/site4'),
]) ])
}); });
}); });
@ -137,10 +121,10 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => { await eventually(async() => {
let tabs = await browser.tabs.query({}); let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [ assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site2`, server.url('/site2'),
`http://127.0.0.1:${port}/site3`, server.url('/site3'),
`http://127.0.0.1:${port}/site4`, server.url('/site4'),
`http://127.0.0.1:${port}/site5`, server.url('/site5'),
]) ])
}); });
}); });
@ -153,9 +137,9 @@ describe('bdelete/bdeletes command test', () => {
await eventually(async() => { await eventually(async() => {
let tabs = await browser.tabs.query({}); let tabs = await browser.tabs.query({});
assert.deepEqual(tabs.map((t: any) => t.url), [ assert.deepEqual(tabs.map((t: any) => t.url), [
`http://127.0.0.1:${port}/site1`, server.url('/site1'),
`http://127.0.0.1:${port}/site2`, server.url('/site2'),
`http://127.0.0.1:${port}/site3`, server.url('/site3'),
]) ])
}); });
}); });

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

@ -1,37 +1,17 @@
import express from 'express';
import * as path from 'path'; import * as path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings'; import settings from './settings';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("open command test", () => {
const port = 12321; let server = new TestServer(12321)
let http: http.Server; .receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
@ -44,15 +24,16 @@ describe("open command test", () => {
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
}); });
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -60,7 +41,7 @@ describe("open command test", () => {
beforeEach(async() => { beforeEach(async() => {
await webdriver.switchTo().defaultContent(); 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() => { it('should open default search for keywords by open command ', async() => {
@ -70,7 +51,7 @@ describe("open command test", () => {
await eventually(async() => { await eventually(async() => {
let tabs = await browser.tabs.query({ active: true }); let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url); 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() => { await eventually(async() => {
let tabs = await browser.tabs.query({ active: true }) let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url); 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() => { await eventually(async() => {
let tabs = await browser.tabs.query({ active: true }) let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url); 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() => { await eventually(async() => {
let tabs = await browser.tabs.query({ active: true }) let tabs = await browser.tabs.query({ active: true })
let url = new URL(tabs[0].url); 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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', () => { describe('quit/quitall command test', () => {
const port = 12321; let server = new TestServer().receiveContent('/*', 'ok');
let http: http.Server;
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -51,9 +35,9 @@ describe('quit/quitall command test', () => {
for (let tab of tabs.slice(1)) { for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id); 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) { 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() => { await eventually(async() => {

@ -1,44 +1,23 @@
import express from 'express';
import * as path from 'path'; import * as path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings'; import settings from './settings';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("tabopen command test", () => {
const port = 12321; let server = new TestServer(12321)
let http: http.Server; .receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
let page: Page; let page: Page;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
@ -49,10 +28,12 @@ describe("tabopen command test", () => {
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
}); });
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -64,7 +45,7 @@ describe("tabopen command test", () => {
await browser.tabs.remove(tab.id); 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() => { 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({}); let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2); assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url); 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({}); let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2); assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url); 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({}); let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2); assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url); 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({}); let tabs = await browser.tabs.query({});
assert.equal(tabs.length, 2); assert.equal(tabs.length, 2);
let url = new URL(tabs[1].url); 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings'; import settings from './settings';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("winopen command test", () => {
const port = 12321; let server = new TestServer(12321)
let http: http.Server; .receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
let page: Page; let page: Page;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
@ -48,10 +27,12 @@ describe("winopen command test", () => {
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
}); });
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -63,7 +44,7 @@ describe("winopen command test", () => {
await browser.windows.remove(win.id); 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() => { 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 tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url); 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 tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url); 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 tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url); 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 tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url); 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import eventually from './eventually'; import eventually from './eventually';
import settings from './settings'; import settings from './settings';
@ -9,20 +7,7 @@ import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver'; import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("general completion test", () => {
const port = 12321;
let http: http.Server;
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
@ -35,7 +20,6 @@ describe("general completion test", () => {
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
@ -43,14 +27,13 @@ describe("general completion test", () => {
}); });
after(async() => { after(async() => {
http.close();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
}); });
beforeEach(async() => { 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() => { 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 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 settings from './settings';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; import Page from './lib/Page';
const newApp = () => {
let app = express();
app.get('/*', (req, res) => {
res.send(`<!DOCTYPEhtml>
<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", () => { describe("completion on buffer/bdelete/bdeletes", () => {
const port = 12321; let server = new TestServer().handle('/*', (req: Request, res: Response) => {
let http: http.Server; res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<title>title_${req.path.slice(1)}</title>
</head>
</html">`);
});
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
@ -39,15 +31,16 @@ describe("completion on buffer/bdelete/bdeletes", () => {
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
}); });
await server.start();
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
@ -59,10 +52,10 @@ describe("completion on buffer/bdelete/bdeletes", () => {
await browser.tabs.remove(tab.id); 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.update(tabs[0].id, { url: server.url('/site1'), pinned: true });
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) await browser.tabs.create({ url:server.url('/site2'), pinned: true })
for (let i = 3; i <= 5; ++i) { 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() => { await eventually(async() => {
@ -102,7 +95,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
assert.ok(items[1].text.startsWith('2:')); assert.ok(items[1].text.startsWith('2:'));
assert.ok(items[1].text.includes('title_site2')); 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import settings from './settings'; import settings from './settings';
import eventually from './eventually'; import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver'; import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("completion on open/tabopen/winopen commands", () => {
const port = 12321; let server = new TestServer().receiveContent('/*', 'ok');
let http: http.Server;
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let browser: any; let browser: any;
let page: Page; let page: Page;
before(async() => { before(async() => {
await server.start();
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser(); browser = lanthan.getWebExtBrowser();
http = newApp().listen(port);
await browser.storage.local.set({ await browser.storage.local.set({
settings, settings,
}); });
// Add item into hitories // Add item into hitories
await webdriver.navigate().to(`https://i-beam.org/404`); await webdriver.navigate().to(('https://i-beam.org/404'));
}); });
after(async() => { after(async() => {
http.close(); await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
}); });
beforeEach(async() => { 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() => { 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 path from 'path';
import * as assert from 'assert'; import * as assert from 'assert';
import * as http from 'http';
import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan'; import { Builder, Lanthan } from 'lanthan';
import { WebDriver, Key } from 'selenium-webdriver'; import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page'; 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", () => { describe("console test", () => {
const port = 12321; let server = new TestServer().receiveContent('/',
let http: http.Server; `<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html">`,
);
let lanthan: Lanthan; let lanthan: Lanthan;
let webdriver: WebDriver; let webdriver: WebDriver;
let page: Page; let page: Page;
before(async() => { before(async() => {
http = newApp().listen(port);
lanthan = await Builder lanthan = await Builder
.forBrowser('firefox') .forBrowser('firefox')
.spyAddon(path.join(__dirname, '..')) .spyAddon(path.join(__dirname, '..'))
.build(); .build();
webdriver = lanthan.getWebDriver(); webdriver = lanthan.getWebDriver();
await server.start();
}); });
after(async() => { after(async() => {
await server.stop();
if (lanthan) { if (lanthan) {
await lanthan.quit(); await lanthan.quit();
} }
if (http) {
http.close();
}
}); });
beforeEach(async() => { 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() => { it('open console with :', async() => {
@ -65,7 +49,7 @@ describe("console test", () => {
it('open console with open command and current URL by O', async() => { it('open console with open command and current URL by O', async() => {
await page.sendKeys(Key.SHIFT, 'o'); await page.sendKeys(Key.SHIFT, 'o');
let console = await page.getConsole(); 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() => { 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() => { it('open console with tabopen command and current URL by T', async() => {
await page.sendKeys(Key.SHIFT, 't'); await page.sendKeys(Key.SHIFT, 't');
let console = await page.getConsole(); 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() => { 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() => { it('open console with winopen command and current URL by W', async() => {
await page.sendKeys(Key.SHIFT, 'W'); await page.sendKeys(Key.SHIFT, 'W');
let console = await page.getConsole(); 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() => { it('open console with buffer command by b', async() => {

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

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

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

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

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

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

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

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