fune/accessible/tests/browser/mac/head.js
Butkovits Atila 119d8f1aa7 Backed out 4 changesets (bug 1198336) for bustage on rules.mk. CLOSED TREE
Backed out changeset 26ad5bb8e1ed (bug 1198336)
Backed out changeset 852dc98e8cf5 (bug 1198336)
Backed out changeset 823511f4191b (bug 1198336)
Backed out changeset 67f5a42ed170 (bug 1198336)
2020-11-13 11:06:12 +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
);
}