Clean e2e tests

jh-changes
Shin'ya UEOKA 5 years ago
parent f59a2dd8c7
commit 68f6211aac
  1. 21
      e2e/blacklist.test.ts
  2. 16
      e2e/clipboard.test.ts
  3. 2
      e2e/command_addbookmark.test.ts
  4. 8
      e2e/command_bdelete.test.ts
  5. 2
      e2e/command_buffer.test.ts
  6. 2
      e2e/command_help.test.ts
  7. 30
      e2e/command_open.test.ts
  8. 20
      e2e/command_tabopen.test.ts
  9. 19
      e2e/command_winopen.test.ts
  10. 21
      e2e/completion.test.ts
  11. 25
      e2e/completion_buffers.test.ts
  12. 55
      e2e/completion_open.test.ts
  13. 13
      e2e/completion_set.test.ts
  14. 4
      e2e/console.test.ts
  15. 18
      e2e/follow.test.ts
  16. 2
      e2e/follow_properties.test.ts
  17. 18
      e2e/lib/SettingRepository.ts
  18. 2
      e2e/mark.test.ts
  19. 14
      e2e/navigate.test.ts
  20. 14
      e2e/options.test.ts
  21. 16
      e2e/options_form.test.ts
  22. 27
      e2e/partial_blacklist.test.ts
  23. 86
      e2e/settings.ts
  24. 2
      e2e/zoom.test.ts

