Add e2e tests for open/tabopen/winopen commands

jh-changes
Shin'ya Ueoka 6 years ago
parent 70ab186541
commit ac1c383fd0
  1. 12
      QA.md
  2. 150
      e2e/command_open.test.js
  3. 161
      e2e/command_tabopen.test.js
  4. 173
      e2e/command_winopen.test.js
  5. 85
      e2e/settings.js

12
QA.md

@ -39,18 +39,6 @@ The behaviors of the console are tested in [Console section](#consoles).
- [ ] `<EMPTY>`: do nothing - [ ] `<EMPTY>`: do nothing
<br> <br>
- [ ] `open an apple`: search with keywords "an apple" by default search engine (google)
- [ ] `open github.com`: open github.com
- [ ] `open https://github.com`: open github.com
- [ ] `open yahoo an apple`: search with keywords "an apple" by yahoo.com
- [ ] `open yahoo`: search with empty keywords; yahoo redirects to top page
- [ ] `open`: open default search engine
<br>
- [ ] `tabopen`: do above tests replaced `open` with `tabopen`, and verify the page is opened in new tab
- [ ] `winopen`: do above tests replaced `open` with `winopen`, and verify the page is opened in new window
<br>
- [ ] `buffer`: do nothing - [ ] `buffer`: do nothing
- [ ] `buffer <title>`, `buffer <url>`: select tab which has an title matched with - [ ] `buffer <title>`, `buffer <url>`: select tab which has an title matched with
- [ ] `buffer 1`: select leftmost tab - [ ] `buffer 1`: select leftmost tab

@ -0,0 +1,150 @@
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(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("open command test", () => {
const port = 12321;
let http;
let firefox;
let session;
let browser;
let tab;
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/')
});
});
});

@ -0,0 +1,161 @@
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(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("tabopen command test", () => {
const port = 12321;
let http;
let firefox;
let session;
let browser;
let tab;
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/')
});
});
});

@ -0,0 +1,173 @@
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(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
</html">`);
});
}
app.get('/', (req, res) => {
res.send(`<!DOCTYPEhtml>
<html lang="en">
<body><h1>home</h1></body>
</html">`);
});
return app;
};
describe("winopen command test", () => {
const port = 12321;
let http;
let firefox;
let session;
let browser;
let tab;
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/')
});
});
});

@ -0,0 +1,85 @@
module.exports = {
source: 'json',
json: `{
"keymaps": {
"0": { "type": "scroll.home" },
":": { "type": "command.show" },
"o": { "type": "command.show.open", "alter": false },
"O": { "type": "command.show.open", "alter": true },
"t": { "type": "command.show.tabopen", "alter": false },
"T": { "type": "command.show.tabopen", "alter": true },
"w": { "type": "command.show.winopen", "alter": false },
"W": { "type": "command.show.winopen", "alter": true },
"b": { "type": "command.show.buffer" },
"a": { "type": "command.show.addbookmark", "alter": true },
"k": { "type": "scroll.vertically", "count": -1 },
"j": { "type": "scroll.vertically", "count": 1 },
"h": { "type": "scroll.horizonally", "count": -1 },
"l": { "type": "scroll.horizonally", "count": 1 },
"<C-U>": { "type": "scroll.pages", "count": -0.5 },
"<C-D>": { "type": "scroll.pages", "count": 0.5 },
"<C-B>": { "type": "scroll.pages", "count": -1 },
"<C-F>": { "type": "scroll.pages", "count": 1 },
"gg": { "type": "scroll.top" },
"G": { "type": "scroll.bottom" },
"$": { "type": "scroll.end" },
"d": { "type": "tabs.close" },
"D": { "type": "tabs.close.right" },
"!d": { "type": "tabs.close.force" },
"u": { "type": "tabs.reopen" },
"K": { "type": "tabs.prev", "count": 1 },
"J": { "type": "tabs.next", "count": 1 },
"gT": { "type": "tabs.prev", "count": 1 },
"gt": { "type": "tabs.next", "count": 1 },
"g0": { "type": "tabs.first" },
"g$": { "type": "tabs.last" },
"<C-6>": { "type": "tabs.prevsel" },
"r": { "type": "tabs.reload", "cache": false },
"R": { "type": "tabs.reload", "cache": true },
"zp": { "type": "tabs.pin.toggle" },
"zd": { "type": "tabs.duplicate" },
"zi": { "type": "zoom.in" },
"zo": { "type": "zoom.out" },
"zz": { "type": "zoom.neutral" },
"f": { "type": "follow.start", "newTab": false },
"F": { "type": "follow.start", "newTab": true, "background": false },
"m": { "type": "mark.set.prefix" },
"'": { "type": "mark.jump.prefix" },
"H": { "type": "navigate.history.prev" },
"L": { "type": "navigate.history.next" },
"[[": { "type": "navigate.link.prev" },
"]]": { "type": "navigate.link.next" },
"gu": { "type": "navigate.parent" },
"gU": { "type": "navigate.root" },
"gi": { "type": "focus.input" },
"gf": { "type": "page.source" },
"gh": { "type": "page.home" },
"gH": { "type": "page.home", "newTab": true },
"y": { "type": "urls.yank" },
"p": { "type": "urls.paste", "newTab": false },
"P": { "type": "urls.paste", "newTab": true },
"/": { "type": "find.start" },
"n": { "type": "find.next" },
"N": { "type": "find.prev" },
"<S-Esc>": { "type": "addon.toggle.enabled" }
},
"search": {
"default": "google",
"engines": {
"google": "http://127.0.0.1:12321/google?q={}",
"yahoo": "http://127.0.0.1:12321/yahoo?q={}",
"bing": "http://127.0.0.1:12321/bind?q={}",
"duckduckgo": "http://127.0.0.1:12321/duplicate?q={}",
"twitter": "http://127.0.0.1:12321/twitter?q={}",
"wikipedia": "http://127.0.0.1:12321/wikipedia?q={}"
}
},
"properties": {
"hintchars": "abcdefghijklmnopqrstuvwxyz",
"smoothscroll": false,
"complete": "sbh"
},
"blacklist": [
]
}`,
}