Files
tubestation/browser/components/sessionstore/test/content.js
Rob Wu 5ea50ab2dd Bug 1544834 - Replace deprecated generics in test code r=evilpie
- `Array.map` becomes `Array.from`
- Array copying via `Array.slice` becomes `Array.from`.
- `Array.forEach` that did not rely on closures becomes `for`-`of` loops.
- Anything else: `Array.X` becomes `Array.prototype.X`.

Complex cases:

dom/bindings/test/TestInterfaceJS.js and
dom/bindings/test/test_exception_options_from_jsimplemented.html
use `Array.indexOf` to generate an error with a specific error message.
Switched to `Array.prototype.forEach` to generate the same error.

js/src/jit-test/tests/basic/exception-column-number.js
In this test `Array.indexOf()` is used to generate an error. Since the
exact message doesn't matter, I switched to `Array.from()`.

Intentionally not changed:

editor/libeditor/tests/browserscope/lib/richtext/richtext/js/range.js
Did not modify because this is 3rd-party code and the code uses
feature detection as a fall back when Array generics are not used.

testing/talos/talos/tests/dromaeo/lib/mootools.js
Did not modify because mootools adds the `Array.slice` method to the
`Array` object.

Not changed because they check the implementation of Array generics:
js/src/jit-test/tests/basic/arrayNatives.js
js/src/jit-test/tests/basic/bug563243.js
js/src/jit-test/tests/basic/bug618853.js
js/src/jit-test/tests/basic/bug830967.js
js/src/jit-test/tests/jaeger/recompile/bug656753.js
js/src/jit-test/tests/self-hosting/alternate-static-and-instance-array-extras.js
js/src/tests/non262/Array/generics.js
js/src/tests/non262/Array/regress-415540.js
js/src/tests/non262/extensions/regress-355497.js
js/src/tests/non262/extensions/typedarray-set-neutering.js

Depends on D27802

Differential Revision: https://phabricator.services.mozilla.com/D27803
2019-04-17 19:03:19 +00:00

151 lines
4.6 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env mozilla/frame-script */
"use strict";
function executeSoon(callback) {
Services.tm.dispatchToMainThread(callback);
}
var historyListener = {
OnHistoryNewEntry() {
sendAsyncMessage("ss-test:OnHistoryNewEntry");
},
OnHistoryGotoIndex() {
sendAsyncMessage("ss-test:OnHistoryGotoIndex");
},
OnHistoryPurge() {
sendAsyncMessage("ss-test:OnHistoryPurge");
},
OnHistoryReload() {
sendAsyncMessage("ss-test:OnHistoryReload");
return true;
},
OnHistoryReplaceEntry() {
sendAsyncMessage("ss-test:OnHistoryReplaceEntry");
},
QueryInterface: ChromeUtils.generateQI([
Ci.nsISHistoryListener,
Ci.nsISupportsWeakReference,
]),
};
var {sessionHistory} = docShell.QueryInterface(Ci.nsIWebNavigation);
if (sessionHistory) {
sessionHistory.legacySHistory.addSHistoryListener(historyListener);
}
/**
* This frame script is only loaded for sessionstore mochitests. It enables us
* to modify and query docShell data when running with multiple processes.
*/
addEventListener("hashchange", function() {
sendAsyncMessage("ss-test:hashchange");
});
addMessageListener("ss-test:getStyleSheets", function(msg) {
let sheets = content.document.styleSheets;
let titles = Array.from(sheets, ss => [ss.title, ss.disabled]);
sendSyncMessage("ss-test:getStyleSheets", titles);
});
addMessageListener("ss-test:enableStyleSheetsForSet", function(msg) {
let sheets = content.document.styleSheets;
let change = false;
for (let i = 0; i < sheets.length; i++) {
if (sheets[i].disabled != (!msg.data.includes(sheets[i].title))) {
change = true;
break;
}
}
function observer() {
Services.obs.removeObserver(observer, "style-sheet-applicable-state-changed");
// It's possible our observer will run before the one in
// content-sessionStore.js. Therefore, we run ours a little
// later.
executeSoon(() => sendAsyncMessage("ss-test:enableStyleSheetsForSet"));
}
if (change) {
// We don't want to reply until content-sessionStore.js has seen
// the change.
Services.obs.addObserver(observer, "style-sheet-applicable-state-changed");
content.document.enableStyleSheetsForSet(msg.data);
} else {
sendAsyncMessage("ss-test:enableStyleSheetsForSet");
}
});
addMessageListener("ss-test:enableSubDocumentStyleSheetsForSet", function(msg) {
let iframe = content.document.getElementById(msg.data.id);
iframe.contentDocument.enableStyleSheetsForSet(msg.data.set);
sendAsyncMessage("ss-test:enableSubDocumentStyleSheetsForSet");
});
addMessageListener("ss-test:getAuthorStyleDisabled", function(msg) {
let {authorStyleDisabled} =
docShell.contentViewer;
sendSyncMessage("ss-test:getAuthorStyleDisabled", authorStyleDisabled);
});
addMessageListener("ss-test:setAuthorStyleDisabled", function(msg) {
let markupDocumentViewer =
docShell.contentViewer;
markupDocumentViewer.authorStyleDisabled = msg.data;
sendSyncMessage("ss-test:setAuthorStyleDisabled");
});
addMessageListener("ss-test:setUsePrivateBrowsing", function(msg) {
let loadContext =
docShell.QueryInterface(Ci.nsILoadContext);
loadContext.usePrivateBrowsing = msg.data;
sendAsyncMessage("ss-test:setUsePrivateBrowsing");
});
addMessageListener("ss-test:getScrollPosition", function(msg) {
let frame = content;
if (msg.data.hasOwnProperty("frame")) {
frame = content.frames[msg.data.frame];
}
let x = {}, y = {};
frame.windowUtils.getVisualViewportOffset(x, y);
sendAsyncMessage("ss-test:getScrollPosition", {x: x.value, y: y.value});
});
addMessageListener("ss-test:setScrollPosition", function(msg) {
let frame = content;
let {x, y} = msg.data;
if (msg.data.hasOwnProperty("frame")) {
frame = content.frames[msg.data.frame];
}
frame.scrollTo(x, y);
frame.addEventListener("mozvisualscroll", function onScroll(event) {
if (frame.document.ownerGlobal.visualViewport == event.target) {
frame.removeEventListener("mozvisualscroll", onScroll,
{ mozSystemGroup: true });
sendAsyncMessage("ss-test:setScrollPosition");
}
}, { mozSystemGroup: true });
});
addMessageListener("ss-test:click", function({data}) {
content.document.getElementById(data.id).click();
sendAsyncMessage("ss-test:click");
});
addEventListener("load", function(event) {
let subframe = event.target != content.document;
sendAsyncMessage("ss-test:loadEvent", {subframe, url: event.target.documentURI});
}, true);