@ -5,10 +5,12 @@ import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
import SettingRepository from "./lib/SettingRepository";
import Settings from "../src/shared/settings/Settings";
describe("blacklist test", () => {
let server = new TestServer().receiveContent('/*',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
@ -24,17 +26,12 @@ describe("blacklist test", () => {
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}" ]
}`,
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
keymaps: {
j: { type: "scroll.vertically", count: 1 },
},
});
blacklist: [ url ],
}));
});
after(async() => {
@ -46,7 +43,7 @@ describe("blacklist test", () => {
it('should disable add-on if the URL is in the blacklist', async () => {
let page = await Page.navigateTo(webdriver, server.url('/a'));
await page.sendKeys('j')
await page.sendKeys('j');
let scrollY = await page.getScrollY();
assert.strictEqual(scrollY, 0);

@ -4,10 +4,11 @@ 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';
import SettingRepository from "./lib/SettingRepository";
import Settings from "../src/shared/settings/Settings";
describe("clipboard test", () => {
let server = new TestServer(12321).receiveContent('/happy', 'ok');
@ -23,9 +24,14 @@ describe("clipboard test", () => {
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
search: {
default: "google",
engines: {
"google": "http://127.0.0.1:12321/google?q={}",
},
},
}));
await server.start();
});
@ -42,7 +48,7 @@ describe("clipboard test", () => {
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'));

@ -10,7 +10,7 @@ import Page from './lib/Page';
describe('addbookmark command test', () => {
let server = new TestServer().receiveContent('/happy', `
<!DOCTYPE html>
<html lang="en"><head><title>how to be happy</title></head></html">`,
<html lang="en"><head><title>how to be happy</title></head></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;

@ -36,10 +36,10 @@ describe('bdelete/bdeletes command test', () => {
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 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();

@ -16,7 +16,7 @@ describe('buffer command test', () => {
<head>
<title>my_${req.path.slice(1)}</title>
</head>
</html">`);
</html>`);
});
let lanthan: Lanthan;
let webdriver: WebDriver;

@ -34,7 +34,7 @@ describe("help command test", () => {
beforeEach(async() => {
page = await Page.navigateTo(webdriver, server.url());
})
});
it('should open help page by help command ', async() => {
let console = await page.showConsole();

@ -2,14 +2,15 @@ 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';
import SettingRepository from "./lib/SettingRepository";
import Settings from "../src/shared/settings/Settings";
describe("open command test", () => {
let server = new TestServer(12321)
let server = new TestServer()
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
@ -25,11 +26,16 @@ describe("open command test", () => {
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
await server.start();
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
search: {
default: "google",
engines: {
"google": server.url('/google?q={}'),
"yahoo": server.url('/yahoo?q={}'),
},
},
}));
});
after(async() => {
@ -42,7 +48,7 @@ describe("open command test", () => {
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();
@ -60,7 +66,7 @@ describe("open command test", () => {
await console.execCommand('open yahoo an apple');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple'))
});
@ -71,7 +77,7 @@ describe("open command test", () => {
await console.execCommand('open');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.strictEqual(url.href, server.url('/google?q='))
});
@ -82,7 +88,7 @@ describe("open command test", () => {
await console.execCommand('open yahoo');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.strictEqual(url.href, server.url('/yahoo?q='))
});
@ -93,7 +99,7 @@ describe("open command test", () => {
await console.execCommand('open example.com');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.strictEqual(url.href, 'http://example.com/')
});
@ -104,7 +110,7 @@ describe("open command test", () => {
await console.execCommand('open https://example.com/');
await eventually(async() => {
let tabs = await browser.tabs.query({ active: true })
let tabs = await browser.tabs.query({ active: true });
let url = new URL(tabs[0].url);
assert.strictEqual(url.href, 'https://example.com/')
});

@ -2,14 +2,15 @@ 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';
import SettingRepository from "./lib/SettingRepository";
import Settings from "../src/shared/settings/Settings";
describe("tabopen command test", () => {
let server = new TestServer(12321)
let server = new TestServer()
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
@ -25,11 +26,16 @@ describe("tabopen command test", () => {
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
await server.start();
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
search: {
default: "google",
engines: {
"google": server.url('/google?q={}'),
"yahoo": server.url('/yahoo?q={}'),
},
},
}));
});
after(async() => {
@ -46,7 +52,7 @@ describe("tabopen command test", () => {
}
page = await Page.navigateTo(webdriver, server.url());
})
});
it('should open default search for keywords by tabopen command ', async() => {
let console = await page.showConsole();

@ -2,14 +2,15 @@ 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';
import SettingRepository from "./lib/SettingRepository";
import Settings from "../src/shared/settings/Settings";
describe("winopen command test", () => {
let server = new TestServer(12321)
let server = new TestServer()
.receiveContent('/google', 'google')
.receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
@ -24,11 +25,17 @@ describe("winopen command test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
await server.start();
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
search: {
default: "google",
engines: {
"google": server.url('/google?q={}'),
"yahoo": server.url('/yahoo?q={}'),
},
},
}));
});
after(async() => {
@ -45,7 +52,7 @@ describe("winopen command test", () => {
}
page = await Page.navigateTo(webdriver, server.url());
})
});
it('should open default search for keywords by winopen command ', async() => {
let console = await page.showConsole();

@ -2,7 +2,6 @@ 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';
@ -10,7 +9,6 @@ import Page from './lib/Page';
describe("general completion test", () => {
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
@ -19,11 +17,6 @@ describe("general completion test", () => {
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
});
after(async() => {
@ -42,8 +35,8 @@ describe("general completion test", () => {
let items = await console.getCompletions();
assert.strictEqual(items.length, 11);
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[1].text.startsWith('set'));
assert.ok(items[2].text.startsWith('open'));
assert.ok(items[3].text.startsWith('tabopen'))
});
@ -54,8 +47,8 @@ describe("general completion test", () => {
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[1].text.startsWith('buffer'));
assert.ok(items[2].text.startsWith('bdelete'));
assert.ok(items[3].text.startsWith('bdeletes'))
});
@ -74,14 +67,14 @@ describe("general completion test", () => {
await console.sendKeys(Key.TAB);
await eventually(async() => {
let items = await console.getCompletions();
assert.ok(items[1].highlight)
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.ok(items[3].highlight);
assert.strictEqual(await console.currentValue(), 'bdeletes');
});
@ -93,7 +86,7 @@ describe("general completion test", () => {
await console.sendKeys(Key.SHIFT, Key.TAB);
await eventually(async() => {
let items = await console.getCompletions();
assert.ok(items[3].highlight)
assert.ok(items[3].highlight);
assert.strictEqual(await console.currentValue(), 'bdeletes');
});
});

@ -3,7 +3,6 @@ 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';
@ -17,7 +16,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
<head>
<title>title_${req.path.slice(1)}</title>
</head>
</html">`);
</html>`);
});
let lanthan: Lanthan;
let webdriver: WebDriver;
@ -32,10 +31,6 @@ describe("completion on buffer/bdelete/bdeletes", () => {
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
await server.start();
});
@ -53,7 +48,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
}
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('/site2'), pinned: true });
for (let i = 3; i <= 5; ++i) {
await browser.tabs.create({ url: server.url('/site' + i) });
}
@ -84,7 +79,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -97,7 +92,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -108,7 +103,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -120,7 +115,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -133,7 +128,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -146,7 +141,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -161,7 +156,7 @@ describe("completion on buffer/bdelete/bdeletes", () => {
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();
@ -176,5 +171,5 @@ describe("completion on buffer/bdelete/bdeletes", () => {
assert.ok(items[4].text.includes('site4'));
assert.ok(items[5].text.includes('site5'));
});
})
});
});

@ -1,12 +1,13 @@
import * as path from 'path';
import * as assert from 'assert';
import Settings from "../src/shared/settings/Settings";
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';
import SettingRepository from "./lib/SettingRepository";
describe("completion on open/tabopen/winopen commands", () => {
let server = new TestServer().receiveContent('/*', 'ok');
@ -25,10 +26,6 @@ describe("completion on open/tabopen/winopen commands", () => {
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'));
});
@ -65,7 +62,7 @@ describe("completion on open/tabopen/winopen commands", () => {
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();
@ -76,7 +73,7 @@ describe("completion on open/tabopen/winopen commands", () => {
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();
@ -87,7 +84,7 @@ describe("completion on open/tabopen/winopen commands", () => {
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();
@ -98,7 +95,7 @@ describe("completion on open/tabopen/winopen commands", () => {
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();
@ -127,24 +124,12 @@ describe("completion on open/tabopen/winopen commands", () => {
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"
}
}`,
}});
new SettingRepository(browser).saveJSON(Settings.fromJSON({
properties: { complete: "sbh" },
}));
let console = await page.showConsole();
await console.inputKeys('open ');
@ -158,21 +143,9 @@ describe("completion on open/tabopen/winopen commands", () => {
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"
}
}`,
}});
new SettingRepository(browser).saveJSON(Settings.fromJSON({
properties: { complete: "bss" },
}));
console = await page.showConsole();
await console.inputKeys('open ');
@ -182,5 +155,5 @@ describe("completion on open/tabopen/winopen commands", () => {
let titles = completions.filter(x => x.type === 'title').map(x => x.text);
assert.deepStrictEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines'])
});
})
});
});

@ -1,7 +1,6 @@
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';
@ -10,7 +9,6 @@ import Page from './lib/Page';
describe("completion on set commands", () => {
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
@ -19,11 +17,6 @@ describe("completion on set commands", () => {
.spyAddon(path.join(__dirname, '..'))
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
await browser.storage.local.set({
settings,
});
});
after(async() => {
@ -44,9 +37,9 @@ describe("completion on set commands", () => {
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[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'))
});
});

@ -7,8 +7,8 @@ import { WebDriver, Key } from 'selenium-webdriver';
import Page from './lib/Page';
describe("console test", () => {
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html">`,
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;

@ -14,13 +14,13 @@ const newApp = () => {
<!DOCTYPE html>
<html lang="en"><body>
<a href="hello">hello</a>
</body></html">`);
</body></html>`);
server.receiveContent('/follow-input', `
<!DOCTYPE html>
<html lang="en"><body>
<input>
</body></html">`);
</body></html>`);
server.receiveContent('/area', `
<!DOCTYPE html>
@ -34,8 +34,8 @@ const newApp = () => {
<area shape="rect" coords="64,64,64,64" href="/">
<area shape="rect" coords="128,128,64,64" href="/">
</map>
</body></html">`);
</body></html>`);
/*
* test case: link2 is out of the viewport
* +-----------------+
@ -52,7 +52,7 @@ const newApp = () => {
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body></html">`);
</body></html>`);
/*
* test case 2: link2 and link3 are out of window of the frame
@ -69,14 +69,14 @@ const newApp = () => {
<!DOCTYPE html>
<html lang="en"><body>
<iframe height="5000" src='/test2-frame'>
</body></html">`);
</body></html>`);
server.receiveContent('/test2-frame', `
<!DOCTYPE html>
<html lang="en"><body>
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body></html">`);
</body></html>`);
/* test case 3: link2 is out of window of the frame
* +-----------------+
@ -92,14 +92,14 @@ const newApp = () => {
<!DOCTYPE html>
<html lang="en"><body>
<iframe src='/test3-frame'>
</body></html">`);
</body></html>`);
server.receiveContent('/test3-frame', `
<!DOCTYPE html>
<html lang="en"><body>
<div><a href="link1">link1</a></div>
<div style="min-height:3000px"></div>
<div><a href="link2">link2</a></div>
</body></html">`);
</body></html>`);
return server;
};

@ -16,7 +16,7 @@ describe('follow properties test', () => {
<a href="/">link3</a>
<a href="/">link4</a>
<a href="/">link5</a>
</body></html">`);
</body></html>`);
let lanthan: Lanthan;
let webdriver: WebDriver;

@ -0,0 +1,18 @@
import { JSONTextSettings, SettingSource } from '../../src/shared/SettingData';
import Settings from '../../src/shared/settings/Settings';
export default class SettingRepository {
constructor(
private readonly browser: any,
) {
}
async saveJSON(settings: Settings): Promise<void> {
await this.browser.storage.local.set({
settings: {
source: SettingSource.JSON,
json: JSONTextSettings.fromSettings(settings).toJSONText(),
}
});
}
}

@ -9,7 +9,7 @@ import Page from './lib/Page';
describe("mark test", () => {
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;

@ -16,7 +16,7 @@ const newApp = () => {
<html lang="en">
<a href="/pagenation-a/${Number(req.params.page) - 1}">prev</a>
<a href="/pagenation-a/${Number(req.params.page) + 1}">next</a>
</html">`);
</html>`);
});
server.handle('/pagenation-link/:page', (req, res) => {
@ -27,7 +27,7 @@ const newApp = () => {
<link rel="prev" href="/pagenation-link/${Number(req.params.page) - 1}"></link>
<link rel="next" href="/pagenation-link/${Number(req.params.page) + 1}"></link>
</head>
</html">`);
</html>`);
});
server.receiveContent('/reload', `
<!DOCTYPE html>
@ -36,7 +36,7 @@ const newApp = () => {
<script>window.location.hash = Date.now()</script>
</head>
<body style="width:10000px; height:10000px"></body>
</html">`);
</html>`);
server.receiveContent('/*', `ok`);
@ -75,7 +75,7 @@ describe("navigate test", () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
})
});
it('should go to parent path without hash by gu', async () => {
let page = await Page.navigateTo(webdriver, server.url('/a/b/c'));
@ -95,7 +95,7 @@ describe("navigate test", () => {
await eventually(async() => {
let tab = (await browser.tabs.query({}))[0];
let url = new URL(tab.url);
assert.strictEqual(url.hash, '')
assert.strictEqual(url.hash, '');
assert.strictEqual(url.pathname, `/a/b/c`)
});
});
@ -213,7 +213,7 @@ describe("navigate test", () => {
await page.sendKeys('r');
let after
let after;
await eventually(async() => {
let tab = (await browser.tabs.query({}))[0];
after = Number(new URL(tab.url).hash.split('#')[1]);
@ -239,7 +239,7 @@ describe("navigate test", () => {
await page.sendKeys(Key.SHIFT, 'R');
let after
let after;
await eventually(async() => {
let tab = (await browser.tabs.query({}))[0];
after = Number(new URL(tab.url).hash.split('#')[1]);

@ -10,7 +10,7 @@ import OptionPage from './lib/OptionPage';
describe("options page", () => {
let server = new TestServer().receiveContent('/',
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html">`,
`<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`,
);
let lanthan: Lanthan;
let webdriver: WebDriver;
@ -39,22 +39,22 @@ describe("options page", () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
})
});
it('saves current config on blur', async () => {
let page = await OptionPage.open(lanthan);
let jsonPage = await page.asJSONOptionPage();
await jsonPage.updateSettings(`{ "blacklist": [ "https://example.com" ] }`)
await jsonPage.updateSettings(`{ "blacklist": [ "https://example.com" ] }`);
let { settings } = await browser.storage.local.get('settings');
assert.strictEqual(settings.source, 'json')
assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } ')
assert.strictEqual(settings.source, 'json');
assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } ');
await jsonPage.updateSettings(`invalid json`);
settings = (await browser.storage.local.get('settings')).settings;
assert.strictEqual(settings.source, 'json')
assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } ')
assert.strictEqual(settings.source, 'json');
assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } ');
let message = await jsonPage.getErrorMessage();
assert.ok(message.startsWith('SyntaxError:'))

