aboutsummaryrefslogtreecommitdiff
path: root/e2e
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-02-14 21:11:03 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-02-14 21:12:06 +0900
commitb694afb7ce0eed4c4ee3ee9c3fae5dd35cb72d14 (patch)
treedcc43cfbd8f95aac495b9a30dec724f78fda2566 /e2e
parentf63920e25e80ca0e472d3514fd56e27fbc505e6f (diff)
add scroll test
Diffstat (limited to 'e2e')
-rw-r--r--e2e/ambassador/src/background/index.js9
-rw-r--r--e2e/ambassador/src/client/scrolls.js20
-rw-r--r--e2e/ambassador/src/content/index.js19
-rw-r--r--e2e/ambassador/src/content/scrolls.js18
-rw-r--r--e2e/ambassador/src/shared/messages.js4
-rw-r--r--e2e/contents/scroll.test.js81
6 files changed, 133 insertions, 18 deletions
diff --git a/e2e/ambassador/src/background/index.js b/e2e/ambassador/src/background/index.js
index f9fda7e..c3e9dc1 100644
--- a/e2e/ambassador/src/background/index.js
+++ b/e2e/ambassador/src/background/index.js
@@ -2,6 +2,7 @@ import {
WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET,
TABS_CREATE,
EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP,
+ SCROLL_GET, SCROLL_SET,
} from '../shared/messages';
import * as tabs from './tabs';
import { receiveContentMessage } from './ipc';
@@ -19,15 +20,11 @@ receiveContentMessage((message) => {
url: message.url,
windowId: message.windowId,
});
- }
-});
-
-
-receiveContentMessage((message) => {
- switch (message.type) {
case EVENT_KEYPRESS:
case EVENT_KEYDOWN:
case EVENT_KEYUP:
+ case SCROLL_GET:
+ case SCROLL_SET:
return browser.tabs.sendMessage(
message.tabId,
message
diff --git a/e2e/ambassador/src/client/scrolls.js b/e2e/ambassador/src/client/scrolls.js
new file mode 100644
index 0000000..f8f82e9
--- /dev/null
+++ b/e2e/ambassador/src/client/scrolls.js
@@ -0,0 +1,20 @@
+import { SCROLL_GET, SCROLL_SET } from '../shared/messages';
+import * as ipc from './ipc';
+
+const get = (tabId) => {
+ return ipc.send({
+ type: SCROLL_GET,
+ tabId,
+ });
+};
+
+const set = (tabId, x, y) => {
+ return ipc.send({
+ type: SCROLL_SET,
+ tabId,
+ x,
+ y,
+ });
+};
+
+export { get, set };
diff --git a/e2e/ambassador/src/content/index.js b/e2e/ambassador/src/content/index.js
index 8573d66..93943b8 100644
--- a/e2e/ambassador/src/content/index.js
+++ b/e2e/ambassador/src/content/index.js
@@ -1,21 +1,12 @@
import {
- WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET,
- TABS_CREATE,
EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP,
+ SCROLL_GET, SCROLL_SET,
} from '../shared/messages';
import * as ipc from './ipc';
+import * as scrolls from './scrolls';
ipc.receivePageMessage((message) => {
- switch (message.type) {
- case WINDOWS_CREATE:
- case WINDOWS_REMOVE:
- case WINDOWS_GET:
- case TABS_CREATE:
- case EVENT_KEYPRESS:
- case EVENT_KEYDOWN:
- case EVENT_KEYUP:
- return ipc.sendToBackground(message);
- }
+ return ipc.sendToBackground(message);
});
ipc.receiveBackgroundMesssage((message) => {
@@ -32,6 +23,10 @@ ipc.receiveBackgroundMesssage((message) => {
document.body.dispatchEvent(
new KeyboardEvent('keyup', { 'key': message.key }));
break;
+ case SCROLL_GET:
+ return Promise.resolve(scrolls.get());
+ case SCROLL_SET:
+ return Promise.resolve(scrolls.set(message.x, message.y));
}
return Promise.resolve({});
});
diff --git a/e2e/ambassador/src/content/scrolls.js b/e2e/ambassador/src/content/scrolls.js
new file mode 100644
index 0000000..79be01d
--- /dev/null
+++ b/e2e/ambassador/src/content/scrolls.js
@@ -0,0 +1,18 @@
+const get = () => {
+ let element = document.documentElement;
+ return {
+ xMax: element.scrollWidth - element.clientWidth,
+ yMax: element.scrollHeight - element.clientHeight,
+ x: element.scrollLeft,
+ y: element.scrollTop,
+ };
+};
+
+const set = (x, y) => {
+ let element = document.documentElement;
+ element.scrollLeft = x;
+ element.scrollTop = y;
+ return get();
+};
+
+export { get, set };
diff --git a/e2e/ambassador/src/shared/messages.js b/e2e/ambassador/src/shared/messages.js
index 32b7aa2..dd389db 100644
--- a/e2e/ambassador/src/shared/messages.js
+++ b/e2e/ambassador/src/shared/messages.js
@@ -7,6 +7,8 @@ const TABS_CREATE = 'tabs.create';
const EVENT_KEYPRESS = 'event.keypress';
const EVENT_KEYDOWN = 'event.keydown';
const EVENT_KEYUP = 'event.keyup';
+const SCROLL_GET = 'scroll.get';
+const SCROLL_SET = 'scroll.set';
export {
METHOD_REQUEST,
@@ -21,4 +23,6 @@ export {
EVENT_KEYPRESS,
EVENT_KEYDOWN,
EVENT_KEYUP,
+ SCROLL_GET,
+ SCROLL_SET,
};
diff --git a/e2e/contents/scroll.test.js b/e2e/contents/scroll.test.js
new file mode 100644
index 0000000..79e0d32
--- /dev/null
+++ b/e2e/contents/scroll.test.js
@@ -0,0 +1,81 @@
+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";
+import * as scrolls from "../ambassador/src/client/scrolls";
+
+const SERVER_URL = "localhost:11111";
+
+describe("scroll test", () => {
+ let targetWindow;
+ let targetTab;
+
+ before(() => {
+ return windows.create().then((win) => {
+ targetWindow = win;
+ return tabs.create(targetWindow.id, SERVER_URL);
+ }).then((tab) => {
+ targetTab = tab;
+ });
+ });
+
+ after(() => {
+ return windows.remove(targetWindow.id);
+ });
+
+ describe('press k', () => {
+ it('scrolls up', () => {
+ let before
+ return scrolls.set(targetTab.id, 100, 100).then((scroll) => {
+ before = scroll;
+ return keys.press(targetTab.id, 'k');
+ }).then(() => {
+ return scrolls.get(targetTab.id);
+ }).then((actual) => {
+ expect(actual.y).to.be.lessThan(before.y);
+ });
+ });
+ });
+
+ describe('press j', () => {
+ it('scrolls down', () => {
+ let before
+ return scrolls.set(targetTab.id, 100, 100).then((scroll) => {
+ before = scroll;
+ return keys.press(targetTab.id, 'j');
+ }).then(() => {
+ return scrolls.get(targetTab.id);
+ }).then((actual) => {
+ expect(actual.y).to.be.greaterThan(before.y);
+ });
+ });
+ });
+
+ describe('press h', () => {
+ it('scrolls left', () => {
+ let before
+ return scrolls.set(targetTab.id, 100, 100).then((scroll) => {
+ before = scroll;
+ return keys.press(targetTab.id, 'h');
+ }).then(() => {
+ return scrolls.get(targetTab.id);
+ }).then((actual) => {
+ expect(actual.x).to.be.lessThan(before.x);
+ });
+ });
+ });
+
+ describe('press l', () => {
+ it('scrolls right', () => {
+ let before
+ return scrolls.set(targetTab.id, 100, 100).then((scroll) => {
+ before = scroll;
+ return keys.press(targetTab.id, 'l');
+ }).then(() => {
+ return scrolls.get(targetTab.id);
+ }).then((actual) => {
+ expect(actual.x).to.be.greaterThan(before.x);
+ });
+ });
+ });
+});