Merge pull request #417 from ueokande/async-function

Use await/async on e2e test
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit 897e010f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 128
      e2e/contents/follow.test.js
  2. 182
      e2e/contents/navigate.test.js
  3. 161
      e2e/contents/scroll.test.js
  4. 325
      e2e/contents/tab.test.js
  5. 72
      e2e/contents/zoom.test.js
  6. 62
      src/background/actions/command.js
  7. 5
      src/background/actions/setting.js
  8. 15
      src/background/actions/tab.js
  9. 5
      src/background/components/background.js
  10. 12
      src/background/components/indicator.js
  11. 5
      src/background/components/tab.js
  12. 18
      src/background/index.js
  13. 5
      src/background/shared/completions/bookmarks.js
  14. 7
      src/background/shared/completions/histories.js
  15. 40
      src/background/shared/completions/index.js
  16. 87
      src/background/shared/tabs.js
  17. 26
      src/background/shared/zooms.js
  18. 7
      src/console/components/console.js
  19. 18
      src/content/actions/find.js
  20. 11
      src/content/components/common/index.js
  21. 13
      src/settings/actions/setting.js
  22. 10
      src/shared/settings/storage.js
  23. 5
      src/shared/versions/index.js
  24. 5
      src/shared/versions/storage.js
  25. 37
      test/shared/versions/index.test.js
  26. 27
      test/shared/versions/storage.test.js

@ -6,116 +6,78 @@ import { CLIENT_URL } from '../web-server/url';
describe("tab test", () => { describe("tab test", () => {
let targetWindow; let targetWindow;
beforeEach(() => { beforeEach(async () => {
return windows.create(CLIENT_URL).then((win) => { targetWindow = await windows.create(CLIENT_URL);
targetWindow = win;
});
}); });
afterEach(() => { afterEach(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });return
it('follows link by `f`', async() => {
let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/follow');
await keys.press(tab.id, 'f');
await new Promise(resolve => { setTimeout(() => resolve(), 10) });
await keys.press(tab.id, 'a');
await new Promise(resolve => { setTimeout(() => resolve(), 10) });
it('follows link by `f`', () => { tab = tabs.get(tab.id);
let targetTab;
return tabs.create(targetWindow.id, CLIENT_URL + '/follow').then((tab) => {
targetTab = tab;
return keys.press(targetTab.id, 'f');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, 'a');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/follow#a'); expect(tab.url).to.be.equal(CLIENT_URL + '/follow#a');
}); });
});
it('follows link into new tab by `F`', () => { it('follows link into new tab by `F`', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/follow');
return tabs.create(targetWindow.id, CLIENT_URL + '/follow').then((tab) => { await keys.press(tab.id, 'F', { shiftKey: true });
targetTab = tab; await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'F', { shiftKey: true }); await keys.press(tab.id, 'a');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 500) });
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => { let win = await windows.get(targetWindow.id);
return keys.press(targetTab.id, 'a');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 500) });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
let urls = win.tabs.map(t => t.url); let urls = win.tabs.map(t => t.url);
expect(urls).to.have.lengthOf(3); expect(urls).to.have.lengthOf(3);
expect(urls).to.include(CLIENT_URL + '/'); expect(urls).to.include(CLIENT_URL + '/');
expect(urls).to.include(CLIENT_URL + '/follow'); expect(urls).to.include(CLIENT_URL + '/follow');
expect(urls).to.include(CLIENT_URL + '/follow#a'); expect(urls).to.include(CLIENT_URL + '/follow#a');
}); });
});
it('follows link with target=_blank into new tab by `f`', () => { it('follows link with target=_blank into new tab by `f`', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/follow');
return tabs.create(targetWindow.id, CLIENT_URL + '/follow').then((tab) => { await keys.press(tab.id, 'f');
targetTab = tab; await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'f'); await keys.press(tab.id, 'b');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 500) });
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => { let win = await windows.get(targetWindow.id);
return keys.press(targetTab.id, 'b');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 500) });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
let urls = win.tabs.map(t => t.url); let urls = win.tabs.map(t => t.url);
expect(urls).to.have.lengthOf(3); expect(urls).to.have.lengthOf(3);
expect(urls).to.include(CLIENT_URL + '/'); expect(urls).to.include(CLIENT_URL + '/');
expect(urls).to.include(CLIENT_URL + '/follow'); expect(urls).to.include(CLIENT_URL + '/follow');
expect(urls).to.include(CLIENT_URL + '/follow#external'); expect(urls).to.include(CLIENT_URL + '/follow#external');
}); });
});
it('follows link with target=_blank into new tab by `F`', () => { it('follows link with target=_blank into new tab by `F`', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/follow');
return tabs.create(targetWindow.id, CLIENT_URL + '/follow').then((tab) => { await keys.press(tab.id, 'F', { shiftKey: true });
targetTab = tab; await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'F', { shiftKey: true }); await keys.press(tab.id, 'b');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 500) });
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) }); let win = await windows.get(targetWindow.id);
}).then(() => {
return keys.press(targetTab.id, 'b');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 500) });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
let urls = win.tabs.map(t => t.url); let urls = win.tabs.map(t => t.url);
expect(urls).to.have.lengthOf(3); expect(urls).to.have.lengthOf(3);
expect(urls).to.include(CLIENT_URL + '/'); expect(urls).to.include(CLIENT_URL + '/');
expect(urls).to.include(CLIENT_URL + '/follow'); expect(urls).to.include(CLIENT_URL + '/follow');
expect(urls).to.include(CLIENT_URL + '/follow#external'); expect(urls).to.include(CLIENT_URL + '/follow#external');
}); });
});
it('follows area by `F`', () => { it('follows area by `F`', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/follow');
return tabs.create(targetWindow.id, CLIENT_URL + '/follow').then((tab) => { await keys.press(tab.id, 'f');
targetTab = tab; await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'f'); await keys.press(tab.id, 'c');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => { tab = await tabs.get(tab.id);
return keys.press(targetTab.id, 'c');
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/follow#area'); expect(tab.url).to.be.equal(CLIENT_URL + '/follow#area');
}); });
}); });
});