@ -19,13 +19,13 @@ describe("options form page", () => {
for (let tab of tabs.slice(1)) {
await browser.tabs.remove(tab.id);
}
})
});
afterEach(async() => {
if (lanthan) {
await lanthan.quit();
}
})
});
it('switch to form settings', async () => {
let page = await OptionPage.open(lanthan);
@ -33,7 +33,7 @@ describe("options form page", () => {
let { settings } = await browser.storage.local.get('settings');
assert.strictEqual(settings.source, 'form')
})
});
it('add blacklist', async () => {
let page = await OptionPage.open(lanthan);
@ -43,20 +43,20 @@ describe("options form page", () => {
// assert default
let settings = (await browser.storage.local.get('settings')).settings;
assert.deepStrictEqual(settings.form.blacklist, [])
assert.deepStrictEqual(settings.form.blacklist, []);
// add blacklist items
await forms.addBlacklist();
await forms.setBlacklist(0, 'google.com')
await forms.setBlacklist(0, 'google.com');
settings = (await browser.storage.local.get('settings')).settings;
assert.deepStrictEqual(settings.form.blacklist, ['google.com'])
assert.deepStrictEqual(settings.form.blacklist, ['google.com']);
await forms.addBlacklist();
await forms.setBlacklist(1, 'yahoo.com')
await forms.setBlacklist(1, 'yahoo.com');
settings = (await browser.storage.local.get('settings')).settings;
assert.deepStrictEqual(settings.form.blacklist, ['google.com', 'yahoo.com'])
assert.deepStrictEqual(settings.form.blacklist, ['google.com', 'yahoo.com']);
// delete first item
await forms.removeBlackList(0);

@ -5,6 +5,8 @@ import TestServer from './lib/TestServer';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
import Settings from '../src/shared/settings/Settings';
import SettingRepository from './lib/SettingRepository';
describe("partial blacklist test", () => {
let server = new TestServer().receiveContent('/*',
@ -24,20 +26,15 @@ describe("partial blacklist test", () => {
await server.start();
let url = server.url().replace('http://', '');
await browser.storage.local.set({
settings: {
source: 'json',
json: `{
"keymaps": {
"j": { "type": "scroll.vertically", "count": 1 },
"k": { "type": "scroll.vertically", "count": -1 }
},
"blacklist": [
{ "url": "${url}", "keys": ["k"] }
]
}`,
await new SettingRepository(browser).saveJSON(Settings.fromJSON({
keymaps: {
j: { type: 'scroll.vertically', count: 1 },
k: { type: 'scroll.vertically', count: -1 },
},
});
blacklist: [
{ 'url': url, 'keys': ['k'] }
]
}));
});
after(async() => {
@ -50,11 +47,11 @@ describe("partial blacklist test", () => {
it('should disable keys in the partial blacklist', async () => {
let page = await Page.navigateTo(webdriver, server.url('/'));
await page.sendKeys('j')
await page.sendKeys('j');
let scrollY = await page.getScrollY();
assert.strictEqual(scrollY, 64);
await page.sendKeys('k')
await page.sendKeys('k');
scrollY = await page.getScrollY();
assert.strictEqual(scrollY, 64);
});

@ -1,86 +0,0 @@
export default {
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", "select": "left" },
"x$": { "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": [
]
}`,
};

@ -20,7 +20,7 @@ describe("zoom test", () => {
.build();
webdriver = lanthan.getWebDriver();
browser = lanthan.getWebExtBrowser();
tab = (await browser.tabs.query({}))[0]
tab = (await browser.tabs.query({}))[0];
page = await Page.currentContext(webdriver);
});