From 3f8bbe11d96b751affa9e2bf0a1995008f9e3220 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 11 Feb 2018 15:40:34 +0900 Subject: send press key to tabs --- e2e/contents/tab.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 e2e/contents/tab.test.js (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js new file mode 100644 index 0000000..d33a35f --- /dev/null +++ b/e2e/contents/tab.test.js @@ -0,0 +1,35 @@ +import { expect } from "chai"; +import * as windows from "../ambassador/src/client/windows"; +import * as tabs from "../ambassador/src/client/tabs"; +import * as keys from "../ambassador/src/client/keys"; + +const SERVER_URL = "localhost:11111"; + +describe("tab test", function() { + let targetWindow; + let targetTab; + + before(() => { + return windows.create().then((win) => { + targetWindow = win; + return tabs.create(win.id, SERVER_URL).then((tab) => { + targetTab = tab; + }); + }); + }); + + after(() => { + return windows.remove(targetWindow.id); + }); + + it('delete tab', (done) => { + let before = window.document.documentElement.scrollTop; + keys.press(targetTab.id, 'j').then((r) => { + }); + keys.press(targetTab.id, 'j').then((r) => { + }); + keys.press(targetTab.id, 'G').then((r) => { + }); + let after = window.document.documentElement.scrollTop; + }); +}); -- cgit v1.2.3 From 0904f8e1ebd61d425c3536a7dd02afbffaad0550 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 13 Feb 2018 20:13:27 +0900 Subject: add tab delete test --- e2e/ambassador/src/background/index.js | 5 ++++- e2e/ambassador/src/client/windows.js | 13 +++++++++++-- e2e/ambassador/src/content/index.js | 4 +++- e2e/ambassador/src/shared/messages.js | 2 ++ e2e/contents/tab.test.js | 17 ++++++++--------- 5 files changed, 28 insertions(+), 13 deletions(-) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/ambassador/src/background/index.js b/e2e/ambassador/src/background/index.js index 9e64986..f9fda7e 100644 --- a/e2e/ambassador/src/background/index.js +++ b/e2e/ambassador/src/background/index.js @@ -1,5 +1,6 @@ import { - WINDOWS_CREATE, WINDOWS_REMOVE, TABS_CREATE, + WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET, + TABS_CREATE, EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, } from '../shared/messages'; import * as tabs from './tabs'; @@ -11,6 +12,8 @@ receiveContentMessage((message) => { return browser.windows.create({ url: message.url }); case WINDOWS_REMOVE: return browser.windows.remove(message.windowId); + case WINDOWS_GET: + return browser.windows.get(message.windowId, { populate: true }); case TABS_CREATE: return tabs.create({ url: message.url, diff --git a/e2e/ambassador/src/client/windows.js b/e2e/ambassador/src/client/windows.js index c6ba37a..f92405a 100644 --- a/e2e/ambassador/src/client/windows.js +++ b/e2e/ambassador/src/client/windows.js @@ -1,4 +1,6 @@ -import { WINDOWS_CREATE, WINDOWS_REMOVE } from '../shared/messages'; +import { + WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET +} from '../shared/messages'; import * as ipc from './ipc'; const create = (url) => { @@ -15,4 +17,11 @@ const remove = (windowId) => { }); }; -export { create, remove }; +const get = (windowId) => { + return ipc.send({ + type: WINDOWS_GET, + windowId, + }); +}; + +export { create, remove, get }; diff --git a/e2e/ambassador/src/content/index.js b/e2e/ambassador/src/content/index.js index 0931f93..8573d66 100644 --- a/e2e/ambassador/src/content/index.js +++ b/e2e/ambassador/src/content/index.js @@ -1,5 +1,6 @@ import { - WINDOWS_CREATE, WINDOWS_REMOVE, TABS_CREATE, + WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET, + TABS_CREATE, EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, } from '../shared/messages'; import * as ipc from './ipc'; @@ -8,6 +9,7 @@ ipc.receivePageMessage((message) => { switch (message.type) { case WINDOWS_CREATE: case WINDOWS_REMOVE: + case WINDOWS_GET: case TABS_CREATE: case EVENT_KEYPRESS: case EVENT_KEYDOWN: diff --git a/e2e/ambassador/src/shared/messages.js b/e2e/ambassador/src/shared/messages.js index 1369260..32b7aa2 100644 --- a/e2e/ambassador/src/shared/messages.js +++ b/e2e/ambassador/src/shared/messages.js @@ -2,6 +2,7 @@ const METHOD_REQUEST = 'request'; const METHOD_RESPONSE = 'response'; const WINDOWS_CREATE = 'windows.create'; const WINDOWS_REMOVE = 'windows.remove'; +const WINDOWS_GET = 'windows.get'; const TABS_CREATE = 'tabs.create'; const EVENT_KEYPRESS = 'event.keypress'; const EVENT_KEYDOWN = 'event.keydown'; @@ -13,6 +14,7 @@ export { WINDOWS_CREATE, WINDOWS_REMOVE, + WINDOWS_GET, TABS_CREATE, diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index d33a35f..dda572f 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -5,7 +5,7 @@ import * as keys from "../ambassador/src/client/keys"; const SERVER_URL = "localhost:11111"; -describe("tab test", function() { +describe("tab test", () => { let targetWindow; let targetTab; @@ -22,14 +22,13 @@ describe("tab test", function() { return windows.remove(targetWindow.id); }); - it('delete tab', (done) => { - let before = window.document.documentElement.scrollTop; - keys.press(targetTab.id, 'j').then((r) => { + it('delete tab', () => { + return Promise.resolve().then(() => { + return keys.press(targetTab.id, 'd'); + }).then(() => { + return windows.get(targetWindow.id); + }).then((after) => { + expect(after.tabs).to.have.lengthOf(1); }); - keys.press(targetTab.id, 'j').then((r) => { - }); - keys.press(targetTab.id, 'G').then((r) => { - }); - let after = window.document.documentElement.scrollTop; }); }); -- cgit v1.2.3 From b566cfa0acd3679f13e89edbeb35b2d9b4905814 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 13 Feb 2018 20:54:37 +0900 Subject: add press zd test --- e2e/contents/tab.test.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index dda572f..198bf0a 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -7,14 +7,10 @@ const SERVER_URL = "localhost:11111"; describe("tab test", () => { let targetWindow; - let targetTab; before(() => { return windows.create().then((win) => { targetWindow = win; - return tabs.create(win.id, SERVER_URL).then((tab) => { - targetTab = tab; - }); }); }); @@ -22,13 +18,31 @@ describe("tab test", () => { return windows.remove(targetWindow.id); }); - it('delete tab', () => { - return Promise.resolve().then(() => { - return keys.press(targetTab.id, 'd'); - }).then(() => { - return windows.get(targetWindow.id); - }).then((after) => { - expect(after.tabs).to.have.lengthOf(1); + describe('press d', () => { + it('deletes tab', () => { + return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + return keys.press(tab.id, 'd'); + }).then(() => { + return windows.get(targetWindow.id); + }).then((after) => { + expect(after.tabs).to.have.lengthOf(1); + }); }); }); + + describe('press zd', () => { + it('duplicates tab', () => { + let targetTab = 0; + return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + targetTab = tab; + return keys.press(targetTab.id, 'z'); + }).then(() => { + return keys.press(targetTab.id, 'd'); + }).then(() => { + return windows.get(targetWindow.id); + }).then((after) => { + expect(after.tabs).to.have.lengthOf(3); + }); + }); + }) }); -- cgit v1.2.3 From 30d6872fa833861bc479494b2951e196f3addb60 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 15 Feb 2018 19:43:58 +0900 Subject: simple and stable --- e2e/contents/tab.test.js | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index 198bf0a..707acef 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -18,31 +18,37 @@ describe("tab test", () => { return windows.remove(targetWindow.id); }); - describe('press d', () => { - it('deletes tab', () => { - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { - return keys.press(tab.id, 'd'); - }).then(() => { - return windows.get(targetWindow.id); - }).then((after) => { - expect(after.tabs).to.have.lengthOf(1); - }); + it('deletes tab by d', () => { + let before; + let targetTab; + return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + targetTab = tab; + return 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); }); }); - describe('press zd', () => { - it('duplicates tab', () => { - let targetTab = 0; - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { - targetTab = tab; - return keys.press(targetTab.id, 'z'); - }).then(() => { - return keys.press(targetTab.id, 'd'); - }).then(() => { - return windows.get(targetWindow.id); - }).then((after) => { - expect(after.tabs).to.have.lengthOf(3); - }); + it('duplicates tab by zd', () => { + let before; + let targetTab; + return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + targetTab = tab; + return windows.get(targetWindow.id) + }).then((win) => {; + 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); }); }) }); -- cgit v1.2.3 From cbd8f5b9288c7ec84fc77a3d1a30a4d018cf05f0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 17 Feb 2018 22:41:08 +0900 Subject: add tab tests --- e2e/ambassador/src/background/index.js | 7 +- e2e/ambassador/src/background/tabs.js | 10 ++- e2e/ambassador/src/client/tabs.js | 14 +++- e2e/ambassador/src/shared/messages.js | 2 + e2e/contents/tab.test.js | 132 ++++++++++++++++++++++++++++++++- 5 files changed, 157 insertions(+), 8 deletions(-) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/ambassador/src/background/index.js b/e2e/ambassador/src/background/index.js index c3e9dc1..6425b54 100644 --- a/e2e/ambassador/src/background/index.js +++ b/e2e/ambassador/src/background/index.js @@ -1,6 +1,6 @@ import { WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET, - TABS_CREATE, + TABS_CREATE, TABS_SELECT_AT, EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, SCROLL_GET, SCROLL_SET, } from '../shared/messages'; @@ -20,6 +20,11 @@ receiveContentMessage((message) => { url: message.url, windowId: message.windowId, }); + case TABS_SELECT_AT: + return tabs.selectAt({ + windowId: message.windowId, + index: message.index, + }); case EVENT_KEYPRESS: case EVENT_KEYDOWN: case EVENT_KEYUP: diff --git a/e2e/ambassador/src/background/tabs.js b/e2e/ambassador/src/background/tabs.js index 93d47a3..d049500 100644 --- a/e2e/ambassador/src/background/tabs.js +++ b/e2e/ambassador/src/background/tabs.js @@ -13,6 +13,14 @@ const create = (props = {}) => { }); }; +const selectAt = (props = {}) => { + return browser.tabs.query({ windowId: props.windowId }).then((tabs) => { + let target = tabs[props.index]; + return browser.tabs.update(target.id, { active: true }); + }); +}; + + export { - create, + create, selectAt }; diff --git a/e2e/ambassador/src/client/tabs.js b/e2e/ambassador/src/client/tabs.js index 4db3c11..6aaefbd 100644 --- a/e2e/ambassador/src/client/tabs.js +++ b/e2e/ambassador/src/client/tabs.js @@ -1,4 +1,6 @@ -import { TABS_CREATE } from '../shared/messages'; +import { + TABS_CREATE, TABS_SELECT_AT, +} from '../shared/messages'; import * as ipc from './ipc'; const create = (windowId, url) => { @@ -9,4 +11,12 @@ const create = (windowId, url) => { }); }; -export { create }; +const selectAt = (windowId, index) => { + return ipc.send({ + type: TABS_SELECT_AT, + windowId, + index, + }); +}; + +export { create, selectAt }; diff --git a/e2e/ambassador/src/shared/messages.js b/e2e/ambassador/src/shared/messages.js index dd389db..9fd1054 100644 --- a/e2e/ambassador/src/shared/messages.js +++ b/e2e/ambassador/src/shared/messages.js @@ -4,6 +4,7 @@ const WINDOWS_CREATE = 'windows.create'; const WINDOWS_REMOVE = 'windows.remove'; const WINDOWS_GET = 'windows.get'; const TABS_CREATE = 'tabs.create'; +const TABS_SELECT_AT = 'tabs.selectAt'; const EVENT_KEYPRESS = 'event.keypress'; const EVENT_KEYDOWN = 'event.keydown'; const EVENT_KEYUP = 'event.keyup'; @@ -19,6 +20,7 @@ export { WINDOWS_GET, TABS_CREATE, + TABS_SELECT_AT, EVENT_KEYPRESS, EVENT_KEYDOWN, diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index 707acef..852c6d9 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -3,18 +3,18 @@ import * as windows from "../ambassador/src/client/windows"; import * as tabs from "../ambassador/src/client/tabs"; import * as keys from "../ambassador/src/client/keys"; -const SERVER_URL = "localhost:11111"; +const SERVER_URL = "localhost:11111/"; describe("tab test", () => { let targetWindow; - before(() => { - return windows.create().then((win) => { + beforeEach(() => { + return windows.create(SERVER_URL).then((win) => { targetWindow = win; }); }); - after(() => { + afterEach(() => { return windows.remove(targetWindow.id); }); @@ -51,4 +51,128 @@ describe("tab test", () => { expect(actual.tabs).to.have.lengthOf(before.tabs.length + 1); }); }) + + it('selects previous tab by K', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).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; + }); + }); + + it('selects previous tab by K rotatory', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + 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; + }); + }); + + it('selects next tab by J', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + 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; + }); + }); + + it('selects previous tab by J rotatory', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + 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; + }); + }); + + it('selects first tab by g0', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + return tabs.selectAt(targetWindow.id, 2); + }).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; + }); + }); + + it('selects last tab by g$', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + return tabs.selectAt(targetWindow.id, 2); + }).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; + }); + }); + + it('deletes tab by d', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1'); + }).then((tab) => { + return keys.press(tab.id, 'd'); + }).then(() => { + return windows.get(targetWindow.id); + }).then((win) => { + expect(win.tabs).to.have.lengthOf(1); + }); + }); }); -- cgit v1.2.3 From 08d198eb3062cd263f799837208eacf5139f0d47 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 18 Feb 2018 21:34:59 +0900 Subject: add zp test --- e2e/contents/tab.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index 852c6d9..56d1f21 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -52,6 +52,24 @@ describe("tab test", () => { }); }) + it('makes pinned by zd', () => { + let before; + let targetTab; + return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + targetTab = tab; + return 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; + }); + }) + it('selects previous tab by K', () => { return Promise.resolve().then(() => { return tabs.create(targetWindow.id, SERVER_URL + '#1') -- cgit v1.2.3 From ec6a7c8871a2fec6c0d8c29a01b655778daad2fa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 18 Feb 2018 21:38:18 +0900 Subject: add test --- e2e/contents/tab.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index 56d1f21..be4288f 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -182,6 +182,26 @@ describe("tab test", () => { }); }); + it('selects last selected tab by ', () => { + return Promise.resolve().then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#1') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#2') + }).then(() => { + return tabs.create(targetWindow.id, SERVER_URL + '#3'); + }).then(() => { + return tabs.selectAt(targetWindow.id, 1); + }).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; + }); + }); + it('deletes tab by d', () => { return Promise.resolve().then(() => { return tabs.create(targetWindow.id, SERVER_URL + '#1'); -- cgit v1.2.3 From 7b3ff33be04e25d73d2a8168b011e4d49189078f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 7 Mar 2018 21:43:18 +0900 Subject: fix test case --- e2e/contents/tab.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'e2e/contents/tab.test.js') diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index be4288f..4374907 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -52,7 +52,7 @@ describe("tab test", () => { }); }) - it('makes pinned by zd', () => { + it('makes pinned by zp', () => { let before; let targetTab; return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { -- cgit v1.2.3