@ -7,150 +7,96 @@ import { CLIENT_URL } from '../web-server/url';
describe("navigate test", () => { describe("navigate test", () => {
let targetWindow; let targetWindow;
before(() => { before(async () => {
return windows.create().then((win) => { targetWindow = await windows.create();
targetWindow = win; await tabs.create(targetWindow.id, CLIENT_URL);
return tabs.create(targetWindow.id, CLIENT_URL);
});
}); });
after(() => { after(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
it('goes to parent', () => { it('goes to parent', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, 'u'); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/'); expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/');
}); });
});
it('removes hash', () => { it('removes hash', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c#navigate');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c#navigate').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); tab = await tabs.get(tab.id);
}).then(() => {
return keys.press(targetTab.id, 'u');
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/c#'); expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/c#');
}); });
});
it('goes to root', () => { it('goes to root', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'U', { shiftKey: true });
return keys.press(targetTab.id, 'g'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, 'U', { shiftKey: true }); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/'); expect(tab.url).to.be.equal(CLIENT_URL + '/');
}); });
});
it('goes back and forward in history', () => { it('goes back and forward in history', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/#navigate');
return tabs.create(targetWindow.id, CLIENT_URL + '/#navigate').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); await keys.press(tab.id, 'H', { shiftKey: true });
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'u');
}).then(() => { tab = await tabs.get(tab.id);
return keys.press(targetTab.id, 'H', { shiftKey: true });
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url, 'go back in history').to.be.equal(CLIENT_URL + '/#navigate'); expect(tab.url, 'go back in history').to.be.equal(CLIENT_URL + '/#navigate');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return new Promise(resolve => { setTimeout(() => resolve(), 10) }); await keys.press(tab.id, 'L', { shiftKey: true });
}).then(() => {
return keys.press(targetTab.id, 'L', { shiftKey: true }); tab = await tabs.get(tab.id);
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#'); expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#');
}); });
});
it('goes previous page by <a>', () => { it('goes previous page by <a>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { await keys.press(tab.id, '[');
targetTab = tab; await keys.press(tab.id, '[');
return keys.press(targetTab.id, '['); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, '['); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=9'); expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=9');
});
}) })
it('goes next page by <a>', () => { it('goes next page by <a>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { await keys.press(tab.id, ']');
targetTab = tab; await keys.press(tab.id, ']');
return keys.press(targetTab.id, ']'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, ']'); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=11'); expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=11');
});
}) })
it('goes previous page by <link>', () => { it('goes previous page by <link>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { await keys.press(tab.id, '[');
targetTab = tab; await keys.press(tab.id, '[');
return keys.press(targetTab.id, '['); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, '['); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=9'); expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=9');
});
}) })
it('goes next page by <link>', () => { it('goes next page by <link>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { await keys.press(tab.id, ']');
targetTab = tab; await keys.press(tab.id, ']');
return keys.press(targetTab.id, ']'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, ']'); tab = await tabs.get(tab.id);
}).then(() => {
return new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=11'); expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=11');
});
}) })
}); });

@ -8,142 +8,99 @@ describe("scroll test", () => {
let targetWindow; let targetWindow;
let targetTab; let targetTab;
before(() => { before(async () => {
return windows.create().then((win) => { targetWindow = await windows.create();
targetWindow = win; targetTab = await tabs.create(targetWindow.id, CLIENT_URL + '/scroll');
return tabs.create(targetWindow.id, CLIENT_URL + '/scroll');
}).then((tab) => {
targetTab = tab;
});
}); });
after(() => { after(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
it('scrolls up by k', () => { it('scrolls up by k', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100);
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'k');
before = scroll;
return keys.press(targetTab.id, 'k'); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.lessThan(before.y); expect(actual.y).to.be.lessThan(before.y);
}); });
});
it('scrolls down by j', () => { it('scrolls down by j', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100);
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'j');
before = scroll;
return keys.press(targetTab.id, 'j'); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.greaterThan(before.y); expect(actual.y).to.be.greaterThan(before.y);
}); });
});
it('scrolls left by h', () => { it('scrolls left by h', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100)
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'h');
before = scroll;
return keys.press(targetTab.id, 'h'); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.x).to.be.lessThan(before.x); expect(actual.x).to.be.lessThan(before.x);
}); });
});
it('scrolls top by gg', () => { it('scrolls top by gg', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, 'g'); await keys.press(targetTab.id, 'g');
}).then(() => { await keys.press(targetTab.id, 'g');
return keys.press(targetTab.id, 'g'); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.equals(0); expect(actual.y).to.be.equals(0);
}); });
});
it('scrolls bottom by G', () => { it('scrolls bottom by G', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, 'G', { shiftKey: true }); await keys.press(targetTab.id, 'G', { shiftKey: true });
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.equals(actual.yMax); expect(actual.y).to.be.equals(actual.yMax);
}); });
});
it('scrolls bottom by 0', () => { it('scrolls bottom by 0', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, '0'); await keys.press(targetTab.id, '0');
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.x).to.be.equals(0); expect(actual.x).to.be.equals(0);
}); });
});
it('scrolls bottom by $', () => { it('scrolls bottom by $', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, '$'); await keys.press(targetTab.id, '$');
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.x).to.be.equals(actual.xMax); expect(actual.x).to.be.equals(actual.xMax);
}); });
});
it('scrolls bottom by <C-U>', () => { it('scrolls bottom by <C-U>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'u', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'u', { ctrlKey: true }); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.closeTo(before.y - before.frameHeight / 2, 1); expect(actual.y).to.closeTo(before.y - before.frameHeight / 2, 1);
}); });
});
it('scrolls bottom by <C-D>', () => { it('scrolls bottom by <C-D>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'd', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'd', { ctrlKey: true }); let actual = await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.closeTo(before.y + before.frameHeight / 2, 1); expect(actual.y).to.closeTo(before.y + before.frameHeight / 2, 1);
}); });
});
it('scrolls bottom by <C-B>', () => { it('scrolls bottom by <C-B>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'b', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'b', { ctrlKey: true }); let actual = await await scrolls.get(targetTab.id);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.equals(before.y - before.frameHeight); expect(actual.y).to.equals(before.y - before.frameHeight);
}); });
});
it('scrolls bottom by <C-F>', () => { it('scrolls bottom by <C-F>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'f', { ctrlKey: true });
before = scroll; let actual = await scrolls.get(targetTab.id);
return keys.press(targetTab.id, 'f', { ctrlKey: true });
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.equals(before.y + before.frameHeight); expect(actual.y).to.equals(before.y + before.frameHeight);
}); });
}); });
});

