diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1294557..342842d 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -63,6 +63,13 @@ jobs:
- checkout
- setup_npm
- run: npm run lint
+ - run:
+ # NOTE: Karma loads ts-node automatically and treats karma.conf.js as a TypeScript.
+ # Karma does not starts by karma.conf.js transpile failure, and this hack removes
+ # ts-node module from the local before test.
+ # See: https://github.com/karma-runner/karma/issues/3329
+ name: Remove node-ts from node_modules
+ command: mv node_modules/ts-node node_modules/ts-node.orig
- run: npm test
- run: npm run package
diff --git a/e2e/blacklist.test.js b/e2e/blacklist.test.js
deleted file mode 100644
index fa8e8db..0000000
--- a/e2e/blacklist.test.js
+++ /dev/null
@@ -1,77 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const settings = require('./settings');
-
-const newApp = () => {
- let app = express();
- app.get('/*', (req, res) => {
- res.status(200).send(`
-
-
-`);
- });
- return app;
-};
-
-describe("navigate test", () => {
-
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- });
-
- after(async() => {
- if (firefox) {
- await firefox.close();
- }
- http.close();
- });
-
- it('should disable add-on if the URL is in the blacklist', async () => {
- await browser.storage.local.set({
- settings: {
- source: 'json',
- json: `{
- "keymaps": {
- "j": { "type": "scroll.vertically", "count": 1 }
- },
- "blacklist": [ "127.0.0.1:${port}/a" ]
- }`,
- },
- });
-
- await session.navigateTo(`http://127.0.0.1:${port}/a`);
-
- let body = await session.findElementByCSS('body');
- await body.sendKeys('j');
-
- // not works
- let pageYOffset = await session.executeScript(() => window.pageYOffset);
- assert.equal(pageYOffset, 0);
-
- await session.navigateTo(`http://127.0.0.1:${port}/ab`);
- body = await session.findElementByCSS('body');
- await body.sendKeys('j');
-
- // works
- pageYOffset = await session.executeScript(() => window.pageYOffset);
- assert.equal(pageYOffset, 64);
- });
-});
-
diff --git a/e2e/blacklist.test.ts b/e2e/blacklist.test.ts
new file mode 100644
index 0000000..8bf1bd8
--- /dev/null
+++ b/e2e/blacklist.test.ts
@@ -0,0 +1,62 @@
+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 Page from './lib/Page';
+
+describe("blacklist test", () => {
+ let server = new TestServer().receiveContent('/*',
+ ``,
+ );
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+ await server.start();
+
+ let url = server.url('/a').replace('http://', '');
+ await browser.storage.local.set({
+ settings: {
+ source: 'json',
+ json: `{
+ "keymaps": {
+ "j": { "type": "scroll.vertically", "count": 1 }
+ },
+ "blacklist": [ "${url}" ]
+ }`,
+ },
+ });
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ 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')
+
+ let scrollY = await page.getScrollY();
+ assert.strictEqual(scrollY, 0);
+ });
+
+ 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');
+
+ let scrollY = await page.getScrollY();
+ assert.strictEqual(scrollY, 64);
+ });
+});
diff --git a/e2e/clipboard.test.js b/e2e/clipboard.test.js
deleted file mode 100644
index 82e45fc..0000000
--- a/e2e/clipboard.test.js
+++ /dev/null
@@ -1,123 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const clipboard = require('./lib/clipboard');
-const settings = require('./settings');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/', (req, res) => {
- res.status(200).send(``);
- });
- return app;
-};
-
-describe("navigate test", () => {
-
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- });
- session = firefox.session;
- browser = firefox.browser;
-
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- if (firefox) {
- await firefox.close();
- }
- http.close();
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- for (let tab of tabs.slice(1)) {
- await browser.tabs.remove(tab.id);
- }
- })
-
- it('should copy current URL by y', async () => {
- await session.navigateTo(`http://127.0.0.1:${port}/#should_copy_url`);
- let body = await session.findElementByCSS('body');
-
- await body.sendKeys('y');
- await eventually(async() => {
- let data = await clipboard.read();
- assert.equal(data, `http://127.0.0.1:${port}/#should_copy_url`);
- });
- });
-
- it('should open an URL from clipboard by p', async () => {
- await session.navigateTo(`http://127.0.0.1:${port}/`);
- let body = await session.findElementByCSS('body');
-
- await clipboard.write(`http://127.0.0.1:${port}/#open_from_clipboard`);
- await body.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`);
- });
- });
-
- it('should open an URL from clipboard to new tab by P', async () => {
- await session.navigateTo(`http://127.0.0.1:${port}/`);
- let body = await session.findElementByCSS('body');
-
- await clipboard.write(`http://127.0.0.1:${port}/#open_to_new_tab`);
- await body.sendKeys(Key.Shift, 'p');
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => t.url), [
- `http://127.0.0.1:${port}/`,
- `http://127.0.0.1:${port}/#open_to_new_tab`,
- ]);
- });
- });
-
- it('should open search result with keywords in clipboard by p', async () => {
- await session.navigateTo(`http://127.0.0.1:${port}/`);
- let body = await session.findElementByCSS('body');
-
- await clipboard.write(`an apple`);
- await body.sendKeys('p');
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs[0].url, `http://127.0.0.1:${port}/google?q=an%20apple`);
- });
- });
-
- it('should open search result with keywords in clipboard to new tabby P', async () => {
- await session.navigateTo(`http://127.0.0.1:${port}/`);
- let body = await session.findElementByCSS('body');
-
- await clipboard.write(`an apple`);
- await body.sendKeys(Key.Shift, 'p');
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => t.url), [
- `http://127.0.0.1:${port}/`,
- `http://127.0.0.1:${port}/google?q=an%20apple`,
- ]);
- });
- });
-});
diff --git a/e2e/clipboard.test.ts b/e2e/clipboard.test.ts
new file mode 100644
index 0000000..2b71ade
--- /dev/null
+++ b/e2e/clipboard.test.ts
@@ -0,0 +1,110 @@
+import * as assert from 'assert';
+import * as path from 'path';
+
+import TestServer from './lib/TestServer';
+import eventually from './eventually';
+import * as clipboard from './lib/clipboard';
+import settings from './settings';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver, Key } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("clipboard test", () => {
+ let server = new TestServer(12321).receiveContent('/happy', 'ok');
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+ })
+
+ it('should copy current URL by y', async () => {
+ let page = await Page.navigateTo(webdriver, server.url('/#should_copy_url'));
+ await page.sendKeys('y');
+
+ await eventually(async() => {
+ let data = await clipboard.read();
+ assert.strictEqual(data, server.url('/#should_copy_url'));
+ });
+ });
+
+ it('should open an URL from clipboard by p', async () => {
+ await clipboard.write(server.url('/#open_from_clipboard'));
+
+ let page = await Page.navigateTo(webdriver, server.url());
+ await page.sendKeys('p');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].url, server.url('/#open_from_clipboard'));
+ });
+ });
+
+ it('should open an URL from clipboard to new tab by P', async () => {
+ await clipboard.write(server.url('/#open_to_new_tab'));
+
+ let page = await Page.navigateTo(webdriver, server.url());
+ await page.sendKeys(Key.SHIFT, 'p');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url(),
+ server.url('/#open_to_new_tab'),
+ ]);
+ });
+ });
+
+ it('should open search result with keywords in clipboard by p', async () => {
+ await clipboard.write(`an apple`);
+
+ 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.strictEqual(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, server.url());
+ await page.sendKeys(Key.SHIFT, 'p');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url(),
+ server.url('/google?q=an%20apple'),
+ ]);
+ });
+ });
+});
diff --git a/e2e/command_addbookmark.test.js b/e2e/command_addbookmark.test.js
deleted file mode 100644
index e8995bc..0000000
--- a/e2e/command_addbookmark.test.js
+++ /dev/null
@@ -1,67 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/happy', (req, res) => {
- res.send(`
-
-
- how to be happy
-
-`);
- });
- return app;
-};
-
-describe('addbookmark command test', () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`http://127.0.0.1:${port}/happy`);
- });
-
- it('should add a bookmark from the current page', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('addbookmark how to be happy', Key.Enter);
-
- 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`);
- });
- });
-});
diff --git a/e2e/command_addbookmark.test.ts b/e2e/command_addbookmark.test.ts
new file mode 100644
index 0000000..bcc75ac
--- /dev/null
+++ b/e2e/command_addbookmark.test.ts
@@ -0,0 +1,51 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import TestServer from './lib/TestServer';
+import eventually from './eventually';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe('addbookmark command test', () => {
+ let server = new TestServer().receiveContent('/happy', `
+
+ how to be happy`,
+ );
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ 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();
+ }
+ });
+
+ beforeEach(async() => {
+ await webdriver.navigate().to(server.url('/happy'));
+ });
+
+ it('should add a bookmark from the current page', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('addbookmark how to be happy');
+
+ await eventually(async() => {
+ var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' });
+ assert.strictEqual(bookmarks.length, 1);
+ assert.strictEqual(bookmarks[0].url, server.url('/happy'));
+ });
+ });
+});
diff --git a/e2e/command_bdelete.test.js b/e2e/command_bdelete.test.js
deleted file mode 100644
index 1f416db..0000000
--- a/e2e/command_bdelete.test.js
+++ /dev/null
@@ -1,203 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/*', (req, res) => {
- res.send(`
-
-
- my_${req.path.slice(1)}
-
- ${req.path}
-`);
- });
- return app;
-};
-
-describe('bdelete/bdeletes command test', () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- 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 eventually(async() => {
- let handles = await session.getWindowHandles();
- assert.equal(handles.length, 5);
- await session.switchToWindow(handles[2]);
- await session.findElementByCSS('iframe');
- });
-
- await new Promise((resolve) => setTimeout(resolve, 100));
- });
-
- it('should delete an unpinned tab by bdelete command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete site5', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => 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`,
- ])
- });
- });
-
- it('should not delete an pinned tab by bdelete command by bdelete command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete site1', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 5);
- });
- });
-
- it('should show an error when no tabs are matched by bdelete command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete xyz', Key.Enter);
-
- await eventually(async() => {
- let p = await session.findElementByCSS('.vimvixen-console-error');
- let text = await p.getText();
- assert.equal(text, 'No matching buffer for xyz');
- });
- });
-
- it('should show an error when more than one tabs are matched by bdelete command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete site', Key.Enter);
-
- await eventually(async() => {
- let p = await session.findElementByCSS('.vimvixen-console-error');
- let text = await p.getText();
- assert.equal(text, 'More than one match for site');
- });
- });
-
- it('should delete an unpinned tab by bdelete! command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete! site5', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => 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`,
- ])
- });
- });
-
- it('should delete an pinned tab by bdelete! command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdelete! site1', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => 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`,
- ])
- });
- });
-
- it('should delete unpinned tabs by bdeletes command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdeletes site', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.deepEqual(tabs.map(t => t.url), [
- `http://127.0.0.1:${port}/site1`,
- `http://127.0.0.1:${port}/site2`,
- `http://127.0.0.1:${port}/site3`,
- ])
- });
- });
-
- it('should delete both pinned and unpinned tabs by bdeletes! command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('bdeletes! site', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 1);
- });
- });
-});
diff --git a/e2e/command_bdelete.test.ts b/e2e/command_bdelete.test.ts
new file mode 100644
index 0000000..c96034d
--- /dev/null
+++ b/e2e/command_bdelete.test.ts
@@ -0,0 +1,157 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import TestServer from './lib/TestServer';
+import eventually from './eventually';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe('bdelete/bdeletes command test', () => {
+ let server = new TestServer().receiveContent('/*', 'ok');
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ 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();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+ 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();
+ assert.strictEqual(handles.length, 5);
+ await webdriver.switchTo().window(handles[2]);
+ });
+ });
+
+ it('should delete an unpinned tab by bdelete command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete site5');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url('/site1'),
+ server.url('/site2'),
+ server.url('/site3'),
+ server.url('/site4'),
+ ])
+ });
+ });
+
+ it('should not delete an pinned tab by bdelete command by bdelete command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete site1');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 5);
+ });
+ });
+
+ it('should show an error when no tabs are matched by bdelete command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete xyz');
+
+ await eventually(async() => {
+ let text = await console.getErrorMessage();
+ assert.strictEqual(text, 'No matching buffer for xyz');
+ });
+ });
+
+ it('should show an error when more than one tabs are matched by bdelete command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete site');
+
+ await eventually(async() => {
+ let text = await console.getErrorMessage();
+ assert.strictEqual(text, 'More than one match for site');
+ });
+ });
+
+ it('should delete an unpinned tab by bdelete! command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete! site5');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url('/site1'),
+ server.url('/site2'),
+ server.url('/site3'),
+ server.url('/site4'),
+ ])
+ });
+ });
+
+ it('should delete an pinned tab by bdelete! command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdelete! site1');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url('/site2'),
+ server.url('/site3'),
+ server.url('/site4'),
+ server.url('/site5'),
+ ])
+ });
+ });
+
+ it('should delete unpinned tabs by bdeletes command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdeletes site');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.deepStrictEqual(tabs.map((t: any) => t.url), [
+ server.url('/site1'),
+ server.url('/site2'),
+ server.url('/site3'),
+ ])
+ });
+ });
+
+ it('should delete both pinned and unpinned tabs by bdeletes! command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('bdeletes! site');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 1);
+ });
+ });
+});
diff --git a/e2e/command_buffer.test.js b/e2e/command_buffer.test.js
deleted file mode 100644
index bf94428..0000000
--- a/e2e/command_buffer.test.js
+++ /dev/null
@@ -1,202 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/*', (req, res) => {
- res.send(`
-
-
- my_${req.path.slice(1)}
-
- ${req.path}
-`);
- });
- return app;
-};
-
-describe('buffer command test', () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- 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` });
- for (let i = 2; i <= 5; ++i) {
- await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`})
- }
-
- await eventually(async() => {
- let handles = await session.getWindowHandles();
- assert.equal(handles.length, 5);
- await session.switchToWindow(handles[2]);
- await session.findElementByCSS('iframe');
- });
-
- await new Promise((resolve) => setTimeout(resolve, 100));
- });
-
- it('should do nothing by buffer command with no parameters', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 2);
- });
- });
-
- it('should select a tab by buffer command with a number', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 2);
- });
- });
-
- it('should should an out of range error by buffer commands', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer 0', Key.Enter);
-
- await eventually(async() => {
- let p = await session.findElementByCSS('.vimvixen-console-error');
- let text = await p.getText();
- assert.equal(text, 'tab 0 does not exist');
- });
-
- await session.switchToParentFrame();
- body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- input = await session.findElementByCSS('input');
- await input.sendKeys('buffer 9', Key.Enter);
-
- await eventually(async() => {
- let p = await session.findElementByCSS('.vimvixen-console-error');
- let text = await p.getText();
- assert.equal(text, 'tab 9 does not exist');
- });
- });
-
- it('should select a tab by buffer command with a title', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer my_site1', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 0);
- });
- });
-
- it('should select a tab by buffer command with an URL', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer /site1', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 0);
- });
- });
-
- it('should select tabs rotately', async() => {
- let handles = await session.getWindowHandles();
- await session.switchToWindow(handles[4]);
-
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer site', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 0);
- });
- });
-
- it('should do nothing by ":buffer %"', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer %', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 2);
- });
- });
-
- it('should selects last selected tab by ":buffer #"', async() => {
- let handles = await session.getWindowHandles();
- await session.switchToWindow(handles[1]);
-
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('buffer #', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true });
- assert.equal(tabs[0].index, 2);
- });
- });
-});
diff --git a/e2e/command_buffer.test.ts b/e2e/command_buffer.test.ts
new file mode 100644
index 0000000..0036839
--- /dev/null
+++ b/e2e/command_buffer.test.ts
@@ -0,0 +1,162 @@
+import * as path from 'path';
+import * as assert from 'assert';
+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';
+
+describe('buffer command test', () => {
+ let server = new TestServer().handle('/*', (req: Request, res: Response) => {
+ res.send(`
+
+
+
+ my_${req.path.slice(1)}
+
+ `);
+ });
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ 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();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+ await browser.tabs.update(tabs[0].id, { url: server.url('/site1') });
+ for (let i = 2; i <= 5; ++i) {
+ await browser.tabs.create({ url: server.url('/site' + i) });
+ }
+
+ await eventually(async() => {
+ let handles = await webdriver.getAllWindowHandles();
+ assert.strictEqual(handles.length, 5);
+ await webdriver.switchTo().window(handles[2]);
+ });
+ });
+
+ it('should do nothing by buffer command with no parameters', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 2);
+ });
+ });
+
+ it('should select a tab by buffer command with a number', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer 1');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 0);
+ });
+ });
+
+ it('should should an out of range error by buffer commands', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer 0');
+
+ await eventually(async() => {
+ let text = await console.getErrorMessage();
+ assert.strictEqual(text, 'tab 0 does not exist');
+ });
+
+ await (webdriver.switchTo() as any).parentFrame();
+
+ console = await page.showConsole();
+ await console.execCommand('buffer 9');
+
+ await eventually(async() => {
+ let text = await console.getErrorMessage();
+ assert.strictEqual(text, 'tab 9 does not exist');
+ });
+ });
+
+ it('should select a tab by buffer command with a title', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer my_site1');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 0);
+ });
+ });
+
+ it('should select a tab by buffer command with an URL', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer /site1');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 0);
+ });
+ });
+
+ it('should select tabs rotately', async() => {
+ let handles = await webdriver.getAllWindowHandles();
+ await webdriver.switchTo().window(handles[4]);
+
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer site');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 0);
+ });
+ });
+
+ it('should do nothing by ":buffer %"', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer %');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 2);
+ });
+ });
+
+ it('should selects last selected tab by ":buffer #"', async() => {
+ let handles = await webdriver.getAllWindowHandles();
+ await webdriver.switchTo().window(handles[1]);
+
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('buffer #');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].index, 2);
+ });
+ });
+});
diff --git a/e2e/command_open.test.js b/e2e/command_open.test.js
deleted file mode 100644
index 0d41f96..0000000
--- a/e2e/command_open.test.js
+++ /dev/null
@@ -1,149 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
-
- let app = express();
- for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
- app.get('/' + name, (req, res) => {
- res.send(`
-
- ${name.charAt(0).toUpperCase() + name.slice(1)}
-`);
- });
- }
- app.get('/', (req, res) => {
- res.send(`
-
- home
-`);
- });
- return app;
-};
-
-describe("open command test", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- http = newApp().listen(port);
-
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- })
-
- it('should open default search for keywords by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open an apple', Key.Enter);
-
- 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`)
- });
- });
-
- it('should open certain search page for keywords by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open yahoo an apple', Key.Enter);
-
- 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`)
- });
- });
-
- it('should open default engine with empty keywords by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open', Key.Enter);
-
- 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=`)
- });
- });
-
- it('should open certain search page for empty keywords by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open yahoo', Key.Enter);
-
- 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=`)
- });
- });
-
- it('should open a site with domain by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true })
- let url = new URL(tabs[0].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-
- it('should open a site with URL by open command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('open https://i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({ active: true })
- let url = new URL(tabs[0].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-});
diff --git a/e2e/command_open.test.ts b/e2e/command_open.test.ts
new file mode 100644
index 0000000..6fb2645
--- /dev/null
+++ b/e2e/command_open.test.ts
@@ -0,0 +1,112 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+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';
+
+describe("open command test", () => {
+ 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() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ await webdriver.switchTo().defaultContent();
+ page = await Page.navigateTo(webdriver, server.url());
+ })
+
+ it('should open default search for keywords by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open an apple');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/google?q=an%20apple'))
+ });
+ });
+
+ it('should open certain search page for keywords by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open yahoo an apple');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true })
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple'))
+ });
+ });
+
+ it('should open default engine with empty keywords by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true })
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/google?q='))
+ });
+ });
+
+ it('should open certain search page for empty keywords by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open yahoo');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true })
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q='))
+ });
+ });
+
+ it('should open a site with domain by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open example.com');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true })
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, 'http://example.com/')
+ });
+ });
+
+ it('should open a site with URL by open command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('open https://example.com/');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true })
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, 'https://example.com/')
+ });
+ });
+});
diff --git a/e2e/command_quit.test.js b/e2e/command_quit.test.js
deleted file mode 100644
index ee4c2d8..0000000
--- a/e2e/command_quit.test.js
+++ /dev/null
@@ -1,125 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/*', (req, res) => {
- res.send(`
-
-
- my_${req.path.slice(1)}
-
- ${req.path}
-`);
- });
- return app;
-};
-
-describe('quit/quitall command test', () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- 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` });
- for (let i = 2; i <= 5; ++i) {
- await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`})
- }
-
- await eventually(async() => {
- let handles = await session.getWindowHandles();
- assert.equal(handles.length, 5);
- await session.switchToWindow(handles[2]);
- await session.findElementByCSS('iframe');
- });
-
- await new Promise((resolve) => setTimeout(resolve, 100));
- });
-
- it('should current tab by q command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('q', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 4)
- });
- });
-
- it('should current tab by quit command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('quit', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 4)
- });
- });
-
- it('should current tab by qa command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('qa', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 1)
- });
- });
-
- it('should current tab by quitall command', async() => {
- let body = await session.findElementByCSS('body');
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- await input.sendKeys('quitall', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 1)
- });
- });
-});
diff --git a/e2e/command_quit.test.ts b/e2e/command_quit.test.ts
new file mode 100644
index 0000000..239d880
--- /dev/null
+++ b/e2e/command_quit.test.ts
@@ -0,0 +1,93 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import TestServer from './lib/TestServer';
+import eventually from './eventually';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe('quit/quitall command test', () => {
+ let server = new TestServer().receiveContent('/*', 'ok');
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+
+ before(async() => {
+ 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();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+ await browser.tabs.update(tabs[0].id, { url: server.url('/site1') });
+ for (let i = 2; i <= 5; ++i) {
+ await browser.tabs.create({ url: server.url('/site' + i) })
+ }
+
+ await eventually(async() => {
+ let handles = await webdriver.getAllWindowHandles();
+ assert.strictEqual(handles.length, 5);
+ await webdriver.switchTo().window(handles[2]);
+ });
+ });
+
+ it('should current tab by q command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('q');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 4)
+ });
+ });
+
+ it('should current tab by quit command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('quit');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 4)
+ });
+ });
+
+ it('should current tab by qa command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('qa');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 1)
+ });
+ });
+
+ it('should current tab by quitall command', async() => {
+ let page = await Page.currentContext(webdriver);
+ let console = await page.showConsole();
+ await console.execCommand('quitall');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 1)
+ });
+ });
+});
diff --git a/e2e/command_tabopen.test.js b/e2e/command_tabopen.test.js
deleted file mode 100644
index 9c5cf3a..0000000
--- a/e2e/command_tabopen.test.js
+++ /dev/null
@@ -1,160 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
-
- let app = express();
- for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
- app.get('/' + name, (req, res) => {
- res.send(`
-
- ${name.charAt(0).toUpperCase() + name.slice(1)}
-`);
- });
- }
- app.get('/', (req, res) => {
- res.send(`
-
- home
-`);
- });
- return app;
-};
-
-describe("tabopen command test", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- for (let tab of tabs.slice(1)) {
- await browser.tabs.remove(tab.id);
- }
-
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- })
-
- it('should open default search for keywords by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen an apple', Key.Enter);
-
- await eventually(async() => {
- 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`)
- });
- });
-
- it('should open certain search page for keywords by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen yahoo an apple', Key.Enter);
-
- await eventually(async() => {
- 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`)
- });
- });
-
- it('should open default engine with empty keywords by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen', Key.Enter);
-
- await eventually(async() => {
- 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=`)
- });
- });
-
- it('should open certain search page for empty keywords by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen yahoo', Key.Enter);
-
- await eventually(async() => {
- 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=`)
- });
- });
-
- it('should open a site with domain by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 2);
- let url = new URL(tabs[1].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-
- it('should open a site with URL by tabopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('tabopen https://i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let tabs = await browser.tabs.query({});
- assert.equal(tabs.length, 2);
- let url = new URL(tabs[1].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-});
diff --git a/e2e/command_tabopen.test.ts b/e2e/command_tabopen.test.ts
new file mode 100644
index 0000000..9d3da9a
--- /dev/null
+++ b/e2e/command_tabopen.test.ts
@@ -0,0 +1,122 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+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';
+
+describe("tabopen command test", () => {
+ 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() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+
+ page = await Page.navigateTo(webdriver, server.url());
+ })
+
+ it('should open default search for keywords by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen an apple');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, server.url('/google?q=an%20apple') )
+ });
+ });
+
+ it('should open certain search page for keywords by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen yahoo an apple');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple'))
+ });
+ });
+
+ it('should open default engine with empty keywords by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, server.url('/google?q='))
+ });
+ });
+
+ it('should open certain search page for empty keywords by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen yahoo');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q='))
+ });
+ });
+
+ it('should open a site with domain by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen example.com');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, 'http://example.com/')
+ });
+ });
+
+ it('should open a site with URL by tabopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('tabopen https://example.com/');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({});
+ assert.strictEqual(tabs.length, 2);
+ let url = new URL(tabs[1].url);
+ assert.strictEqual(url.href, 'https://example.com/')
+ });
+ });
+});
diff --git a/e2e/command_winopen.test.js b/e2e/command_winopen.test.js
deleted file mode 100644
index 536d759..0000000
--- a/e2e/command_winopen.test.js
+++ /dev/null
@@ -1,172 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
-
- let app = express();
- for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
- app.get('/' + name, (req, res) => {
- res.send(`
-
- ${name.charAt(0).toUpperCase() + name.slice(1)}
-`);
- });
- }
- app.get('/', (req, res) => {
- res.send(`
-
- home
-`);
- });
- return app;
-};
-
-describe("winopen command test", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- http = newApp().listen(port);
-
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let wins = await browser.windows.getAll();
- for (let win of wins.slice(1)) {
- await browser.windows.remove(win.id);
- }
-
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- })
-
- it('should open default search for keywords by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen an apple', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- 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`)
- });
- });
-
- it('should open certain search page for keywords by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen yahoo an apple', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- 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`)
- });
- });
-
- it('should open default engine with empty keywords by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- 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=`)
- });
- });
-
- it('should open certain search page for empty keywords by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen yahoo', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- 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=`)
- });
- });
-
- it('should open a site with domain by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- let tabs = await browser.tabs.query({ windowId: wins[1].id });
- let url = new URL(tabs[0].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-
- it('should open a site with URL by winopen command ', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let input = await session.findElementByCSS('input');
- input.sendKeys('winopen https://i-beam.org', Key.Enter);
-
- await eventually(async() => {
- let wins = await browser.windows.getAll();
- assert.equal(wins.length, 2);
-
- let tabs = await browser.tabs.query({ windowId: wins[1].id });
- let url = new URL(tabs[0].url);
- assert.equal(url.href, 'https://i-beam.org/')
- });
- });
-});
diff --git a/e2e/command_winopen.test.ts b/e2e/command_winopen.test.ts
new file mode 100644
index 0000000..95a0b6a
--- /dev/null
+++ b/e2e/command_winopen.test.ts
@@ -0,0 +1,133 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+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';
+
+describe("winopen command test", () => {
+ 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() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+ await browser.storage.local.set({
+ settings,
+ });
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ let wins = await browser.windows.getAll();
+ for (let win of wins.slice(1)) {
+ await browser.windows.remove(win.id);
+ }
+
+ page = await Page.navigateTo(webdriver, server.url());
+ })
+
+ it('should open default search for keywords by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen an apple');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/google?q=an%20apple'))
+ });
+ });
+
+ it('should open certain search page for keywords by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen yahoo an apple');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple'))
+ });
+ });
+
+ it('should open default engine with empty keywords by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/google?q='))
+ });
+ });
+
+ it('should open certain search page for empty keywords by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen yahoo');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, server.url('/yahoo?q='))
+ });
+ });
+
+ it('should open a site with domain by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen example.com');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, 'http://example.com/')
+ });
+ });
+
+ it('should open a site with URL by winopen command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('winopen https://example.com/');
+
+ await eventually(async() => {
+ let wins = await browser.windows.getAll();
+ assert.strictEqual(wins.length, 2);
+
+ let tabs = await browser.tabs.query({ windowId: wins[1].id });
+ let url = new URL(tabs[0].url);
+ assert.strictEqual(url.href, 'https://example.com/')
+ });
+ });
+});
diff --git a/e2e/completion.test.js b/e2e/completion.test.js
deleted file mode 100644
index 5d910c6..0000000
--- a/e2e/completion.test.js
+++ /dev/null
@@ -1,136 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-const Console = require('./lib/Console');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/', (req, res) => {
- res.send(`
-
- ok
-`);
- });
- return app;
-};
-
-describe("general completion test", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- http = newApp().listen(port);
-
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- });
-
- it('should all commands on empty line', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 10);
- assert.deepEqual(items[0], { type: 'title', text: 'Console Command' });
- assert(items[1].text.startsWith('set'))
- assert(items[2].text.startsWith('open'))
- assert(items[3].text.startsWith('tabopen'))
- });
- });
-
- it('should only commands filtered by prefix', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('b');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 4);
- assert.deepEqual(items[0], { type: 'title', text: 'Console Command' });
- assert(items[1].text.startsWith('buffer'))
- assert(items[2].text.startsWith('bdelete'))
- assert(items[3].text.startsWith('bdeletes'))
- });
- });
-
- it('selects completion items by / keys', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('b');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 4);
- });
-
- await c.sendKeys(Key.Tab);
- await eventually(async() => {
- let items = await c.getCompletions();
- assert(items[1].highlight)
-
- let v = await c.currentValue();
- assert.equal(v, 'buffer');
- });
-
- await c.sendKeys(Key.Tab, Key.Tab);
- await eventually(async() => {
- let items = await c.getCompletions();
- assert(items[3].highlight)
-
- let v = await c.currentValue();
- assert.equal(v, 'bdeletes');
- });
-
- await c.sendKeys(Key.Tab);
- await eventually(async() => {
- let v = await c.currentValue();
- assert.equal(v, 'b');
- });
-
- await c.sendKeys(Key.Shift, Key.Tab);
- await eventually(async() => {
- let items = await c.getCompletions();
- assert(items[3].highlight)
-
- let v = await c.currentValue();
- assert.equal(v, 'bdeletes');
- });
- });
-});
diff --git a/e2e/completion.test.ts b/e2e/completion.test.ts
new file mode 100644
index 0000000..28c1913
--- /dev/null
+++ b/e2e/completion.test.ts
@@ -0,0 +1,100 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import eventually from './eventually';
+import settings from './settings';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver, Key } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("general completion test", () => {
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+ let page: Page;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+ });
+
+ after(async() => {
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, 'about:blank');
+ });
+
+ it('should all commands on empty line', async() => {
+ let console = await page.showConsole();
+
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 10);
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' });
+ assert.ok(items[1].text.startsWith('set'))
+ assert.ok(items[2].text.startsWith('open'))
+ assert.ok(items[3].text.startsWith('tabopen'))
+ });
+
+ it('should only commands filtered by prefix', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('b');
+
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 4);
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' });
+ assert.ok(items[1].text.startsWith('buffer'))
+ assert.ok(items[2].text.startsWith('bdelete'))
+ assert.ok(items[3].text.startsWith('bdeletes'))
+ });
+
+ // > byffer
+ // > bdelete
+ // > bdeletes
+ // : b
+ it('selects completion items by / keys', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('b');
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 4);
+ });
+
+ await console.sendKeys(Key.TAB);
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.ok(items[1].highlight)
+ assert.strictEqual(await console.currentValue(), 'buffer');
+ });
+
+ await console.sendKeys(Key.TAB, Key.TAB);
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.ok(items[3].highlight)
+ assert.strictEqual(await console.currentValue(), 'bdeletes');
+ });
+
+ await console.sendKeys(Key.TAB);
+ await eventually(async() => {
+ assert.strictEqual(await console.currentValue(), 'b');
+ });
+
+ await console.sendKeys(Key.SHIFT, Key.TAB);
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.ok(items[3].highlight)
+ assert.strictEqual(await console.currentValue(), 'bdeletes');
+ });
+ });
+});
diff --git a/e2e/completion_buffers.test.js b/e2e/completion_buffers.test.js
deleted file mode 100644
index de26747..0000000
--- a/e2e/completion_buffers.test.js
+++ /dev/null
@@ -1,214 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-const Console = require('./lib/Console');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
-
- let app = express();
- app.get('/*', (req, res) => {
- res.send(`
-
-
- title_${req.path.slice(1)}
-
- home
-`);
- });
- return app;
-};
-
-describe("completion on buffer/bdelete/bdeletes", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- http = newApp().listen(port);
-
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- let tabs = await browser.tabs.query({});
- 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 })
- for (let i = 3; i <= 5; ++i) {
- await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}` })
- }
-
- await eventually(async() => {
- let handles = await session.getWindowHandles();
- assert.equal(handles.length, 5);
- await session.switchToWindow(handles[2]);
- await session.findElementByCSS('iframe');
- });
- body = await session.findElementByCSS('body');
-
- await new Promise((resolve) => setTimeout(resolve, 100));
- });
-
- it('should all tabs by "buffer" command with empty params', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('buffer ');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 6);
- assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
- assert(items[1].text.startsWith('1:'));
- assert(items[2].text.startsWith('2:'));
- assert(items[3].text.startsWith('3:'));
- assert(items[4].text.startsWith('4:'));
- assert(items[5].text.startsWith('5:'));
-
- assert(items[3].text.includes('%'));
- assert(items[5].text.includes('#'));
- });
- })
-
- it('should filter items with URLs by keywords on "buffer" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('buffer title_site2');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
- assert(items[1].text.startsWith('2:'));
- assert(items[1].text.includes('title_site2'));
- assert(items[1].text.includes(`http://127.0.0.1:${port}/site2`));
- });
- })
-
- it('should filter items with titles by keywords on "buffer" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('buffer /site2');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
- assert(items[1].text.startsWith('2:'));
- });
- })
-
- it('should show one item by number on "buffer" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('buffer 2');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 2);
- assert.deepEqual(items[0], { type: 'title', text: 'Buffers' });
- assert(items[1].text.startsWith('2:'));
- });
- })
-
- it('should show unpinned tabs "bdelete" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('bdelete site');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 4);
- assert(items[1].text.includes('site3'));
- assert(items[2].text.includes('site4'));
- assert(items[3].text.includes('site5'));
- });
- })
-
- it('should show unpinned tabs "bdeletes" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('bdelete site');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 4);
- assert(items[1].text.includes('site3'));
- assert(items[2].text.includes('site4'));
- assert(items[3].text.includes('site5'));
- });
- })
-
- it('should show both pinned and unpinned tabs "bdelete!" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('bdelete! site');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 6);
- assert(items[1].text.includes('site1'));
- assert(items[2].text.includes('site2'));
- assert(items[3].text.includes('site3'));
- assert(items[4].text.includes('site4'));
- assert(items[5].text.includes('site5'));
- });
- })
-
- it('should show both pinned and unpinned tabs "bdeletes!" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('bdeletes! site');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 6);
- assert(items[1].text.includes('site1'));
- assert(items[2].text.includes('site2'));
- assert(items[3].text.includes('site3'));
- assert(items[4].text.includes('site4'));
- assert(items[5].text.includes('site5'));
- });
- })
-});
diff --git a/e2e/completion_buffers.test.ts b/e2e/completion_buffers.test.ts
new file mode 100644
index 0000000..b2d4201
--- /dev/null
+++ b/e2e/completion_buffers.test.ts
@@ -0,0 +1,180 @@
+import * as assert from 'assert';
+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';
+
+describe("completion on buffer/bdelete/bdeletes", () => {
+ let server = new TestServer().handle('/*', (req: Request, res: Response) => {
+ res.send(`
+
+
+
+ title_${req.path.slice(1)}
+
+ `);
+ });
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+ let page: Page;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ let tabs = await browser.tabs.query({});
+ for (let tab of tabs.slice(1)) {
+ await browser.tabs.remove(tab.id);
+ }
+
+ 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: server.url('/site' + i) });
+ }
+
+ await eventually(async() => {
+ let handles = await webdriver.getAllWindowHandles();
+ assert.strictEqual(handles.length, 5);
+ await webdriver.switchTo().window(handles[2]);
+ });
+
+ page = await Page.currentContext(webdriver);
+ });
+
+ it('should all tabs by "buffer" command with empty params', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('buffer ');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 6);
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' });
+ assert.ok(items[1].text.startsWith('1:'));
+ assert.ok(items[2].text.startsWith('2:'));
+ assert.ok(items[3].text.startsWith('3:'));
+ assert.ok(items[4].text.startsWith('4:'));
+ assert.ok(items[5].text.startsWith('5:'));
+
+ assert.ok(items[3].text.includes('%'));
+ assert.ok(items[5].text.includes('#'));
+ });
+ })
+
+ it('should filter items with URLs by keywords on "buffer" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('buffer title_site2');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.deepStrictEqual(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(server.url('/site2')));
+ });
+ })
+
+ it('should filter items with titles by keywords on "buffer" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('buffer /site2');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' });
+ assert.ok(items[1].text.startsWith('2:'));
+ });
+ })
+
+ it('should show one item by number on "buffer" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('buffer 2');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 2);
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' });
+ assert.ok(items[1].text.startsWith('2:'));
+ });
+ })
+
+ it('should show unpinned tabs "bdelete" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('bdelete site');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 4);
+ assert.ok(items[1].text.includes('site3'));
+ assert.ok(items[2].text.includes('site4'));
+ assert.ok(items[3].text.includes('site5'));
+ });
+ })
+
+ it('should show unpinned tabs "bdeletes" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('bdeletes site');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 4);
+ assert.ok(items[1].text.includes('site3'));
+ assert.ok(items[2].text.includes('site4'));
+ assert.ok(items[3].text.includes('site5'));
+ });
+ })
+
+ it('should show both pinned and unpinned tabs "bdelete!" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('bdelete! site');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 6);
+ assert.ok(items[1].text.includes('site1'));
+ assert.ok(items[2].text.includes('site2'));
+ assert.ok(items[3].text.includes('site3'));
+ assert.ok(items[4].text.includes('site4'));
+ assert.ok(items[5].text.includes('site5'));
+ });
+ })
+
+ it('should show both pinned and unpinned tabs "bdeletes!" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('bdeletes! site');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 6);
+ assert.ok(items[1].text.includes('site1'));
+ assert.ok(items[2].text.includes('site2'));
+ assert.ok(items[3].text.includes('site3'));
+ assert.ok(items[4].text.includes('site4'));
+ assert.ok(items[5].text.includes('site5'));
+ });
+ })
+});
diff --git a/e2e/completion_open.test.js b/e2e/completion_open.test.js
deleted file mode 100644
index 5828768..0000000
--- a/e2e/completion_open.test.js
+++ /dev/null
@@ -1,255 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-const Console = require('./lib/Console');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
-
- let app = express();
- app.get('/', (req, res) => {
- res.send(`
-
- ok
-`);
- });
- return app;
-};
-
-describe("completion on open/tabopen/winopen commands", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
- http = newApp().listen(port);
-
- await browser.storage.local.set({
- settings,
- });
-
- // Add item into hitories
- await session.navigateTo(`https://i-beam.org/404`);
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- });
-
- it('should show completions from search engines, bookmarks, and histories by "open" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('open ');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- assert(completions.find(x => x.type === 'title' && x.text === 'Search Engines'));
- assert(completions.find(x => x.type === 'title' && x.text === 'Bookmarks'));
- assert(completions.find(x => x.type === 'title' && x.text === 'History'));
- });
- });
-
- it('should filter items with URLs by keywords on "open" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('open https://');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let items = completions.filter(x => x.type === 'item').map(x => x.text);
- assert(items.every(x => x.includes('https://')));
- });
- })
-
- it('should filter items with titles by keywords on "open" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('open getting');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let items = completions.filter(x => x.type === 'item').map(x => x.text);
- assert(items.every(x => x.toLowerCase().includes('getting')));
- });
- })
-
- it('should filter items with titles by keywords on "tabopen" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('tabopen https://');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let items = completions.filter(x => x.type === 'item').map(x => x.text);
- assert(items.every(x => x.includes('https://')));
- });
- })
-
- it('should filter items with titles by keywords on "winopen" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('winopen https://');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let items = completions.filter(x => x.type === 'item').map(x => x.text);
- assert(items.every(x => x.includes('https://')));
- });
- })
-
- it('should display only specified items in "complete" property by set command', async() => {
- let c = new Console(session);
-
- const execCommand = async(line) => {
- await body.sendKeys(':');
- await session.switchToFrame(0);
- await c.sendKeys(line, Key.Enter);
- await session.switchToParentFrame();
- }
-
- const typeCommand = async(...keys) => {
- await body.sendKeys(':');
- await session.switchToFrame(0);
- await c.sendKeys(...keys);
- }
-
- const cancel = async() => {
- await c.sendKeys(Key.Escape);
- await session.switchToParentFrame();
- }
-
- await execCommand('set complete=sbh');
- await typeCommand('open ');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let titles = completions.filter(x => x.type === 'title').map(x => x.text);
- assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History'])
- });
-
- await cancel();
- await execCommand('set complete=bss');
- await typeCommand('open ');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let titles = completions.filter(x => x.type === 'title').map(x => x.text);
- assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines'])
- });
- })
-
- it('should display only specified items in "complete" property by setting', async() => {
- const settings = {
- source: 'json',
- json: `{
- "keymaps": {
- ":": { "type": "command.show" }
- },
- "search": {
- "default": "google",
- "engines": { "google": "https://google.com/search?q={}" }
- },
- "properties": {
- "complete": "sbh"
- }
- }`,
- };
- await browser.storage.local.set({ settings, });
-
- let c = new Console(session);
-
- const typeCommand = async(...keys) => {
- await body.sendKeys(':');
- await session.switchToFrame(0);
- await c.sendKeys(...keys);
- }
-
- const cancel = async() => {
- await c.sendKeys(Key.Escape);
- await session.switchToParentFrame();
- }
-
- await browser.storage.local.set({ settings: {
- source: 'json',
- json: `{
- "keymaps": {
- ":": { "type": "command.show" }
- },
- "search": {
- "default": "google",
- "engines": { "google": "https://google.com/search?q={}" }
- },
- "properties": {
- "complete": "sbh"
- }
- }`,
- }});
- await typeCommand('open ');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let titles = completions.filter(x => x.type === 'title').map(x => x.text);
- assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History'])
- });
-
- await cancel();
-
- await browser.storage.local.set({ settings: {
- source: 'json',
- json: `{
- "keymaps": {
- ":": { "type": "command.show" }
- },
- "search": {
- "default": "google",
- "engines": { "google": "https://google.com/search?q={}" }
- },
- "properties": {
- "complete": "bss"
- }
- }`,
- }});
- await typeCommand('open ');
-
- await eventually(async() => {
- let completions = await c.getCompletions();
- let titles = completions.filter(x => x.type === 'title').map(x => x.text);
- assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines'])
- });
-
-
- })
-});
diff --git a/e2e/completion_open.test.ts b/e2e/completion_open.test.ts
new file mode 100644
index 0000000..c957e2e
--- /dev/null
+++ b/e2e/completion_open.test.ts
@@ -0,0 +1,186 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+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';
+
+describe("completion on open/tabopen/winopen commands", () => {
+ 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();
+
+ await browser.storage.local.set({
+ settings,
+ });
+
+ // Add item into hitories
+ await webdriver.navigate().to(('https://i-beam.org/404'));
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, server.url());
+ });
+
+ it('should show completions from search engines, bookmarks, and histories by "open" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('open ');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ assert.ok(completions.find(x => x.type === 'title' && x.text === 'Search Engines'));
+ assert.ok(completions.find(x => x.type === 'title' && x.text === 'Bookmarks'));
+ assert.ok(completions.find(x => x.type === 'title' && x.text === 'History'));
+ });
+ });
+
+ it('should filter items with URLs by keywords on "open" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('open https://');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let items = completions.filter(x => x.type === 'item').map(x => x.text);
+ assert.ok(items.every(x => x.includes('https://')));
+ });
+ })
+
+ it('should filter items with titles by keywords on "open" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('open getting');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let items = completions.filter(x => x.type === 'item').map(x => x.text);
+ assert.ok(items.every(x => x.toLowerCase().includes('getting')));
+ });
+ })
+
+ it('should filter items with titles by keywords on "tabopen" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('tabopen getting');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let items = completions.filter(x => x.type === 'item').map(x => x.text);
+ assert.ok(items.every(x => x.includes('https://')));
+ });
+ })
+
+ it('should filter items with titles by keywords on "winopen" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('winopen https://');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let items = completions.filter(x => x.type === 'item').map(x => x.text);
+ assert.ok(items.every(x => x.includes('https://')));
+ });
+ })
+
+ it('should display only specified items in "complete" property by set command', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('set complete=sbh');
+ await (webdriver.switchTo() as any).parentFrame();
+
+ console = await page.showConsole();
+ await console.inputKeys('open ');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let titles = completions.filter(x => x.type === 'title').map(x => x.text);
+ assert.deepStrictEqual(titles, ['Search Engines', 'Bookmarks', 'History'])
+ });
+
+ await console.close();
+ console = await page.showConsole();
+ await console.execCommand('set complete=bss');
+ await (webdriver.switchTo() as any).parentFrame();
+
+ console = await page.showConsole();
+ await console.inputKeys('open ');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let titles = completions.filter(x => x.type === 'title').map(x => x.text);
+ assert.deepStrictEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines'])
+ });
+ })
+
+ it('should display only specified items in "complete" property by setting', async() => {
+ await browser.storage.local.set({ settings: {
+ source: 'json',
+ json: `{
+ "keymaps": {
+ ":": { "type": "command.show" }
+ },
+ "search": {
+ "default": "google",
+ "engines": { "google": "https://google.com/search?q={}" }
+ },
+ "properties": {
+ "complete": "sbh"
+ }
+ }`,
+ }});
+
+ let console = await page.showConsole();
+ await console.inputKeys('open ');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let titles = completions.filter(x => x.type === 'title').map(x => x.text);
+ assert.deepStrictEqual(titles, ['Search Engines', 'Bookmarks', 'History'])
+ });
+
+ await console.close();
+ await (webdriver.switchTo() as any).parentFrame();
+
+ await browser.storage.local.set({ settings: {
+ source: 'json',
+ json: `{
+ "keymaps": {
+ ":": { "type": "command.show" }
+ },
+ "search": {
+ "default": "google",
+ "engines": { "google": "https://google.com/search?q={}" }
+ },
+ "properties": {
+ "complete": "bss"
+ }
+ }`,
+ }});
+
+ console = await page.showConsole();
+ await console.inputKeys('open ');
+
+ await eventually(async() => {
+ let completions = await console.getCompletions();
+ let titles = completions.filter(x => x.type === 'title').map(x => x.text);
+ assert.deepStrictEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines'])
+ });
+ })
+});
diff --git a/e2e/completion_set.test.js b/e2e/completion_set.test.js
deleted file mode 100644
index cf5ff5b..0000000
--- a/e2e/completion_set.test.js
+++ /dev/null
@@ -1,75 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-const settings = require('./settings');
-const Console = require('./lib/Console');
-
-const Key = lanthan.Key;
-
-describe("completion on set commands", () => {
- const port = 12321;
- let firefox;
- let session;
- let browser;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox({
- spy: path.join(__dirname, '..'),
- builderf: (builder) => {
- builder.addFile('build/settings.js');
- },
- });
- session = firefox.session;
- browser = firefox.browser;
-
- await browser.storage.local.set({
- settings,
- });
- });
-
- after(async() => {
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`about:blank`);
- body = await session.findElementByCSS('body');
- });
-
- it('should show all property names by "set" command with empty params', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('set ');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 5);
- assert.deepEqual(items[0], { type: 'title', text: 'Properties' });
- assert(items[1].text.startsWith('hintchars'))
- assert(items[2].text.startsWith('smoothscroll'))
- assert(items[3].text.startsWith('nosmoothscroll'))
- assert(items[4].text.startsWith('complete'))
- });
- });
-
- it('should show filtered property names by "set" command', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
- let c = new Console(session);
- await c.sendKeys('set no');
-
- await eventually(async() => {
- let items = await c.getCompletions();
- assert.equal(items.length, 2);
- assert(items[1].text.includes('nosmoothscroll'))
- });
- });
-});
diff --git a/e2e/completion_set.test.ts b/e2e/completion_set.test.ts
new file mode 100644
index 0000000..2a14b2c
--- /dev/null
+++ b/e2e/completion_set.test.ts
@@ -0,0 +1,64 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import settings from './settings';
+import eventually from './eventually';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("completion on set commands", () => {
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+ let page: Page;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await browser.storage.local.set({
+ settings,
+ });
+ });
+
+ after(async() => {
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, `about:blank`);
+ });
+
+ it('should show all property names by "set" command with empty params', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('set ');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 5);
+ assert.deepStrictEqual(items[0], { type: 'title', text: 'Properties' });
+ assert.ok(items[1].text.startsWith('hintchars'))
+ assert.ok(items[2].text.startsWith('smoothscroll'))
+ assert.ok(items[3].text.startsWith('nosmoothscroll'))
+ assert.ok(items[4].text.startsWith('complete'))
+ });
+ });
+
+ it('should show filtered property names by "set" command', async() => {
+ let console = await page.showConsole();
+ await console.inputKeys('set no');
+
+ await eventually(async() => {
+ let items = await console.getCompletions();
+ assert.strictEqual(items.length, 2);
+ assert.ok(items[1].text.includes('nosmoothscroll'))
+ });
+ });
+});
diff --git a/e2e/console.test.js b/e2e/console.test.js
deleted file mode 100644
index 6f6341f..0000000
--- a/e2e/console.test.js
+++ /dev/null
@@ -1,125 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
- app.get('/', (req, res) => {
- res.send(`
-
-
- Hello, world!
-
-`);
- });
- return app;
-};
-
-
-describe("console test", () => {
- const port = 12321;
- let http;
- let firefox;
- let session;
- let browser;
- let tab;
- let body;
-
- before(async() => {
- firefox = await lanthan.firefox();
- await firefox.session.installAddonFromPath(path.join(__dirname, '..'));
- session = firefox.session;
- browser = firefox.browser;
- http = newApp().listen(port);
- });
-
- after(async() => {
- http.close();
- if (firefox) {
- await firefox.close();
- }
- });
-
- beforeEach(async() => {
- await session.navigateTo(`http://127.0.0.1:${port}`);
- body = await session.findElementByCSS('body');
- });
-
- it('open console with :', async() => {
- await body.sendKeys(':');
-
- await session.switchToFrame(0);
-
- let input = await session.findElementByCSS('input');
- assert.equal(await input.isDisplayed(), true);
- });
-
- it('open console with open command by o', async() => {
- await body.sendKeys('o');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, 'open ');
- });
-
- it('open console with open command and current URL by O', async() => {
- await body.sendKeys(Key.Shift, 'o');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, `open http://127.0.0.1:${port}/`);
- });
-
- it('open console with tabopen command by t', async() => {
- await body.sendKeys('t');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, 'tabopen ');
- });
-
- it('open console with tabopen command and current URL by T', async() => {
- await body.sendKeys(Key.Shift, 't');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, `tabopen http://127.0.0.1:${port}/`);
- });
-
- it('open console with winopen command by w', async() => {
- await body.sendKeys('w');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, 'winopen ');
- });
-
- it('open console with winopen command and current URL by W', async() => {
- await body.sendKeys(Key.Shift, 'W');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, `winopen http://127.0.0.1:${port}/`);
- });
-
- it('open console with buffer command by b', async() => {
- await body.sendKeys('b');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, `buffer `);
- });
-
- it('open console with addbookmark command with title by a', async() => {
- await body.sendKeys('a');
-
- await session.switchToFrame(0);
- let value = await session.executeScript(() => document.querySelector('input').value);
- assert.equal(value, `addbookmark Hello, world!`);
- });
-});
-
diff --git a/e2e/console.test.ts b/e2e/console.test.ts
new file mode 100644
index 0000000..583580a
--- /dev/null
+++ b/e2e/console.test.ts
@@ -0,0 +1,90 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import TestServer from './lib/TestServer';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver, Key } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("console test", () => {
+ let server = new TestServer().receiveContent('/',
+ `Hello, world!`,
+ );
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let page: Page;
+
+ before(async() => {
+ 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();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, server.url());
+ });
+
+ it('open console with :', async() => {
+ await page.sendKeys(':');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), '');
+ });
+
+ it('open console with open command by o', async() => {
+ await page.sendKeys('o');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), 'open ');
+ });
+
+ it('open console with open command and current URL by O', async() => {
+ await page.sendKeys(Key.SHIFT, 'o');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `open ${server.url()}`);
+ });
+
+ it('open console with tabopen command by t', async() => {
+ await page.sendKeys('t');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), 'tabopen ');
+ });
+
+ it('open console with tabopen command and current URL by T', async() => {
+ await page.sendKeys(Key.SHIFT, 't');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `tabopen ${server.url()}`);
+ });
+
+ it('open console with winopen command by w', async() => {
+ await page.sendKeys('w');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `winopen `);
+ });
+
+ it('open console with winopen command and current URL by W', async() => {
+ await page.sendKeys(Key.SHIFT, 'W');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `winopen ${server.url()}`);
+ });
+
+ it('open console with buffer command by b', async() => {
+ await page.sendKeys('b');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `buffer `);
+ });
+
+ it('open console with addbookmark command with title by a', async() => {
+ await page.sendKeys('a');
+ let console = await page.getConsole();
+ assert.strictEqual(await console.currentValue(), `addbookmark Hello, world!`);
+ });
+});
diff --git a/e2e/eventually.js b/e2e/eventually.js
deleted file mode 100644
index ab0ae25..0000000
--- a/e2e/eventually.js
+++ /dev/null
@@ -1,23 +0,0 @@
-let defaultInterval = 100;
-let defaultTimeout = 2000;
-
-function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
-}
-
-const eventually = async (fn, timeout = defaultTimeout, interval = defaultInterval) => {
- let start = Date.now();
- let loop = async() => {
- try {
- await fn();
- } catch (err) {
- if (Date.now() - start > timeout) {
- throw err;
- }
- await new Promise((resolve) => setTimeout(resolve, interval))
- await loop();
- }
- };
- await loop();
-};
-module.exports = eventually;
diff --git a/e2e/eventually.ts b/e2e/eventually.ts
new file mode 100644
index 0000000..12c4552
--- /dev/null
+++ b/e2e/eventually.ts
@@ -0,0 +1,30 @@
+const defaultInterval = 100;
+const defaultTimeout = 2000;
+
+type Handler = () => void
+
+const sleep = (ms: number): Promise => {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+const eventually = async (
+ fn: Handler,
+ timeout = defaultTimeout,
+ interval = defaultInterval,
+): Promise => {
+ let start = Date.now();
+ let loop = async() => {
+ try {
+ await fn();
+ } catch (err) {
+ if (Date.now() - start > timeout) {
+ throw err;
+ }
+ await sleep(interval);
+ await loop();
+ }
+ };
+ await loop();
+};
+
+export default eventually;
diff --git a/e2e/follow.test.js b/e2e/follow.test.js
deleted file mode 100644
index 7e49119..0000000
--- a/e2e/follow.test.js
+++ /dev/null
@@ -1,257 +0,0 @@
-const express = require('express');
-const lanthan = require('lanthan');
-const path = require('path');
-const assert = require('assert');
-const eventually = require('./eventually');
-
-const Key = lanthan.Key;
-
-const newApp = () => {
- let app = express();
-
- app.get('/', (req, res) => {
- res.send(`
-
- hello
-`);
- });
-
- app.get('/follow-input', (req, res) => {
- res.send(`
-
-
-`);
- });
-
- app.get('/area', (req, res) => {
- res.send(`
-
-
-
-
-
-`);
- });
-
- /*
- * test case: link2 is out of the viewport
- * +-----------------+
- * | [link1] |<--- window
- * | |
- * |=================|<--- viewport
- * | [link2] |
- * | |
- * +-----------------+
- */
- app.get('/test1', (req, res) => {
- res.send(`
-
-
-
-
-
-
-`);
- });
-
-/*
- * test case 2: link2 and link3 are out of window of the frame
- * +-----------------+
- * | +-----------+ |
- * | | [link1] | |
- * |=================|
- * | | [link2] | |
- * | +-----------+ |
- * | |
- * +-----------------+
- */
- app.get('/test2', (req, res) => {
- res.send(`
-
-