зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1672390, remove code_frame-script.js frame script and replace with SpecialPowers.spawn, r=ochameau
Differential Revision: https://phabricator.services.mozilla.com/D94387
This commit is contained in:
Родитель
0ad047845e
Коммит
c2792f5216
|
@ -9,7 +9,6 @@ support-files =
|
|||
code_WorkerTargetActor.attach-worker1.js
|
||||
code_WorkerTargetActor.attach-worker2.js
|
||||
code_WorkerTargetActor.attachThread-worker.js
|
||||
code_frame-script.js
|
||||
doc_cubic-bezier-01.html
|
||||
doc_cubic-bezier-02.html
|
||||
doc_empty-tab-01.html
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/* eslint-disable */
|
||||
"use strict";
|
||||
|
||||
const { loadSubScript } = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
||||
getService(Ci.mozIJSSubScriptLoader);
|
||||
|
||||
// Set up a dummy environment so that EventUtils works. We need to be careful to
|
||||
// pass a window object into each EventUtils method we call rather than having
|
||||
// it rely on the |window| global.
|
||||
const EventUtils = {};
|
||||
EventUtils.window = content;
|
||||
EventUtils.parent = EventUtils.window;
|
||||
EventUtils._EU_Ci = Ci;
|
||||
EventUtils._EU_Cc = Cc;
|
||||
EventUtils.navigator = content.navigator;
|
||||
EventUtils.KeyboardEvent = content.KeyboardEvent;
|
||||
loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
|
||||
|
||||
dump("Frame script loaded.\n");
|
||||
|
||||
var workers = {};
|
||||
|
||||
this._eval = function(string) {
|
||||
dump("Evalling string.\n");
|
||||
|
||||
return content.eval(string);
|
||||
};
|
||||
|
||||
this.generateMouseClick = function(path) {
|
||||
dump("Generating mouse click.\n");
|
||||
|
||||
const target = eval(path);
|
||||
EventUtils.synthesizeMouseAtCenter(target, {},
|
||||
target.ownerDocument.defaultView);
|
||||
};
|
||||
|
||||
this.createWorker = function(url) {
|
||||
dump("Creating worker with url '" + url + "'.\n");
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
const worker = new content.Worker(url);
|
||||
worker.addEventListener("message", function() {
|
||||
workers[url] = worker;
|
||||
resolve();
|
||||
}, {once: true});
|
||||
});
|
||||
};
|
||||
|
||||
this.terminateWorker = function(url) {
|
||||
dump("Terminating worker with url '" + url + "'.\n");
|
||||
|
||||
workers[url].terminate();
|
||||
delete workers[url];
|
||||
};
|
||||
|
||||
this.postMessageToWorker = function(url, message) {
|
||||
dump("Posting message to worker with url '" + url + "'.\n");
|
||||
|
||||
return new Promise(function(resolve) {
|
||||
const worker = workers[url];
|
||||
worker.postMessage(message);
|
||||
worker.addEventListener("message", function() {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
});
|
||||
};
|
||||
|
||||
addMessageListener("jsonrpc", function({ data: { method, params, id } }) {
|
||||
method = this[method];
|
||||
Promise.resolve().then(function() {
|
||||
return method.apply(undefined, params);
|
||||
}).then(function(result) {
|
||||
sendAsyncMessage("jsonrpc", {
|
||||
result: result,
|
||||
error: null,
|
||||
id: id
|
||||
});
|
||||
}, function(error) {
|
||||
sendAsyncMessage("jsonrpc", {
|
||||
result: null,
|
||||
error: error.message.toString(),
|
||||
id: id
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
addMessageListener("test:postMessageToWorker", function(message) {
|
||||
dump("Posting message '" + message.data.message + "' to worker with url '" +
|
||||
message.data.url + "'.\n");
|
||||
|
||||
let worker = workers[message.data.url];
|
||||
worker.postMessage(message.data.message);
|
||||
worker.addEventListener("message", function() {
|
||||
sendAsyncMessage("test:postMessageToWorker");
|
||||
}, {once: true});
|
||||
});
|
|
@ -15,65 +15,64 @@ var { DevToolsServer } = require("devtools/server/devtools-server");
|
|||
var { DevToolsClient } = require("devtools/client/devtools-client");
|
||||
var { Toolbox } = require("devtools/client/framework/toolbox");
|
||||
|
||||
const FRAME_SCRIPT_URL = getRootDirectory(gTestPath) + "code_frame-script.js";
|
||||
|
||||
var nextId = 0;
|
||||
|
||||
function jsonrpc(tab, method, params) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
const currentId = nextId++;
|
||||
const messageManager = tab.linkedBrowser.messageManager;
|
||||
messageManager.sendAsyncMessage("jsonrpc", {
|
||||
method: method,
|
||||
params: params,
|
||||
id: currentId,
|
||||
});
|
||||
messageManager.addMessageListener("jsonrpc", function listener(res) {
|
||||
const {
|
||||
data: { result, error, id },
|
||||
} = res;
|
||||
if (id !== currentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
messageManager.removeMessageListener("jsonrpc", listener);
|
||||
if (error != null) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createWorkerInTab(tab, url) {
|
||||
info("Creating worker with url '" + url + "' in tab.");
|
||||
|
||||
return jsonrpc(tab, "createWorker", [url]);
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [url], urlChild => {
|
||||
return new Promise(resolve => {
|
||||
const worker = new content.Worker(urlChild);
|
||||
worker.addEventListener(
|
||||
"message",
|
||||
function() {
|
||||
if (!content.workers) {
|
||||
content.workers = [];
|
||||
}
|
||||
content.workers[urlChild] = worker;
|
||||
resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function terminateWorkerInTab(tab, url) {
|
||||
info("Terminating worker with url '" + url + "' in tab.");
|
||||
|
||||
return jsonrpc(tab, "terminateWorker", [url]);
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [url], urlChild => {
|
||||
content.workers[urlChild].terminate();
|
||||
delete content.workers[urlChild];
|
||||
});
|
||||
}
|
||||
|
||||
function postMessageToWorkerInTab(tab, url, message) {
|
||||
info("Posting message to worker with url '" + url + "' in tab.");
|
||||
|
||||
return jsonrpc(tab, "postMessageToWorker", [url, message]);
|
||||
}
|
||||
|
||||
function generateMouseClickInTab(tab, path) {
|
||||
info("Generating mouse click in tab.");
|
||||
|
||||
return jsonrpc(tab, "generateMouseClick", [path]);
|
||||
return SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[url, message],
|
||||
(urlChild, messageChild) => {
|
||||
return new Promise(function(resolve) {
|
||||
const worker = content.workers[urlChild];
|
||||
worker.postMessage(messageChild);
|
||||
worker.addEventListener(
|
||||
"message",
|
||||
function() {
|
||||
resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function evalInTab(tab, string) {
|
||||
info("Evalling string in tab.");
|
||||
|
||||
return jsonrpc(tab, "_eval", [string]);
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [string], stringChild => {
|
||||
return content.eval(stringChild);
|
||||
});
|
||||
}
|
||||
|
||||
function connect(client) {
|
||||
|
@ -217,9 +216,6 @@ this.addTab = function addTab(url, win) {
|
|||
));
|
||||
const linkedBrowser = tab.linkedBrowser;
|
||||
|
||||
info("Loading frame script with url " + FRAME_SCRIPT_URL + ".");
|
||||
linkedBrowser.messageManager.loadFrameScript(FRAME_SCRIPT_URL, false);
|
||||
|
||||
BrowserTestUtils.browserLoaded(linkedBrowser).then(function() {
|
||||
info("Tab added and finished loading: " + url);
|
||||
resolve(tab);
|
||||
|
|
Загрузка…
Ссылка в новой задаче