@ -6,260 +6,161 @@ import { CLIENT_URL } from '../web-server/url';
describe("tab test", () => { describe("tab test", () => {
let targetWindow; let targetWindow;
beforeEach(() => { beforeEach(async () => {
return windows.create(CLIENT_URL).then((win) => { targetWindow = await windows.create(CLIENT_URL);
targetWindow = win;
});
}); });
afterEach(() => { afterEach(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
it('deletes tab by d', () => { it('deletes tab by d', async () => {
let before; let tab = await tabs.create(targetWindow.id, CLIENT_URL);
let targetTab; let before = await windows.get(targetWindow.id);
return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { await keys.press(tab.id, 'd');
targetTab = tab;
return windows.get(targetWindow.id); let actual = await windows.get(targetWindow.id);
}).then((win) => {
before = win;
return keys.press(targetTab.id, 'd');
}).then(() => {
return windows.get(targetWindow.id);
}).then((actual) => {
expect(actual.tabs).to.have.lengthOf(before.tabs.length - 1); expect(actual.tabs).to.have.lengthOf(before.tabs.length - 1);
}); });
});
it('duplicates tab by zd', () => { it('duplicates tab by zd', async () => {
let before; let tab = await tabs.create(targetWindow.id, CLIENT_URL);
let targetTab; let before = await windows.get(targetWindow.id)
return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { await keys.press(tab.id, 'z');
targetTab = tab; await keys.press(tab.id, 'd');
return windows.get(targetWindow.id)
}).then((win) => {; let actual = await windows.get(targetWindow.id);
before = win;
return keys.press(targetTab.id, 'z');
}).then(() => {
return keys.press(targetTab.id, 'd');
}).then(() => {
return windows.get(targetWindow.id);
}).then((actual) => {
expect(actual.tabs).to.have.lengthOf(before.tabs.length + 1); expect(actual.tabs).to.have.lengthOf(before.tabs.length + 1);
}); });
})
it('makes pinned by zp', async () => {
it('makes pinned by zp', () => { let tab = await tabs.create(targetWindow.id, CLIENT_URL);
let before; let before = await windows.get(targetWindow.id);
let targetTab; await keys.press(tab.id, 'z');
return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { await keys.press(tab.id, 'p');
targetTab = tab;
return windows.get(targetWindow.id) let actual = await windows.get(targetWindow.id);
}).then((win) => {;
before = win;
return keys.press(targetTab.id, 'z');
}).then(() => {
return keys.press(targetTab.id, 'p');
}).then(() => {
return windows.get(targetWindow.id);
}).then((actual) => {
expect(actual.tabs[0].pinned).to.be.true; expect(actual.tabs[0].pinned).to.be.true;
}); });
})
it('selects previous tab by K', async () => {
it('selects previous tab by K', () => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#2');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#3');
}).then(() => { let tab = await tabs.selectAt(targetWindow.id, 2);
return tabs.create(targetWindow.id, CLIENT_URL + '#2') await keys.press(tab.id, 'K', { shiftKey: true });
}).then(() => {
return tabs.create(targetWindow.id, CLIENT_URL + '#3'); let win = await windows.get(targetWindow.id);
}).then(() => {
return tabs.selectAt(targetWindow.id, 2);
}).then((tab) => {
return keys.press(tab.id, 'K', { shiftKey: true });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[1].active).to.be.true; expect(win.tabs[1].active).to.be.true;
}); });
});
it('selects previous tab by K rotatory', () => { it('selects previous tab by K rotatory', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') let tab = await tabs.selectAt(targetWindow.id, 0);
}).then(() => { await keys.press(tab.id, 'K', { shiftKey: true });
return tabs.create(targetWindow.id, CLIENT_URL + '#3');
}).then(() => { let win = await windows.get(targetWindow.id);
return tabs.selectAt(targetWindow.id, 0);
}).then((tab) => {
return keys.press(tab.id, 'K', { shiftKey: true });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[3].active).to.be.true; expect(win.tabs[3].active).to.be.true;
}); });
});
it('selects next tab by J', () => { it('selects next tab by J', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') let tab = await tabs.selectAt(targetWindow.id, 2);
}).then(() => { await keys.press(tab.id, 'J', { shiftKey: true });
return tabs.create(targetWindow.id, CLIENT_URL + '#3');
}).then(() => { let win = await windows.get(targetWindow.id);
return tabs.selectAt(targetWindow.id, 2);
}).then((tab) => {
return keys.press(tab.id, 'J', { shiftKey: true });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[3].active).to.be.true; expect(win.tabs[3].active).to.be.true;
}); });
});
it('selects previous tab by J rotatory', () => { it('selects previous tab by J rotatory', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') let tab = await tabs.selectAt(targetWindow.id, 3);
}).then(() => { await keys.press(tab.id, 'J', { shiftKey: true });
return tabs.create(targetWindow.id, CLIENT_URL + '#3');
}).then(() => { let win = await windows.get(targetWindow.id);
return tabs.selectAt(targetWindow.id, 3);
}).then((tab) => {
return keys.press(tab.id, 'J', { shiftKey: true });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[0].active).to.be.true; expect(win.tabs[0].active).to.be.true;
}); });
});
it('selects first tab by g0', () => { it('selects first tab by g0', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') let tab = await tabs.selectAt(targetWindow.id, 2);
}).then(() => { await keys.press(tab.id, 'g');
return tabs.create(targetWindow.id, CLIENT_URL + '#3'); await keys.press(tab.id, '0');
}).then(() => {
return tabs.selectAt(targetWindow.id, 2); let win = await windows.get(targetWindow.id);
}).then((tab) => {
return keys.press(tab.id, 'g').then(() => tab);
}).then((tab) => {
return keys.press(tab.id, '0');
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[0].active).to.be.true; expect(win.tabs[0].active).to.be.true;
}); });
});
it('selects last tab by g$', () => { it('selects last tab by g$', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') let tab = await tabs.selectAt(targetWindow.id, 2);
}).then(() => { await keys.press(tab.id, 'g');
return tabs.create(targetWindow.id, CLIENT_URL + '#3'); await keys.press(tab.id, '$');
}).then(() => {
return tabs.selectAt(targetWindow.id, 2); let win = await windows.get(targetWindow.id);
}).then((tab) => {
return keys.press(tab.id, 'g').then(() => tab);
}).then((tab) => {
return keys.press(tab.id, '$');
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[3].active).to.be.true; expect(win.tabs[3].active).to.be.true;
}); });
});
it('selects last selected tab by <C-6>', () => { it('selects last selected tab by <C-6>', async () => {
return Promise.resolve().then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1') await tabs.create(targetWindow.id, CLIENT_URL + '#2');
}).then(() => { await tabs.create(targetWindow.id, CLIENT_URL + '#3');
return tabs.create(targetWindow.id, CLIENT_URL + '#2') await tabs.selectAt(targetWindow.id, 1);
}).then(() => { let tab = await tabs.selectAt(targetWindow.id, 3);
return tabs.create(targetWindow.id, CLIENT_URL + '#3'); await keys.press(tab.id, '6', { ctrlKey: true });
}).then(() => {
return tabs.selectAt(targetWindow.id, 1); let win = await windows.get(targetWindow.id);
}).then(() => {
return tabs.selectAt(targetWindow.id, 3);
}).then((tab) => {
return keys.press(tab.id, '6', { ctrlKey: true });
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs[1].active).to.be.true; expect(win.tabs[1].active).to.be.true;
}); });
});
it('deletes tab by d', () => { it('deletes tab by d', async () => {
return Promise.resolve().then(() => { let tab = await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1'); await keys.press(tab.id, 'd');
}).then((tab) => {
return keys.press(tab.id, 'd'); let win = await windows.get(targetWindow.id);
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs).to.have.lengthOf(1); expect(win.tabs).to.have.lengthOf(1);
}); });
});
it('reopen tab by u', () => { it('reopen tab by u', async () => {
return Promise.resolve().then(() => { let tab = await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1'); await keys.press(tab.id, 'd');
}).then((tab) => {
return keys.press(tab.id, 'd'); let win = await windows.get(targetWindow.id);
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs).to.have.lengthOf(1); expect(win.tabs).to.have.lengthOf(1);
return keys.press(win.tabs[0].id, 'u');
}).then(() => { await keys.press(win.tabs[0].id, 'u');
return new Promise((resolve) => setTimeout(resolve, 100)); await new Promise((resolve) => setTimeout(resolve, 100));
}).then(() => {
return windows.get(targetWindow.id); win = await windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs).to.have.lengthOf(2); expect(win.tabs).to.have.lengthOf(2);
}); });
});
it('does not delete pinned tab by d', () => { it('does not delete pinned tab by d', async () => {
return Promise.resolve().then(() => { let tab = await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return tabs.create(targetWindow.id, CLIENT_URL + '#1'); tab = await tabs.update(tab.id, { pinned: true });
}).then((tab) => { await keys.press(tab.id, 'd');
return tabs.update(tab.id, { pinned: true });
}).then((tab) => { let win = await windows.get(targetWindow.id);
return keys.press(tab.id, 'd');
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs).to.have.lengthOf(2); expect(win.tabs).to.have.lengthOf(2);
}); });
});
it('deletes pinned tab by !d', () => { it('deletes pinned tab by !d', async () => {
let target; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '#1');
return Promise.resolve().then(() => { tab = await tabs.update(tab.id, { pinned: true });
return tabs.create(targetWindow.id, CLIENT_URL + '#1'); await keys.press(tab.id, '!');
}).then((tab) => { await keys.press(tab.id, 'd');
return tabs.update(tab.id, { pinned: true });
}).then((tab) => { let win = await windows.get(targetWindow.id);
target = tab;
return keys.press(target.id, '!');
}).then(() => {
return keys.press(target.id, 'd');
}).then(() => {
return windows.get(targetWindow.id);
}).then((win) => {
expect(win.tabs).to.have.lengthOf(1); expect(win.tabs).to.have.lengthOf(1);
}); });
}); });
});

@ -7,64 +7,44 @@ describe("zoom test", () => {
let targetWindow; let targetWindow;
let targetTab; let targetTab;
before(() => { before(async () => {
return windows.create(CLIENT_URL).then((win) => { targetWindow = await windows.create(CLIENT_URL);
targetWindow = win;
});
}); });
after(() => { after(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
beforeEach(() => { beforeEach(async () => {
return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { targetTab = await tabs.create(targetWindow.id, CLIENT_URL);
targetTab = tab;
});
}); });
it('zooms-in by zi', () => { it('zooms-in by zi', async () => {
let before; let before = await tabs.getZoom(targetTab.id);
return tabs.getZoom(targetTab.id).then((zoom) => { await keys.press(targetTab.id, 'z');
before = zoom; await keys.press(targetTab.id, 'i');
return keys.press(targetTab.id, 'z');
}).then(() => { let actual = await tabs.getZoom(targetTab.id);
return keys.press(targetTab.id, 'i');
}).then(() => {
return tabs.getZoom(targetTab.id);
}).then((actual) => {
expect(actual).to.be.greaterThan(before); expect(actual).to.be.greaterThan(before);
}); });
});
it('zooms-in by zo', () => { it('zooms-in by zo', async () => {
let before; let before = await tabs.getZoom(targetTab.id);
return tabs.getZoom(targetTab.id).then((zoom) => { await keys.press(targetTab.id, 'z');
before = zoom; await keys.press(targetTab.id, 'o');
return keys.press(targetTab.id, 'z');
}).then(() => { let actual = await tabs.getZoom(targetTab.id);
return keys.press(targetTab.id, 'o');
}).then(() => {
return tabs.getZoom(targetTab.id);
}).then((actual) => {
expect(actual).to.be.lessThan(before); expect(actual).to.be.lessThan(before);
}); });
});
it('zooms-in by zz', () => { it('zooms-in by zz', async () => {
let before; await tabs.setZoom(targetTab.id, 1.5);
tabs.setZoom(targetTab.id, 1.5).then(() => { let before = await tabs.getZoom(targetTab.id);
return tabs.getZoom(targetTab.id); await keys.press(targetTab.id, 'z');
}).then((zoom) => { await keys.press(targetTab.id, 'z');
before = zoom;
return keys.press(targetTab.id, 'z'); let actual = await tabs.getZoom(targetTab.id);
}).then(() => {
return keys.press(targetTab.id, 'z');
}).then(() => {
return tabs.getZoom(targetTab.id);
}).then((actual) => {
expect(actual).to.be.lessThan(before); expect(actual).to.be.lessThan(before);
expect(actual).to.be.be(1); expect(actual).to.equal(1);
});
}); });
}); });

@ -5,56 +5,63 @@ import * as bookmarks from '../shared/bookmarks';
import * as parsers from 'shared/commands/parsers'; import * as parsers from 'shared/commands/parsers';
import * as properties from 'shared/settings/properties'; import * as properties from 'shared/settings/properties';
const openCommand = (url) => { const openCommand = async(url) => {
return browser.tabs.query({ let got = await browser.tabs.query({
active: true, currentWindow: true active: true, currentWindow: true
}).then((gotTabs) => {
if (gotTabs.length > 0) {
return browser.tabs.update(gotTabs[0].id, { url: url });
}
}); });
if (got.length > 0) {
return browser.tabs.update(got[0].id, { url: url });
}
}; };
const tabopenCommand = (url) => { const tabopenCommand = (url) => {
return browser.tabs.create({ url: url }); return browser.tabs.create({ url: url });
}; };
const tabcloseCommand = () => { const tabcloseCommand = async() => {
return browser.tabs.query({ let got = await browser.tabs.query({
active: true, currentWindow: true active: true, currentWindow: true
}).then((tabList) => {
return browser.tabs.remove(tabList.map(tab => tab.id));
}); });
return browser.tabs.remove(got.map(tab => tab.id));
}; };
const winopenCommand = (url) => { const winopenCommand = (url) => {
return browser.windows.create({ url }); return browser.windows.create({ url });
}; };
const bufferCommand = (keywords) => { const bufferCommand = async(keywords) => {
if (keywords.length === 0) { if (keywords.length === 0) {
return Promise.resolve([]); return Promise.resolve([]);
} }
let keywordsStr = keywords.join(' '); let keywordsStr = keywords.join(' ');
return browser.tabs.query({ let got = await browser.tabs.query({
active: true, currentWindow: true active: true, currentWindow: true
}).then((gotTabs) => { });
if (gotTabs.length > 0) { if (got.length === 0) {
return;
}
if (isNaN(keywordsStr)) { if (isNaN(keywordsStr)) {
return tabs.selectByKeyword(gotTabs[0], keywordsStr); return tabs.selectByKeyword(got[0], keywordsStr);
} }
let index = parseInt(keywordsStr, 10) - 1; let index = parseInt(keywordsStr, 10) - 1;
return tabs.selectAt(index); return tabs.selectAt(index);
}
});
}; };
const addBookmarkCommand = (tab, args) => { const addbookmarkCommand = async(tab, args) => {
if (!args[0]) { if (!args[0]) {
return Promise.resolve(); return;
} }
let item = await bookmarks.create(args.join(' '), tab.url);
return bookmarks.create(args.join(' '), tab.url); if (!item) {
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_ERROR,
text: 'Could not create a bookmark',
});
}
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_INFO,
text: 'Saved current page: ' + item.url,
});
}; };
const setCommand = (args) => { const setCommand = (args) => {
@ -100,18 +107,7 @@ const exec = (tab, line, settings) => {
case 'bdeletes!': case 'bdeletes!':
return tabs.closeTabsByKeywordsForce(args.join(' ')); return tabs.closeTabsByKeywordsForce(args.join(' '));
case 'addbookmark': case 'addbookmark':
return addBookmarkCommand(tab, args).then((item) => { return addbookmarkCommand(tab, args);
if (!item) {
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_ERROR,
text: 'Could not create a bookmark',
});
}
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_INFO,
text: 'Saved current page: ' + item.url,
});
});
case 'set': case 'set':
return setCommand(args); return setCommand(args);
case 'q': case 'q':

@ -1,13 +1,12 @@
import actions from '../actions'; import actions from '../actions';
import * as settingsStorage from 'shared/settings/storage'; import * as settingsStorage from 'shared/settings/storage';
const load = () => { const load = async() => {
return settingsStorage.loadValue().then((value) => { let value = await settingsStorage.loadValue();
return { return {
type: actions.SETTING_SET_SETTINGS, type: actions.SETTING_SET_SETTINGS,
value, value,
}; };
});
}; };
const setProperty = (name, value) => { const setProperty = (name, value) => {

@ -1,19 +1,20 @@
import actions from './index'; import actions from './index';
const openNewTab = (url, openerTabId, background = false, adjacent = false) => { const openNewTab = async(
if (adjacent) { url, openerTabId, background = false, adjacent = false
return browser.tabs.query({ ) => {
if (!adjacent) {
return browser.tabs.create({ url, active: !background });
}
let tabs = await browser.tabs.query({
active: true, currentWindow: true active: true, currentWindow: true
}).then((tabs) => { });
return browser.tabs.create({ return browser.tabs.create({
url, url,
openerTabId, openerTabId,
active: !background, active: !background,
index: tabs[0].index + 1 index: tabs[0].index + 1
}); });
});
}
return browser.tabs.create({ url, active: !background });
}; };
const openToTab = (url, tab) => { const openToTab = (url, tab) => {

@ -56,13 +56,12 @@ export default class BackgroundComponent {
} }
} }
broadcastSettingsChanged() { async broadcastSettingsChanged() {
return browser.tabs.query({}).then((tabs) => { let tabs = await browser.tabs.query({});
for (let tab of tabs) { for (let tab of tabs) {
browser.tabs.sendMessage(tab.id, { browser.tabs.sendMessage(tab.id, {
type: messages.SETTINGS_CHANGED, type: messages.SETTINGS_CHANGED,
}); });
} }
});
} }
} }

@ -8,19 +8,17 @@ export default class IndicatorComponent {
messages.onMessage(this.onMessage.bind(this)); messages.onMessage(this.onMessage.bind(this));
browser.browserAction.onClicked.addListener(this.onClicked); browser.browserAction.onClicked.addListener(this.onClicked);
browser.tabs.onActivated.addListener((info) => { browser.tabs.onActivated.addListener(async(info) => {
return browser.tabs.query({ currentWindow: true }).then(() => { await browser.tabs.query({ currentWindow: true });
return this.onTabActivated(info); return this.onTabActivated(info);
}); });
});
} }
onTabActivated(info) { async onTabActivated(info) {
return browser.tabs.sendMessage(info.tabId, { let { enabled } = await browser.tabs.sendMessage(info.tabId, {
type: messages.ADDON_ENABLED_QUERY, type: messages.ADDON_ENABLED_QUERY,
}).then((resp) => {
return this.updateIndicator(resp.enabled);
}); });
return this.updateIndicator(enabled);
} }
onClicked(tab) { onClicked(tab) {

@ -4,11 +4,10 @@ export default class TabComponent {
constructor(store) { constructor(store) {
this.store = store; this.store = store;
browser.tabs.onActivated.addListener((info) => { browser.tabs.onActivated.addListener(async(info) => {
return browser.tabs.query({ currentWindow: true }).then(() => { await browser.tabs.query({ currentWindow: true });
return this.onTabActivated(info); return this.onTabActivated(info);
}); });
});
} }
onTabActivated(info) { onTabActivated(info) {

@ -18,6 +18,15 @@ const store = createStore(reducers, (e, sender) => {
} }
}); });
const checkAndNotifyUpdated = async() => {
let updated = await versions.checkUpdated();
if (!updated) {
return;
}
await versions.notify();
await versions.commit();
};
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
const backgroundComponent = new BackgroundComponent(store); const backgroundComponent = new BackgroundComponent(store);
const operationComponent = new OperationComponent(store); const operationComponent = new OperationComponent(store);
@ -27,11 +36,4 @@ const indicatorComponent = new IndicatorComponent(store);
store.dispatch(settingActions.load()); store.dispatch(settingActions.load());
versions.checkUpdated().then((updated) => { checkAndNotifyUpdated();
if (!updated) {
return;
}
return versions.notify();
}).then(() => {
return versions.commit();
});

@ -1,5 +1,5 @@
const getCompletions = (keywords) => { const getCompletions = async(keywords) => {
return browser.bookmarks.search({ query: keywords }).then((items) => { let items = await browser.bookmarks.search({ query: keywords });
return items.filter((item) => { return items.filter((item) => {
let url = undefined; let url = undefined;
try { try {
@ -9,7 +9,6 @@ const getCompletions = (keywords) => {
} }
return item.type === 'bookmark' && url.protocol !== 'place:'; return item.type === 'bookmark' && url.protocol !== 'place:';
}).slice(0, 10); }).slice(0, 10);
});
}; };
export { getCompletions }; export { getCompletions };

@ -61,11 +61,11 @@ const reduceByOrigin = (items, min) => {
return filtered; return filtered;
}; };
const getCompletions = (keyword) => { const getCompletions = async(keyword) => {
return browser.history.search({ let historyItems = await browser.history.search({
text: keyword, text: keyword,
startTime: 0, startTime: 0,
}).then((historyItems) => { });
return [historyItems.map(item => [item, new URL(item.url)])] return [historyItems.map(item => [item, new URL(item.url)])]
.map(filterEmptyTitle) .map(filterEmptyTitle)
.map(filterHttp) .map(filterHttp)
@ -77,7 +77,6 @@ const getCompletions = (keyword) => {
.slice(0, 10) .slice(0, 10)
.map(item => item[0]) .map(item => item[0])
)[0]; )[0];
});
}; };
export { getCompletions }; export { getCompletions };

