2009-02-15 00:29:45 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Object attributes.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test object attributes.
|
|
|
|
*
|
2009-07-03 00:29:51 -07:00
|
|
|
* @param aAccOrElmOrID [in] the accessible identifier
|
2009-02-15 00:29:45 -08:00
|
|
|
* @param aAttrs [in] the map of expected object attributes
|
|
|
|
* (name/value pairs)
|
|
|
|
* @param aSkipUnexpectedAttrs [in] points this function doesn't fail if
|
|
|
|
* unexpected attribute is encountered
|
|
|
|
*/
|
|
|
|
function testAttrs(aAccOrElmOrID, aAttrs, aSkipUnexpectedAttrs)
|
|
|
|
{
|
2009-07-03 00:29:51 -07:00
|
|
|
testAttrsInternal(aAccOrElmOrID, aAttrs, aSkipUnexpectedAttrs);
|
|
|
|
}
|
2009-02-15 00:29:45 -08:00
|
|
|
|
2009-07-03 00:29:51 -07:00
|
|
|
/**
|
|
|
|
* Test object attributes that must not be present.
|
|
|
|
*
|
|
|
|
* @param aAccOrElmOrID [in] the accessible identifier
|
|
|
|
* @param aAbsentAttrs [in] map of attributes that should not be
|
|
|
|
* present (name/value pairs)
|
|
|
|
*/
|
2009-08-27 22:27:27 -07:00
|
|
|
function testAbsentAttrs(aAccOrElmOrID, aAbsentAttrs)
|
2009-07-03 00:29:51 -07:00
|
|
|
{
|
|
|
|
testAttrsInternal(aAccOrElmOrID, {}, true, aAbsentAttrs);
|
2009-02-15 00:29:45 -08:00
|
|
|
}
|
|
|
|
|
2012-02-20 07:45:29 -08:00
|
|
|
/**
|
|
|
|
* Test CSS based object attributes.
|
|
|
|
*/
|
|
|
|
function testCSSAttrs(aID)
|
|
|
|
{
|
|
|
|
var node = document.getElementById(aID);
|
|
|
|
var computedStyle = document.defaultView.getComputedStyle(node, "");
|
|
|
|
|
|
|
|
var attrs = {
|
|
|
|
"display": computedStyle.display,
|
|
|
|
"text-align": computedStyle.textAlign,
|
|
|
|
"text-indent": computedStyle.textIndent,
|
|
|
|
"margin-left": computedStyle.marginLeft,
|
|
|
|
"margin-right": computedStyle.marginRight,
|
|
|
|
"margin-top": computedStyle.marginTop,
|
|
|
|
"margin-bottom": computedStyle.marginBottom
|
|
|
|
};
|
|
|
|
testAttrs(aID, attrs, true);
|
|
|
|
}
|
|
|
|
|
2012-03-09 06:20:17 -08:00
|
|
|
/**
|
|
|
|
* Test the accessible that it doesn't have CSS-based object attributes.
|
|
|
|
*/
|
|
|
|
function testAbsentCSSAttrs(aID)
|
|
|
|
{
|
|
|
|
var attrs = {
|
|
|
|
"display": "",
|
|
|
|
"text-align": "",
|
|
|
|
"text-indent": "",
|
|
|
|
"margin-left": "",
|
|
|
|
"margin-right": "",
|
|
|
|
"margin-top": "",
|
|
|
|
"margin-bottom": ""
|
|
|
|
};
|
|
|
|
testAbsentAttrs(aID, attrs);
|
|
|
|
}
|
|
|
|
|
2009-02-15 00:29:45 -08:00
|
|
|
/**
|
2010-01-06 02:36:50 -08:00
|
|
|
* Test group object attributes (posinset, setsize and level) and
|
|
|
|
* nsIAccessible::groupPosition() method.
|
2009-02-15 00:29:45 -08:00
|
|
|
*
|
|
|
|
* @param aAccOrElmOrID [in] the ID, DOM node or accessible
|
|
|
|
* @param aPosInSet [in] the value of 'posinset' attribute
|
|
|
|
* @param aSetSize [in] the value of 'setsize' attribute
|
|
|
|
* @param aLevel [in, optional] the value of 'level' attribute
|
|
|
|
*/
|
|
|
|
function testGroupAttrs(aAccOrElmOrID, aPosInSet, aSetSize, aLevel)
|
|
|
|
{
|
2010-01-06 02:36:50 -08:00
|
|
|
var acc = getAccessible(aAccOrElmOrID);
|
|
|
|
var levelObj = {}, posInSetObj = {}, setSizeObj = {};
|
|
|
|
acc.groupPosition(levelObj, setSizeObj, posInSetObj);
|
2009-02-15 00:29:45 -08:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
if (aPosInSet && aSetSize) {
|
|
|
|
is(posInSetObj.value, aPosInSet,
|
|
|
|
"Wrong group position (posinset) for " + prettyName(aAccOrElmOrID));
|
|
|
|
is(setSizeObj.value, aSetSize,
|
|
|
|
"Wrong size of the group (setsize) for " + prettyName(aAccOrElmOrID));
|
2009-02-15 00:29:45 -08:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
var attrs = {
|
|
|
|
"posinset": String(aPosInSet),
|
|
|
|
"setsize": String(aSetSize)
|
|
|
|
};
|
|
|
|
testAttrs(aAccOrElmOrID, attrs, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLevel) {
|
|
|
|
is(levelObj.value, aLevel,
|
|
|
|
"Wrong group level for " + prettyName(aAccOrElmOrID));
|
|
|
|
|
|
|
|
var attrs = { "level" : String(aLevel) };
|
|
|
|
testAttrs(aAccOrElmOrID, attrs, true);
|
|
|
|
}
|
2009-02-15 00:29:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Text attributes.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test text attributes.
|
|
|
|
*
|
|
|
|
* @param aID [in] the ID of DOM element having text
|
|
|
|
* accessible
|
|
|
|
* @param aOffset [in] the offset inside text accessible to fetch
|
|
|
|
* text attributes
|
|
|
|
* @param aAttrs [in] the map of expected text attributes
|
2009-02-15 00:35:10 -08:00
|
|
|
* (name/value pairs) exposed at the offset
|
|
|
|
* @param aDefAttrs [in] the map of expected text attributes
|
|
|
|
* (name/value pairs) exposed on hyper text
|
|
|
|
* accessible
|
2009-02-15 00:29:45 -08:00
|
|
|
* @param aStartOffset [in] expected start offset where text attributes
|
|
|
|
* are applied
|
|
|
|
* @param aEndOffset [in] expected end offset where text attribute
|
|
|
|
* are applied
|
|
|
|
* @param aSkipUnexpectedAttrs [in] points the function doesn't fail if
|
|
|
|
* unexpected attribute is encountered
|
|
|
|
*/
|
2009-02-15 00:35:10 -08:00
|
|
|
function testTextAttrs(aID, aOffset, aAttrs, aDefAttrs,
|
|
|
|
aStartOffset, aEndOffset, aSkipUnexpectedAttrs)
|
2009-02-15 00:29:45 -08:00
|
|
|
{
|
|
|
|
var accessible = getAccessible(aID, [nsIAccessibleText]);
|
|
|
|
if (!accessible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var startOffset = { value: -1 };
|
|
|
|
var endOffset = { value: -1 };
|
|
|
|
|
2009-02-15 00:35:10 -08:00
|
|
|
// do not include attributes exposed on hyper text accessbile
|
|
|
|
var attrs = getTextAttributes(aID, accessible, false, aOffset,
|
|
|
|
startOffset, endOffset);
|
|
|
|
|
|
|
|
if (!attrs)
|
2009-02-15 00:29:45 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
var errorMsg = " for " + aID + " at offset " + aOffset;
|
|
|
|
|
|
|
|
is(startOffset.value, aStartOffset, "Wrong start offset" + errorMsg);
|
|
|
|
is(endOffset.value, aEndOffset, "Wrong end offset" + errorMsg);
|
|
|
|
|
|
|
|
compareAttrs(errorMsg, attrs, aAttrs, aSkipUnexpectedAttrs);
|
2009-02-15 00:35:10 -08:00
|
|
|
|
|
|
|
// include attributes exposed on hyper text accessbile
|
|
|
|
var expectedAttrs = {};
|
|
|
|
for (var name in aAttrs)
|
|
|
|
expectedAttrs[name] = aAttrs[name];
|
|
|
|
|
|
|
|
for (var name in aDefAttrs) {
|
|
|
|
if (!(name in expectedAttrs))
|
|
|
|
expectedAttrs[name] = aDefAttrs[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = getTextAttributes(aID, accessible, true, aOffset,
|
|
|
|
startOffset, endOffset);
|
|
|
|
|
|
|
|
if (!attrs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
compareAttrs(errorMsg, attrs, expectedAttrs, aSkipUnexpectedAttrs);
|
2009-02-15 00:29:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test default text attributes.
|
|
|
|
*
|
|
|
|
* @param aID [in] the ID of DOM element having text
|
|
|
|
* accessible
|
|
|
|
* @param aDefAttrs [in] the map of expected text attributes
|
|
|
|
* (name/value pairs)
|
|
|
|
* @param aSkipUnexpectedAttrs [in] points the function doesn't fail if
|
|
|
|
* unexpected attribute is encountered
|
|
|
|
*/
|
|
|
|
function testDefaultTextAttrs(aID, aDefAttrs, aSkipUnexpectedAttrs)
|
|
|
|
{
|
|
|
|
var accessible = getAccessible(aID, [nsIAccessibleText]);
|
|
|
|
if (!accessible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var defAttrs = null;
|
|
|
|
try{
|
|
|
|
defAttrs = accessible.defaultTextAttributes;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defAttrs) {
|
|
|
|
ok(false, "Can't get default text attributes for " + aID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var errorMsg = ". Getting default text attributes for " + aID;
|
|
|
|
compareAttrs(errorMsg, defAttrs, aDefAttrs, aSkipUnexpectedAttrs);
|
|
|
|
}
|
|
|
|
|
2010-05-21 04:27:00 -07:00
|
|
|
/**
|
|
|
|
* Test text attributes for wrong offset.
|
|
|
|
*/
|
|
|
|
function testTextAttrsWrongOffset(aID, aOffset)
|
|
|
|
{
|
|
|
|
var res = false;
|
|
|
|
try {
|
|
|
|
var s = {}, e = {};
|
|
|
|
var acc = getAccessible(ID, [nsIAccessibleText]);
|
|
|
|
acc.getTextAttributes(false, 157, s, e);
|
|
|
|
} catch (e) {
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(res,
|
|
|
|
"text attributes are calculated successfully at wrong offset " + aOffset + " for " + prettyName(aID));
|
|
|
|
}
|
|
|
|
|
|
|
|
const kNormalFontWeight =
|
|
|
|
function equalsToNormal(aWeight) { return aWeight <= 400 ; }
|
|
|
|
|
|
|
|
const kBoldFontWeight =
|
|
|
|
function equalsToBold(aWeight) { return aWeight > 400; }
|
|
|
|
|
|
|
|
// The pt font size of the input element can vary by Linux distro.
|
|
|
|
const kInputFontSize = WIN ?
|
|
|
|
"10pt" : (MAC ? "8pt" : function() { return true; });
|
|
|
|
|
2012-02-28 16:25:06 -08:00
|
|
|
const kAbsentFontFamily =
|
|
|
|
function(aFontFamily) { return aFontFamily != "sans-serif"; }
|
|
|
|
const kInputFontFamily =
|
|
|
|
function(aFontFamily) { return aFontFamily != "sans-serif"; }
|
|
|
|
|
|
|
|
const kMonospaceFontFamily =
|
|
|
|
function(aFontFamily) { return aFontFamily != "monospace"; }
|
|
|
|
const kSansSerifFontFamily =
|
|
|
|
function(aFontFamily) { return aFontFamily != "sans-serif"; }
|
|
|
|
const kSerifFontFamily =
|
|
|
|
function(aFontFamily) { return aFontFamily != "serif"; }
|
|
|
|
|
2012-04-17 09:39:18 -07:00
|
|
|
const kCursiveFontFamily = LINUX ? "DejaVu Serif" : "Comic Sans MS";
|
2012-02-28 16:25:06 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return used font from the given computed style.
|
|
|
|
*/
|
|
|
|
function fontFamily(aComputedStyle)
|
|
|
|
{
|
|
|
|
var name = aComputedStyle.fontFamily;
|
|
|
|
switch (name) {
|
|
|
|
case "monospace":
|
|
|
|
return kMonospaceFontFamily;
|
|
|
|
case "sans-serif":
|
|
|
|
return kSansSerifFontFamily;
|
|
|
|
case "serif":
|
|
|
|
return kSerifFontFamily;
|
|
|
|
default:
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 04:27:00 -07:00
|
|
|
/**
|
|
|
|
* Build an object of default text attributes expected for the given accessible.
|
|
|
|
*
|
|
|
|
* @param aID [in] identifier of accessible
|
|
|
|
* @param aFontSize [in] font size
|
|
|
|
* @param aFontWeight [in, optional] kBoldFontWeight or kNormalFontWeight,
|
|
|
|
* default value is kNormalFontWeight
|
|
|
|
*/
|
2012-02-28 16:25:06 -08:00
|
|
|
function buildDefaultTextAttrs(aID, aFontSize, aFontWeight, aFontFamily)
|
2010-05-21 04:27:00 -07:00
|
|
|
{
|
|
|
|
var elm = getNode(aID);
|
|
|
|
var computedStyle = document.defaultView.getComputedStyle(elm, "");
|
|
|
|
var bgColor = computedStyle.backgroundColor == "transparent" ?
|
|
|
|
"rgb(255, 255, 255)" : computedStyle.backgroundColor;
|
|
|
|
|
|
|
|
var defAttrs = {
|
|
|
|
"font-style": computedStyle.fontStyle,
|
|
|
|
"font-size": aFontSize,
|
|
|
|
"background-color": bgColor,
|
|
|
|
"font-weight": aFontWeight ? aFontWeight : kNormalFontWeight,
|
|
|
|
"color": computedStyle.color,
|
2012-02-28 16:25:06 -08:00
|
|
|
"font-family": aFontFamily ? aFontFamily : fontFamily(computedStyle),
|
2010-05-21 04:27:00 -07:00
|
|
|
"text-position": computedStyle.verticalAlign
|
|
|
|
};
|
|
|
|
|
|
|
|
return defAttrs;
|
|
|
|
}
|
|
|
|
|
2009-02-15 00:29:45 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private.
|
|
|
|
|
2009-02-15 00:35:10 -08:00
|
|
|
function getTextAttributes(aID, aAccessible, aIncludeDefAttrs, aOffset,
|
|
|
|
aStartOffset, aEndOffset)
|
|
|
|
{
|
|
|
|
// This function expects the passed in accessible to already be queried for
|
|
|
|
// nsIAccessibleText.
|
|
|
|
var attrs = null;
|
|
|
|
try {
|
|
|
|
attrs = aAccessible.getTextAttributes(aIncludeDefAttrs, aOffset,
|
|
|
|
aStartOffset, aEndOffset);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrs)
|
|
|
|
return attrs;
|
|
|
|
|
|
|
|
ok(false, "Can't get text attributes for " + aID);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:29:51 -07:00
|
|
|
function testAttrsInternal(aAccOrElmOrID, aAttrs, aSkipUnexpectedAttrs,
|
|
|
|
aAbsentAttrs)
|
|
|
|
{
|
|
|
|
var accessible = getAccessible(aAccOrElmOrID);
|
|
|
|
if (!accessible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var attrs = null;
|
|
|
|
try {
|
|
|
|
attrs = accessible.attributes;
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
if (!attrs) {
|
2009-08-19 23:45:19 -07:00
|
|
|
ok(false, "Can't get object attributes for " + prettyName(aAccOrElmOrID));
|
2009-07-03 00:29:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
var errorMsg = " for " + prettyName(aAccOrElmOrID);
|
2009-07-03 00:29:51 -07:00
|
|
|
compareAttrs(errorMsg, attrs, aAttrs, aSkipUnexpectedAttrs, aAbsentAttrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
function compareAttrs(aErrorMsg, aAttrs, aExpectedAttrs, aSkipUnexpectedAttrs,
|
|
|
|
aAbsentAttrs)
|
2009-02-15 00:29:45 -08:00
|
|
|
{
|
2009-08-27 22:27:27 -07:00
|
|
|
// Check if all obtained attributes are expected and have expected value.
|
2009-02-15 00:29:45 -08:00
|
|
|
var enumerate = aAttrs.enumerate();
|
|
|
|
while (enumerate.hasMoreElements()) {
|
|
|
|
var prop = enumerate.getNext().QueryInterface(nsIPropertyElement);
|
|
|
|
|
|
|
|
if (!(prop.key in aExpectedAttrs)) {
|
|
|
|
if (!aSkipUnexpectedAttrs)
|
|
|
|
ok(false, "Unexpected attribute '" + prop.key + "' having '" +
|
|
|
|
prop.value + "'" + aErrorMsg);
|
|
|
|
} else {
|
2009-08-19 23:45:19 -07:00
|
|
|
var msg = "Attribute '" + prop.key + "' has wrong value" + aErrorMsg;
|
2009-03-03 22:46:29 -08:00
|
|
|
var expectedValue = aExpectedAttrs[prop.key];
|
|
|
|
|
|
|
|
if (typeof expectedValue == "function")
|
|
|
|
ok(expectedValue(prop.value), msg);
|
|
|
|
else
|
|
|
|
is(prop.value, expectedValue, msg);
|
2009-02-15 00:29:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-27 22:27:27 -07:00
|
|
|
// Check if all expected attributes are presented.
|
2009-02-15 00:29:45 -08:00
|
|
|
for (var name in aExpectedAttrs) {
|
|
|
|
var value = "";
|
|
|
|
try {
|
|
|
|
value = aAttrs.getStringProperty(name);
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
ok(false,
|
|
|
|
"There is no expected attribute '" + name + "' " + aErrorMsg);
|
|
|
|
}
|
2009-07-03 00:29:51 -07:00
|
|
|
|
2009-08-27 22:27:27 -07:00
|
|
|
// Check if all unexpected attributes are absent.
|
|
|
|
if (aAbsentAttrs) {
|
2009-07-03 00:29:51 -07:00
|
|
|
for (var name in aAbsentAttrs) {
|
2009-08-27 22:27:27 -07:00
|
|
|
var wasFound = false;
|
|
|
|
|
|
|
|
var enumerate = aAttrs.enumerate();
|
|
|
|
while (enumerate.hasMoreElements()) {
|
|
|
|
var prop = enumerate.getNext().QueryInterface(nsIPropertyElement);
|
|
|
|
if (prop.key == name)
|
|
|
|
wasFound = true;
|
|
|
|
}
|
2009-07-03 00:29:51 -07:00
|
|
|
}
|
2009-08-27 22:27:27 -07:00
|
|
|
|
|
|
|
ok(!wasFound,
|
|
|
|
"There is an unexpected attribute '" + name + "' " + aErrorMsg);
|
|
|
|
}
|
2009-02-15 00:29:45 -08:00
|
|
|
}
|