parent
cf03d278eb
commit
3f8bbe11d9
11 changed files with 153 additions and 30 deletions
@ -1,12 +1,33 @@ |
||||
import { WINDOWS_CREATE, WINDOWS_REMOVE } from '../shared/messages'; |
||||
import { |
||||
WINDOWS_CREATE, WINDOWS_REMOVE, TABS_CREATE, |
||||
EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, |
||||
} from '../shared/messages'; |
||||
import * as tabs from './tabs'; |
||||
import { receiveContentMessage } from './ipc'; |
||||
|
||||
receiveContentMessage((message) => { |
||||
switch (message.type) { |
||||
case WINDOWS_CREATE: |
||||
return browser.windows.create(); |
||||
return browser.windows.create({ url: message.url }); |
||||
case WINDOWS_REMOVE: |
||||
return browser.windows.remove(message.windowId); |
||||
case TABS_CREATE: |
||||
return tabs.create({ |
||||
url: message.url, |
||||
windowId: message.windowId, |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
|
||||
receiveContentMessage((message) => { |
||||
switch (message.type) { |
||||
case EVENT_KEYPRESS: |
||||
case EVENT_KEYDOWN: |
||||
case EVENT_KEYUP: |
||||
return browser.tabs.sendMessage( |
||||
message.tabId, |
||||
message |
||||
); |
||||
} |
||||
}); |
||||
|
@ -0,0 +1,29 @@ |
||||
import { EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP } from '../shared/messages'; |
||||
import * as ipc from './ipc'; |
||||
|
||||
const press = (tabId, key) => { |
||||
return ipc.send({ |
||||
type: EVENT_KEYPRESS, |
||||
tabId, |
||||
key, |
||||
}); |
||||
}; |
||||
|
||||
const down = (tabId, key) => { |
||||
return ipc.send({ |
||||
type: EVENT_KEYDOWN, |
||||
tabId, |
||||
key, |
||||
}); |
||||
}; |
||||
|
||||
|
||||
const up = (tabId, key) => { |
||||
return ipc.send({ |
||||
type: EVENT_KEYUP, |
||||
tabId, |
||||
key, |
||||
}); |
||||
}; |
||||
|
||||
export { press, down, up }; |
@ -0,0 +1,12 @@ |
||||
import { TABS_CREATE } from '../shared/messages'; |
||||
import * as ipc from './ipc'; |
||||
|
||||
const create = (windowId, url) => { |
||||
return ipc.send({ |
||||
type: TABS_CREATE, |
||||
windowId, |
||||
url, |
||||
}); |
||||
}; |
||||
|
||||
export { create }; |
@ -1,11 +1,35 @@ |
||||
import { WINDOWS_CREATE, WINDOWS_REMOVE } from '../shared/messages'; |
||||
import { |
||||
WINDOWS_CREATE, WINDOWS_REMOVE, TABS_CREATE, |
||||
EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP, |
||||
} from '../shared/messages'; |
||||
import * as ipc from './ipc'; |
||||
|
||||
ipc.receivePageMessage((message) => { |
||||
switch (message.type) { |
||||
case WINDOWS_CREATE: |
||||
return ipc.send(message); |
||||
case WINDOWS_REMOVE: |
||||
return ipc.send(message); |
||||
case TABS_CREATE: |
||||
case EVENT_KEYPRESS: |
||||
case EVENT_KEYDOWN: |
||||
case EVENT_KEYUP: |
||||
return ipc.sendToBackground(message); |
||||
} |
||||
}); |
||||
|
||||
ipc.receiveBackgroundMesssage((message) => { |
||||
switch (message.type) { |
||||
case EVENT_KEYPRESS: |
||||
document.body.dispatchEvent( |
||||
new KeyboardEvent('keypress', { 'key': message.key })); |
||||
break; |
||||
case EVENT_KEYDOWN: |
||||
document.body.dispatchEvent( |
||||
new KeyboardEvent('keydown', { 'key': message.key })); |
||||
break; |
||||
case EVENT_KEYUP: |
||||
document.body.dispatchEvent( |
||||
new KeyboardEvent('keyup', { 'key': message.key })); |
||||
break; |
||||
} |
||||
return Promise.resolve({}); |
||||
}); |
||||
|
@ -1,19 +0,0 @@ |
||||
import { expect } from "chai"; |
||||
import * as windows from "../ambassador/src/client/windows"; |
||||
|
||||
describe("scroll test", () => { |
||||
let targetWindow; |
||||
before(() => { |
||||
return windows.create().then((win) => { |
||||
targetWindow = win; |
||||
}); |
||||
}); |
||||
|
||||
after(() => { |
||||
return windows.remove(targetWindow.id); |
||||
}); |
||||
|
||||
it('runs test', () => { |
||||
expect(targetWindow.id).be.a('number'); |
||||
}); |
||||
}); |
@ -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; |
||||
}); |
||||
}); |
Reference in new issue