зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1480244: Part 3a - Fix non-strict-mode test code which expects `this` to be bound to its global. r=aswan
A lot of the ad-hoc frame scripts we execute for tests does not run in strict mode, and therefore has its functions' `this` objects set to the global when they are called without a target object. At the moment, this gives them a MessageManager global. Once message managers become non-global objects, however, it will give them the shared JSM global, which is not what they expect. This patches changes scripts which rely on this to explicitly capture or set the appropriate `this` object for their calls. MozReview-Commit-ID: DY8DDb0xE1K --HG-- extra : rebase_source : 86c1fa4df070711f666dfee5487182afe28a7611
This commit is contained in:
Родитель
3020a8b0a8
Коммит
24dc48a4df
|
@ -2,29 +2,26 @@
|
|||
"use strict";
|
||||
|
||||
function frameScript() {
|
||||
function getSelectedText() {
|
||||
let frame = this.content.frames[0].frames[1];
|
||||
let docShell = frame.docShell;
|
||||
let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
let selection = controller.getSelection(controller.SELECTION_FIND);
|
||||
let range = selection.getRangeAt(0);
|
||||
let scope = {};
|
||||
ChromeUtils.import("resource://gre/modules/FindContent.jsm", scope);
|
||||
let highlighter = (new scope.FindContent(docShell)).highlighter;
|
||||
let r1 = frame.parent.frameElement.getBoundingClientRect();
|
||||
let f1 = highlighter._getFrameElementOffsets(frame.parent);
|
||||
let r2 = frame.frameElement.getBoundingClientRect();
|
||||
let f2 = highlighter._getFrameElementOffsets(frame);
|
||||
let r3 = range.getBoundingClientRect();
|
||||
let rect = {
|
||||
top: (r1.top + r2.top + r3.top + f1.y + f2.y),
|
||||
left: (r1.left + r2.left + r3.left + f1.x + f2.x),
|
||||
};
|
||||
this.sendAsyncMessage("test:find:selectionTest", {text: selection.toString(), rect});
|
||||
}
|
||||
getSelectedText();
|
||||
let frame = this.content.frames[0].frames[1];
|
||||
let docShell = frame.docShell;
|
||||
let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
let selection = controller.getSelection(controller.SELECTION_FIND);
|
||||
let range = selection.getRangeAt(0);
|
||||
let scope = {};
|
||||
ChromeUtils.import("resource://gre/modules/FindContent.jsm", scope);
|
||||
let highlighter = (new scope.FindContent(docShell)).highlighter;
|
||||
let r1 = frame.parent.frameElement.getBoundingClientRect();
|
||||
let f1 = highlighter._getFrameElementOffsets(frame.parent);
|
||||
let r2 = frame.frameElement.getBoundingClientRect();
|
||||
let f2 = highlighter._getFrameElementOffsets(frame);
|
||||
let r3 = range.getBoundingClientRect();
|
||||
let rect = {
|
||||
top: (r1.top + r2.top + r3.top + f1.y + f2.y),
|
||||
left: (r1.left + r2.left + r3.left + f1.x + f2.x),
|
||||
};
|
||||
this.sendAsyncMessage("test:find:selectionTest", {text: selection.toString(), rect});
|
||||
}
|
||||
|
||||
function waitForMessage(messageManager, topic) {
|
||||
|
@ -144,7 +141,7 @@ add_task(async function testDuplicatePinnedTab() {
|
|||
|
||||
let {selectedBrowser} = gBrowser;
|
||||
|
||||
let frameScriptUrl = `data:,(${frameScript})()`;
|
||||
let frameScriptUrl = `data:,(${frameScript}).call(this)`;
|
||||
selectedBrowser.messageManager.loadFrameScript(frameScriptUrl, false);
|
||||
let message = await waitForMessage(selectedBrowser.messageManager, "test:find:selectionTest");
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ add_task(async function test_on_created_navigation_target_from_mouse_click_subfr
|
|||
await runCreatedNavigationTargetTest({
|
||||
extension,
|
||||
openNavTarget() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(function() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(() => {
|
||||
// This code runs as a framescript in the child process and it returns the
|
||||
// target link in the subframe.
|
||||
return this.content.frames[0].document
|
||||
|
@ -138,7 +138,7 @@ add_task(async function test_on_created_navigation_target_from_mouse_click_subfr
|
|||
await runCreatedNavigationTargetTest({
|
||||
extension,
|
||||
openNavTarget() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(function() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(() => {
|
||||
// This code runs as a framescript in the child process and it returns the
|
||||
// target link in the subframe.
|
||||
return this.content.frames[0].document
|
||||
|
@ -157,7 +157,7 @@ add_task(async function test_on_created_navigation_target_from_mouse_click_subfr
|
|||
await runCreatedNavigationTargetTest({
|
||||
extension,
|
||||
openNavTarget() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(function() {
|
||||
BrowserTestUtils.synthesizeMouseAtCenter(() => {
|
||||
// This code runs as a framescript in the child process and it returns the
|
||||
// target link in the subframe.
|
||||
return this.content.frames[0].document
|
||||
|
|
|
@ -114,7 +114,7 @@ add_task(async function test_on_created_navigation_target_from_context_menu_subf
|
|||
extension,
|
||||
async openNavTarget() {
|
||||
await clickContextMenuItem({
|
||||
pageElementSelector: function() {
|
||||
pageElementSelector: () => {
|
||||
// This code runs as a framescript in the child process and it returns the
|
||||
// target link in the subframe.
|
||||
return this.content.frames[0]
|
||||
|
@ -136,7 +136,7 @@ add_task(async function test_on_created_navigation_target_from_context_menu_subf
|
|||
extension,
|
||||
async openNavTarget() {
|
||||
await clickContextMenuItem({
|
||||
pageElementSelector: function() {
|
||||
pageElementSelector: () => {
|
||||
// This code runs as a framescript in the child process and it returns the
|
||||
// target link in the subframe.
|
||||
return this.content.frames[0]
|
||||
|
|
|
@ -38,7 +38,7 @@ function processScript() {
|
|||
});
|
||||
sendSyncMessage("ProcessTest:Loaded");
|
||||
}
|
||||
var processScriptURL = "data:,(" + processScript.toString() + ")()";
|
||||
var processScriptURL = "data:,(" + processScript.toString() + ").call(this)";
|
||||
|
||||
function initTestScript() {
|
||||
let init = initialProcessData;
|
||||
|
|
|
@ -36,7 +36,7 @@ async function withHandlingUserInput(extension, fn) {
|
|||
let {messageManager} = extension.extension.groupFrameLoader;
|
||||
|
||||
if (!extensionHandlers.has(extension)) {
|
||||
messageManager.loadFrameScript(`data:,(${frameScript})(this)`, false);
|
||||
messageManager.loadFrameScript(`data:,(${frameScript}).call(this)`, false);
|
||||
extensionHandlers.add(extension);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче