fune/accessible/tests/browser/mac/head.js
Csoregi Natalia 6ddec72329 Backed out 4 changesets (bug 1198336) for causing leaks. CLOSED TREE
Backed out changeset faa35ea77d35 (bug 1198336)
Backed out changeset 821f94bae182 (bug 1198336)
Backed out changeset ee78c1e8cc3b (bug 1198336)
Backed out changeset 2c56e36b869d (bug 1198336)
2020-11-12 01:46:52 +02:00

77 lines
2 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/. */
"use strict";
/* exported getNativeInterface, waitForMacEventWithInfo, waitForMacEvent,
NSRange, NSDictionary, stringForRange */
// Load the shared-head file first.
/* import-globals-from ../shared-head.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js",
this
);
// Loading and common.js from accessible/tests/mochitest/ for all tests, as
// well as promisified-events.js.
loadScripts(
{ name: "common.js", dir: MOCHITESTS_DIR },
{ name: "promisified-events.js", dir: MOCHITESTS_DIR }
);
function getNativeInterface(accDoc, id) {
return findAccessibleChildByID(accDoc, id).nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
}
function waitForMacEventWithInfo(notificationType, filter) {
return new Promise(resolve => {
let eventObserver = {
observe(subject, topic, data) {
let macEvent = subject.QueryInterface(Ci.nsIAccessibleMacEvent);
if (
data === notificationType &&
(!filter || filter(macEvent.macIface, macEvent.data))
) {
Services.obs.removeObserver(this, "accessible-mac-event");
resolve(macEvent);
}
},
};
Services.obs.addObserver(eventObserver, "accessible-mac-event");
});
}
function waitForMacEvent(notificationType, filter) {
return waitForMacEventWithInfo(notificationType, filter).then(
e => e.macIface
);
}
function NSRange(location, length) {
return {
valueType: "NSRange",
value: [location, length],
};
}
function NSDictionary(dict) {
return {
objectType: "NSDictionary",
object: dict,
};
}
function stringForRange(macDoc, range) {
if (!range) {
return "";
}
return macDoc.getParameterizedAttributeValue(
"AXStringForTextMarkerRange",
range
);
}