diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-02-04 19:27:22 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-02-04 19:27:22 +0900 |
commit | f6f64297aa030cd3fbad4bbb9e322e469bc762e8 (patch) | |
tree | 02ad2374c6e7060c7f13658e7dd4c3c0d99b5b9f /e2e/ambassador/src/client | |
parent | bb5b6d367cdd19a1d81c78cf8a79c47520ca469e (diff) |
first webextension test
Diffstat (limited to 'e2e/ambassador/src/client')
-rw-r--r-- | e2e/ambassador/src/client/ipc.js | 29 | ||||
-rw-r--r-- | e2e/ambassador/src/client/windows.js | 17 |
2 files changed, 46 insertions, 0 deletions
diff --git a/e2e/ambassador/src/client/ipc.js b/e2e/ambassador/src/client/ipc.js new file mode 100644 index 0000000..9f232ea --- /dev/null +++ b/e2e/ambassador/src/client/ipc.js @@ -0,0 +1,29 @@ +import { METHOD_REQUEST, METHOD_RESPONSE } from '../shared/messages'; + +const generateId = () => { + return Math.random().toString(); +}; + +const send = (message) => { + return new Promise((resolve) => { + let id = generateId(); + let callback = (e) => { + let packet = e.data; + if (e.source !== window || packet.method !== METHOD_RESPONSE || + packet.id !== id) { + return; + } + window.removeEventListener('message', callback); + resolve(packet.message); + }; + window.addEventListener('message', callback); + + window.postMessage({ + id, + method: METHOD_REQUEST, + message + }, window.origin); + }); +}; + +export { send }; diff --git a/e2e/ambassador/src/client/windows.js b/e2e/ambassador/src/client/windows.js new file mode 100644 index 0000000..69b8905 --- /dev/null +++ b/e2e/ambassador/src/client/windows.js @@ -0,0 +1,17 @@ +import { WINDOWS_CREATE, WINDOWS_REMOVE } from '../shared/messages'; +import * as ipc from './ipc'; + +const create = () => { + return ipc.send({ + type: WINDOWS_CREATE + }); +}; + +const remove = (windowId) => { + return ipc.send({ + type: WINDOWS_REMOVE, + windowId, + }); +}; + +export { create, remove }; |