@ -12,36 +12,30 @@ const getSearchCompletions = (command, keywords, searchConfig) => {
return Promise.resolve(engineItems); return Promise.resolve(engineItems);
}; };
const getHistoryCompletions = (command, keywords) => { const getHistoryCompletions = async(command, keywords) => {
return histories.getCompletions(keywords).then((pages) => { let items = await histories.getCompletions(keywords);
return pages.map((page) => { return items.map((page) => {
return { return {
caption: page.title, caption: page.title,
content: command + ' ' + page.url, content: command + ' ' + page.url,
url: page.url url: page.url
}; };
}); });
});
}; };
const getBookmarksCompletions = (command, keywords) => { const getBookmarksCompletions = async(command, keywords) => {
return bookmarks.getCompletions(keywords).then((items) => { let items = await bookmarks.getCompletions(keywords);
return items.map((item) => { return items.map(item => ({
return {
caption: item.title, caption: item.title,
content: command + ' ' + item.url, content: command + ' ' + item.url,
url: item.url, url: item.url,
}; }));
});
});
}; };
const getOpenCompletions = (command, keywords, searchConfig) => { const getOpenCompletions = async(command, keywords, searchConfig) => {
return Promise.all([ let engineItems = await getSearchCompletions(command, keywords, searchConfig);
getSearchCompletions(command, keywords, searchConfig), let historyItems = await getHistoryCompletions(command, keywords);
getHistoryCompletions(command, keywords), let bookmarkItems = await getBookmarksCompletions(command, keywords);
getBookmarksCompletions(command, keywords),
]).then(([engineItems, historyItems, bookmarkItems]) => {
let completions = []; let completions = [];
if (engineItems.length > 0) { if (engineItems.length > 0) {
completions.push({ completions.push({
@ -62,26 +56,22 @@ const getOpenCompletions = (command, keywords, searchConfig) => {
}); });
} }
return completions; return completions;
});
}; };
const getBufferCompletions = (command, keywords, excludePinned) => { const getBufferCompletions = async(command, keywords, excludePinned) => {
return tabs.getCompletions(keywords, excludePinned).then((got) => { let items = await tabs.getCompletions(keywords, excludePinned);
let items = got.map((tab) => { items = items.map(tab => ({
return {
caption: tab.title, caption: tab.title,
content: command + ' ' + tab.title, content: command + ' ' + tab.title,
url: tab.url, url: tab.url,
icon: tab.favIconUrl icon: tab.favIconUrl
}; }));
});
return [ return [
{ {
name: 'Buffers', name: 'Buffers',
items: items items: items
} }
]; ];
});
}; };
const getCompletions = (line, settings) => { const getCompletions = (line, settings) => {

@ -1,69 +1,60 @@
import * as tabCompletions from './completions/tabs'; import * as tabCompletions from './completions/tabs';
const closeTab = (id) => { const closeTab = async(id) => {
return browser.tabs.get(id).then((tab) => { let tab = await browser.tabs.get(id);
if (!tab.pinned) { if (!tab.pinned) {
return browser.tabs.remove(id); return browser.tabs.remove(id);
} }
});
}; };
const closeTabForce = (id) => { const closeTabForce = (id) => {
return browser.tabs.remove(id); return browser.tabs.remove(id);
}; };
const queryByKeyword = (keyword, excludePinned = false) => { const queryByKeyword = async(keyword, excludePinned = false) => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => { return tabs.filter((t) => {
return t.url.toLowerCase().includes(keyword.toLowerCase()) || return t.url.toLowerCase().includes(keyword.toLowerCase()) ||
t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); t.title && t.title.toLowerCase().includes(keyword.toLowerCase());
}).filter((t) => { }).filter((t) => {
return !(excludePinned && t.pinned); return !(excludePinned && t.pinned);
}); });
});
}; };
const closeTabByKeywords = (keyword) => { const closeTabByKeywords = async(keyword) => {
return queryByKeyword(keyword, false).then((tabs) => { let tabs = await queryByKeyword(keyword, false);
if (tabs.length === 0) { if (tabs.length === 0) {
throw new Error('No matching buffer for ' + keyword); throw new Error('No matching buffer for ' + keyword);
} else if (tabs.length > 1) { } else if (tabs.length > 1) {
throw new Error('More than one match for ' + keyword); throw new Error('More than one match for ' + keyword);
} }
browser.tabs.remove(tabs[0].id); return browser.tabs.remove(tabs[0].id);
});
}; };
const closeTabByKeywordsForce = (keyword) => { const closeTabByKeywordsForce = async(keyword) => {
return queryByKeyword(keyword, true).then((tabs) => { let tabs = await queryByKeyword(keyword, true);
if (tabs.length === 0) { if (tabs.length === 0) {
throw new Error('No matching buffer for ' + keyword); throw new Error('No matching buffer for ' + keyword);
} else if (tabs.length > 1) { } else if (tabs.length > 1) {
throw new Error('More than one match for ' + keyword); throw new Error('More than one match for ' + keyword);
} }
browser.tabs.remove(tabs[0].id); return browser.tabs.remove(tabs[0].id);
});
}; };
const closeTabsByKeywords = (keyword) => { const closeTabsByKeywords = async(keyword) => {
tabCompletions.getCompletions(keyword).then((tabs) => { let tabs = await tabCompletions.getCompletions(keyword);
let tabs2 = tabs.filter(tab => !tab.pinned); tabs = tabs.filter(tab => !tab.pinned);
browser.tabs.remove(tabs2.map(tab => tab.id)); return browser.tabs.remove(tabs.map(tab => tab.id));
});
}; };
const closeTabsByKeywordsForce = (keyword) => { const closeTabsByKeywordsForce = async(keyword) => {
tabCompletions.getCompletions(keyword).then((tabs) => { let tabs = await tabCompletions.getCompletions(keyword);
browser.tabs.remove(tabs.map(tab => tab.id)); return browser.tabs.remove(tabs.map(tab => tab.id));
});
}; };
const reopenTab = () => { const reopenTab = async() => {
let window = null; let window = await browser.windows.getCurrent();
return browser.windows.getCurrent().then().then((w) => { let sessions = await browser.sessions.getRecentlyClosed();
window = w;
return browser.sessions.getRecentlyClosed();
}).then((sessions) => {
let session = sessions.find((s) => { let session = sessions.find((s) => {
return s.tab && s.tab.windowId === window.id; return s.tab && s.tab.windowId === window.id;
}); });
@ -74,11 +65,10 @@ const reopenTab = () => {
return browser.sessions.restore(session.tab.sessionId); return browser.sessions.restore(session.tab.sessionId);
} }
return browser.sessions.restore(session.window.sessionId); return browser.sessions.restore(session.window.sessionId);
});
}; };
const selectAt = (index) => { const selectAt = async(index) => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
if (tabs.length < 2) { if (tabs.length < 2) {
return; return;
} }
@ -87,11 +77,10 @@ const selectAt = (index) => {
} }
let id = tabs[index].id; let id = tabs[index].id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
});
}; };
const selectByKeyword = (current, keyword) => { const selectByKeyword = async(current, keyword) => {
return queryByKeyword(keyword).then((tabs) => { let tabs = await queryByKeyword(keyword);
if (tabs.length === 0) { if (tabs.length === 0) {
throw new RangeError('No matching buffer for ' + keyword); throw new RangeError('No matching buffer for ' + keyword);
} }
@ -101,43 +90,38 @@ const selectByKeyword = (current, keyword) => {
} }
} }
return browser.tabs.update(tabs[0].id, { active: true }); return browser.tabs.update(tabs[0].id, { active: true });
});
}; };
const selectPrevTab = (current, count) => { const selectPrevTab = async(current, count) => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
if (tabs.length < 2) { if (tabs.length < 2) {
return; return;
} }
let select = (current - count + tabs.length) % tabs.length; let select = (current - count + tabs.length) % tabs.length;
let id = tabs[select].id; let id = tabs[select].id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
});
}; };
const selectNextTab = (current, count) => { const selectNextTab = async(current, count) => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
if (tabs.length < 2) { if (tabs.length < 2) {
return; return;
} }
let select = (current + count) % tabs.length; let select = (current + count) % tabs.length;
let id = tabs[select].id; let id = tabs[select].id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
});
}; };
const selectFirstTab = () => { const selectFirstTab = async() => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
let id = tabs[0].id; let id = tabs[0].id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
});
}; };
const selectLastTab = () => { const selectLastTab = async() => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => { let tabs = await browser.tabs.query({ currentWindow: true });
let id = tabs[tabs.length - 1].id; let id = tabs[tabs.length - 1].id;
return browser.tabs.update(id, { active: true }); return browser.tabs.update(id, { active: true });
});
}; };
const selectTab = (id) => { const selectTab = (id) => {
@ -152,14 +136,11 @@ const reload = (current, cache) => {
}; };
const updateTabPinned = (current, pinned) => { const updateTabPinned = (current, pinned) => {
return browser.tabs.query({ currentWindow: true, active: true }) return browser.tabs.update(current.id, { pinned });
.then(() => {
return browser.tabs.update(current.id, { pinned: pinned });
});
}; };
const toggleTabPinned = (current) => { const toggleTabPinned = (current) => {
updateTabPinned(current, !current.pinned); return updateTabPinned(current, !current.pinned);
}; };
const duplicate = (id) => { const duplicate = (id) => {

@ -9,26 +9,20 @@ const ZOOM_SETTINGS = [
1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00
]; ];
const zoomIn = (tabId = undefined) => { const zoomIn = async(tabId = undefined) => {
return browser.tabs.getZoom(tabId).then((factor) => { let current = await browser.tabs.getZoom(tabId);
for (let f of ZOOM_SETTINGS) { let factor = ZOOM_SETTINGS.find(f => f > current);
if (f > factor) { if (factor) {
browser.tabs.setZoom(tabId, f); return browser.tabs.setZoom(tabId, factor);
break;
} }
}
});
}; };
const zoomOut = (tabId = undefined) => { const zoomOut = async(tabId = undefined) => {
return browser.tabs.getZoom(tabId).then((factor) => { let current = await browser.tabs.getZoom(tabId);
for (let f of [].concat(ZOOM_SETTINGS).reverse()) { let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current);
if (f < factor) { if (factor) {
browser.tabs.setZoom(tabId, f); return browser.tabs.setZoom(tabId, factor);
break;
}
} }
});
}; };
const neutral = (tabId = undefined) => { const neutral = (tabId = undefined) => {

@ -107,16 +107,15 @@ export default class ConsoleComponent {
} }
} }
onInput(e) { async onInput(e) {
this.store.dispatch(consoleActions.setConsoleText(e.target.value)); this.store.dispatch(consoleActions.setConsoleText(e.target.value));
let source = e.target.value; let source = e.target.value;
return browser.runtime.sendMessage({ let completions = await browser.runtime.sendMessage({
type: messages.CONSOLE_QUERY_COMPLETIONS, type: messages.CONSOLE_QUERY_COMPLETIONS,
text: source, text: source,
}).then((completions) => {
this.store.dispatch(consoleActions.setCompletions(source, completions));
}); });
this.store.dispatch(consoleActions.setCompletions(source, completions));
} }
onInputShown(state) { onInputShown(state) {

@ -35,35 +35,34 @@ const find = (string, backwards) => {
// NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work
// because of same origin policy // because of same origin policy
let found = window.find(string, caseSensitive, backwards, wrapScan);
if (found) {
return found;
}
window.getSelection().removeAllRanges();
return window.find(string, caseSensitive, backwards, wrapScan); return window.find(string, caseSensitive, backwards, wrapScan);
}; };
const findNext = (currentKeyword, reset, backwards) => { const findNext = async(currentKeyword, reset, backwards) => {
if (reset) { if (reset) {
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
} }
let promise = Promise.resolve(currentKeyword); let keyword = currentKeyword;
if (currentKeyword) { if (currentKeyword) {
browser.runtime.sendMessage({ browser.runtime.sendMessage({
type: messages.FIND_SET_KEYWORD, type: messages.FIND_SET_KEYWORD,
keyword: currentKeyword, keyword: currentKeyword,
}); });
} else { } else {
promise = browser.runtime.sendMessage({ keyword = await browser.runtime.sendMessage({
type: messages.FIND_GET_KEYWORD, type: messages.FIND_GET_KEYWORD,
}); });
} }
return promise.then((keyword) => {
if (!keyword) { if (!keyword) {
return postNoPrevious(); return postNoPrevious();
} }
let found = find(keyword, backwards); let found = find(keyword, backwards);
if (!found) {
window.getSelection().removeAllRanges();
found = find(keyword, backwards);
}
if (found) { if (found) {
postPatternFound(keyword); postPatternFound(keyword);
} else { } else {
@ -75,7 +74,6 @@ const findNext = (currentKeyword, reset, backwards) => {
keyword, keyword,
found, found,
}; };
});
}; };
const next = (currentKeyword, reset) => { const next = (currentKeyword, reset) => {

@ -44,15 +44,16 @@ export default class Common {
} }
} }
reloadSettings() { async reloadSettings() {
browser.runtime.sendMessage({ try {
let settings = await browser.runtime.sendMessage({
type: messages.SETTINGS_QUERY, type: messages.SETTINGS_QUERY,
}).then((settings) => { });
this.store.dispatch(settingActions.set(settings)); this.store.dispatch(settingActions.set(settings));
}).catch((e) => { } catch (e) {
// Sometime sendMessage fails when background script is not ready. // Sometime sendMessage fails when background script is not ready.
console.warn(e); console.warn(e);
setTimeout(() => this.reloadSettings(), 500); setTimeout(() => this.reloadSettings(), 500);
}); }
} }
} }

