aboutsummaryrefslogtreecommitdiff
path: root/e2e/ambassador/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'e2e/ambassador/src/client')
-rw-r--r--e2e/ambassador/src/client/ipc.js29
-rw-r--r--e2e/ambassador/src/client/keys.js29
-rw-r--r--e2e/ambassador/src/client/tabs.js12
-rw-r--r--e2e/ambassador/src/client/windows.js27
4 files changed, 97 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/keys.js b/e2e/ambassador/src/client/keys.js
new file mode 100644
index 0000000..af0fb3d
--- /dev/null
+++ b/e2e/ambassador/src/client/keys.js
@@ -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 };
diff --git a/e2e/ambassador/src/client/tabs.js b/e2e/ambassador/src/client/tabs.js
new file mode 100644
index 0000000..4db3c11
--- /dev/null
+++ b/e2e/ambassador/src/client/tabs.js
@@ -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 };
diff --git a/e2e/ambassador/src/client/windows.js b/e2e/ambassador/src/client/windows.js
new file mode 100644
index 0000000..f92405a
--- /dev/null
+++ b/e2e/ambassador/src/client/windows.js
@@ -0,0 +1,27 @@
+import {
+ WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET
+} from '../shared/messages';
+import * as ipc from './ipc';
+
+const create = (url) => {
+ return ipc.send({
+ type: WINDOWS_CREATE,
+ url,
+ });
+};
+
+const remove = (windowId) => {
+ return ipc.send({
+ type: WINDOWS_REMOVE,
+ windowId,
+ });
+};
+
+const get = (windowId) => {
+ return ipc.send({
+ type: WINDOWS_GET,
+ windowId,
+ });
+};
+
+export { create, remove, get };