2016-01-13 22:08:20 +03:00
|
|
|
const FRAME_URL = "http://example.org/";
|
|
|
|
|
|
|
|
const METHODS = {
|
|
|
|
addNextPaintListener: {},
|
|
|
|
removeNextPaintListener: {},
|
|
|
|
sendMouseEvent: {},
|
|
|
|
sendTouchEvent: {},
|
|
|
|
goBack: {},
|
|
|
|
goForward: {},
|
|
|
|
reload: {},
|
|
|
|
stop: {},
|
|
|
|
download: {},
|
|
|
|
purgeHistory: {},
|
|
|
|
getScreenshot: {},
|
|
|
|
zoom: {},
|
|
|
|
getCanGoBack: {},
|
|
|
|
getCanGoForward: {},
|
|
|
|
getContentDimensions: {},
|
|
|
|
findAll: {},
|
|
|
|
findNext: {},
|
|
|
|
clearMatch: {},
|
2016-04-21 16:48:59 +03:00
|
|
|
executeScript: {},
|
2016-01-13 22:08:20 +03:00
|
|
|
getWebManifest: {},
|
|
|
|
};
|
|
|
|
|
2017-05-18 04:31:01 +03:00
|
|
|
const ATTRIBUTES = [];
|
2016-01-13 22:08:20 +03:00
|
|
|
|
|
|
|
function once(target, eventName, useCapture = false) {
|
2016-04-21 16:48:59 +03:00
|
|
|
info("Waiting for event: '" + JSON.stringify(eventName) + "' on " + target + ".");
|
2016-01-13 22:08:20 +03:00
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
for (let [add, remove] of [
|
|
|
|
["addEventListener", "removeEventListener"],
|
|
|
|
["addMessageListener", "removeMessageListener"],
|
|
|
|
]) {
|
|
|
|
if ((add in target) && (remove in target)) {
|
2016-04-21 16:48:59 +03:00
|
|
|
eventName.forEach(evName => {
|
|
|
|
target[add](evName, function onEvent(...aArgs) {
|
|
|
|
info("Got event: '" + evName + "' on " + target + ".");
|
|
|
|
target[remove](evName, onEvent, useCapture);
|
|
|
|
resolve(aArgs);
|
|
|
|
}, useCapture);
|
|
|
|
});
|
2016-01-13 22:08:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
async function loadFrame(attributes = {}) {
|
2016-01-13 22:08:20 +03:00
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
iframe.setAttribute("src", FRAME_URL);
|
|
|
|
for (let key in attributes) {
|
|
|
|
iframe.setAttribute(key, attributes[key]);
|
|
|
|
}
|
2016-04-21 16:48:59 +03:00
|
|
|
let loaded = once(iframe, [ "load", "mozbrowserloadend" ]);
|
2016-01-13 22:08:20 +03:00
|
|
|
document.body.appendChild(iframe);
|
2017-06-22 13:51:42 +03:00
|
|
|
await loaded;
|
2016-01-13 22:08:20 +03:00
|
|
|
return iframe;
|
|
|
|
}
|