@ -4,20 +4,17 @@ import DefaultSettings from 'shared/settings/default';
import * as settingsStorage from 'shared/settings/storage'; import * as settingsStorage from 'shared/settings/storage';
import * as settingsValues from 'shared/settings/values'; import * as settingsValues from 'shared/settings/values';
const load = () => { const load = async() => {
return settingsStorage.loadRaw().then((settings) => { let settings = await settingsStorage.loadRaw();
return set(settings); return set(settings);
});
}; };
const save = (settings) => { const save = async(settings) => {
return settingsStorage.save(settings).then(() => { await settingsStorage.save(settings);
return browser.runtime.sendMessage({ await browser.runtime.sendMessage({
type: messages.SETTINGS_RELOAD type: messages.SETTINGS_RELOAD
}); });
}).then(() => {
return set(settings); return set(settings);
});
}; };
const set = (settings) => { const set = (settings) => {

@ -1,17 +1,16 @@
import DefaultSettings from './default'; import DefaultSettings from './default';
import * as settingsValues from './values'; import * as settingsValues from './values';
const loadRaw = () => { const loadRaw = async() => {
return browser.storage.local.get('settings').then(({ settings }) => { let { settings } = await browser.storage.local.get('settings');
if (!settings) { if (!settings) {
return DefaultSettings; return DefaultSettings;
} }
return Object.assign({}, DefaultSettings, settings); return Object.assign({}, DefaultSettings, settings);
});
}; };
const loadValue = () => { const loadValue = async() => {
return loadRaw().then((settings) => { let settings = await loadRaw();
let value = JSON.parse(DefaultSettings.json); let value = JSON.parse(DefaultSettings.json);
if (settings.source === 'json') { if (settings.source === 'json') {
value = settingsValues.valueFromJson(settings.json); value = settingsValues.valueFromJson(settings.json);
@ -24,7 +23,6 @@ const loadValue = () => {
return Object.assign({}, return Object.assign({},
settingsValues.valueFromJson(DefaultSettings.json), settingsValues.valueFromJson(DefaultSettings.json),
value); value);
});
}; };
const save = (settings) => { const save = (settings) => {

@ -13,13 +13,12 @@ const notificationClickListener = (id) => {
browser.notifications.onClicked.removeListener(notificationClickListener); browser.notifications.onClicked.removeListener(notificationClickListener);
}; };
const checkUpdated = () => { const checkUpdated = async() => {
return storage.load().then((prev) => { let prev = await storage.load();
if (!prev) { if (!prev) {
return true; return true;
} }
return manifest.version !== prev; return manifest.version !== prev;
});
}; };
const notify = () => { const notify = () => {

@ -1,7 +1,6 @@
const load = () => { const load = async() => {
return browser.storage.local.get('version').then(({ version }) => { let { version } = await browser.storage.local.get('version');
return version; return version;
});
}; };
const save = (version) => { const save = (version) => {

@ -7,49 +7,34 @@ describe("shared/versions/storage", () => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('return true if no previous versions', () => { it('return true if no previous versions', async() => {
return Promise.resolve().then(() => { let updated = await versions.checkUpdated();
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true; expect(updated).to.be.true;
}); });
});
it('return true if updated', () => { it('return true if updated', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: '0.001' });
return browser.storage.local.set({ version: '0.001' }); let updated = await versions.checkUpdated();
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true; expect(updated).to.be.true;
}); });
});
it('return false if not updated', () => { it('return false if not updated', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: manifest.version });
return browser.storage.local.set({ version: manifest.version }); let updated = await versions.checkUpdated();
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.false; expect(updated).to.be.false;
}); });
}); });
});
describe('#commit', () => { describe('#commit', () => {
beforeEach(() => { beforeEach(() => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('saves current version from manifest.json', () => { it('saves current version from manifest.json', async() => {
return Promise.resolve().then(() => { await versions.commit();
return versions.commit(); let { version } = await browser.storage.local.get('version');
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.be.a('string'); expect(version).to.be.a('string');
expect(version).to.equal(manifest.version); expect(version).to.equal(manifest.version);
}); });
}); });
}); });
});

@ -6,34 +6,23 @@ describe("shared/versions/storage", () => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('loads saved version', () => { it('loads saved version', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: '1.2.3' });
return browser.storage.local.set({ version: '1.2.3' }); let version = await storage.load();
}).then(() => {
return storage.load();
}).then((version) => {
expect(version).to.equal('1.2.3'); expect(version).to.equal('1.2.3');
}); });
});
it('returns undefined if no versions in storage', () => { it('returns undefined if no versions in storage', async() => {
return Promise.resolve().then(() => { let version = await storage.load();
return storage.load();
}).then((version) => {
expect(version).to.be.a('undefined'); expect(version).to.be.a('undefined');
}); });
}); });
});
describe('#save', () => { describe('#save', () => {
it('saves version string', () => { it('saves version string', async() => {
return Promise.resolve().then(() => { await storage.save('2.3.4');
return storage.save('2.3.4'); let { version } = await browser.storage.local.get('version');
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.equal('2.3.4'); expect(version).to.equal('2.3.4');
}); });
}); });
}); });
});