Bug 490761 - do not fail when nsIAccessibleValue accessible can't get value from markup, r=marcoz, davidb

--HG--
rename : accessible/tests/mochitest/test_elm_prgrsmtr.xul => accessible/tests/mochitest/test_value.xul
This commit is contained in:
Alexander Surkov 2009-05-06 11:16:36 +08:00
Родитель 371a7530cb
Коммит cd02410f24
8 изменённых файлов: 112 добавлений и 50 удалений

Просмотреть файл

@ -3223,7 +3223,7 @@ nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue)
NS_ENSURE_ARG_POINTER(aValue);
*aValue = 0;
if (!mDOMNode)
if (IsDefunct())
return NS_ERROR_FAILURE; // Node already shut down
if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
@ -3232,12 +3232,19 @@ nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue)
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
NS_ENSURE_STATE(content);
PRInt32 result = NS_OK;
nsAutoString value;
if (content->GetAttr(kNameSpaceID_None, aProperty, value))
*aValue = value.ToFloat(&result);
nsAutoString attrValue;
content->GetAttr(kNameSpaceID_None, aProperty, attrValue);
return result;
// Return zero value if there is no attribute or its value is empty.
if (attrValue.IsEmpty())
return NS_OK;
PRInt32 error = NS_OK;
double value = attrValue.ToFloat(&error);
if (NS_SUCCEEDED(error))
*aValue = value;
return NS_OK;
}
PRUint32

Просмотреть файл

@ -579,16 +579,25 @@ nsXULProgressMeterAccessible::GetCurrentValue(double *aCurrentValue)
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsAutoString currentValue;
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, currentValue);
nsAutoString attrValue;
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, attrValue);
PRInt32 result = NS_OK;
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::max))
*aCurrentValue = currentValue.ToFloat(&result);
else
*aCurrentValue = currentValue.ToFloat(&result) / 100;
// Return zero value if there is no attribute or its value is empty.
if (attrValue.IsEmpty())
return NS_OK;
return result;
PRInt32 error = NS_OK;
double value = attrValue.ToFloat(&error);
if (NS_FAILED(error))
return NS_OK; // Zero value because of wrong markup.
// If no max value then value is between 0 and 1 (refer to GetMaximumValue()
// method where max value is assumed to be equal to 1 in this case).
if (!content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::max))
value /= 100;
*aCurrentValue = value;
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -49,6 +49,12 @@ nsXULSliderAccessible::nsXULSliderAccessible(nsIDOMNode* aNode,
{
}
// nsISupports
NS_IMPL_ISUPPORTS_INHERITED1(nsXULSliderAccessible,
nsAccessibleWrap,
nsIAccessibleValue)
// nsIAccessible
nsresult
@ -175,7 +181,7 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, nsAString& aValue)
{
aValue.Truncate();
if (!mDOMNode)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> sliderNode(GetSliderNode());
@ -188,7 +194,7 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, nsAString& aValue)
nsresult
nsXULSliderAccessible::SetSliderAttr(nsIAtom *aName, const nsAString& aValue)
{
if (!mDOMNode)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> sliderNode(GetSliderNode());
@ -204,13 +210,20 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, double *aValue)
NS_ENSURE_ARG_POINTER(aValue);
*aValue = 0;
nsAutoString value;
nsresult rv = GetSliderAttr(aName, value);
nsAutoString attrValue;
nsresult rv = GetSliderAttr(aName, attrValue);
NS_ENSURE_SUCCESS(rv, rv);
// Return zero value if there is no attribute or its value is empty.
if (attrValue.IsEmpty())
return NS_OK;
PRInt32 error = NS_OK;
*aValue = value.ToFloat(&error);
return error;
double value = attrValue.ToFloat(&error);
if (NS_SUCCEEDED(error))
*aValue = value;
return NS_OK;
}
nsresult

Просмотреть файл

@ -48,15 +48,14 @@ class nsXULSliderAccessible : public nsAccessibleWrap
public:
nsXULSliderAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIAccessible
NS_IMETHOD GetValue(nsAString& aValue);
// nsIAccessibleValue
NS_IMETHOD GetMaximumValue(double *aMaximumValue);
NS_IMETHOD GetMinimumValue(double *aMinimumValue);
NS_IMETHOD GetMinimumIncrement(double *aMinIncrement);
NS_IMETHOD GetCurrentValue(double *aValue);
NS_IMETHOD SetCurrentValue(double aValue);
NS_DECL_NSIACCESSIBLEVALUE
// nsPIAccessible
NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);

Просмотреть файл

@ -64,6 +64,7 @@ _TEST_FILES =\
nsIAccessibleEditableText.js \
relations.js \
role.js \
value.js \
test_accessnode_invalidation.html \
test_actions_aria.html \
$(warning test_actions_inputs.html temporarily disabled) \
@ -78,7 +79,6 @@ _TEST_FILES =\
test_descr.html \
test_elm_filectrl.html \
test_elm_media.html \
test_elm_prgrsmtr.xul \
test_elm_txtcntnr.html \
test_events_caretmove.html \
test_events_mutation.html \
@ -121,6 +121,7 @@ _TEST_FILES =\
test_textattrs.html \
test_textboxes.html \
test_textboxes.xul \
test_value.xul \
testTextboxes.js \
treeview.js \
z_states_frame.html \

Просмотреть файл

@ -215,7 +215,7 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj, aDoNotFailIf)
acc.QueryInterface(aInterfaces[index]);
} catch (e) {
if (!(aDoNotFailIf & DONOTFAIL_IF_NO_INTERFACE))
ok(false, "Can't query " + aInterfaces[index] + " for " + aID);
ok(false, "Can't query " + aInterfaces[index] + " for " + aAccOrElmOrID);
return null;
}
@ -226,7 +226,7 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj, aDoNotFailIf)
try {
acc.QueryInterface(aInterfaces);
} catch (e) {
ok(false, "Can't query " + aInterfaces + " for " + aID);
ok(false, "Can't query " + aInterfaces + " for " + aAccOrElmOrID);
return null;
}

Просмотреть файл

@ -13,35 +13,25 @@
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/value.js" />
<script type="application/javascript">
<![CDATA[
/**
* Helper function to test nsIAccessibleValue interface.
*/
function testValue(aAccOrElmOrId, aValue, aCurrValue,
aMinValue, aMaxValue, aMinIncr)
{
var acc = getAccessible(aAccOrElmOrId, [nsIAccessibleValue]);
if (!acc)
return;
is(acc.value, aValue, "Wrong value of " + prettyName(aAccOrElmOrId));
is(acc.currentValue, aCurrValue,
"Wrong current value of " + prettyName(aAccOrElmOrId));
is(acc.minimumValue, aMinValue,
"Wrong minimum value of " + prettyName(aAccOrElmOrId));
is(acc.maximumValue, aMaxValue,
"Wrong maximum value of " + prettyName(aAccOrElmOrId));
is(acc.minimumIncrement, aMinIncr,
"Wrong minimum increment value of " + prettyName(aAccOrElmOrId));
}
function doTest()
{
// progressmeter
testValue("pm1", "50%", .5, 0, 1, 0);
testValue("pm2", "50%", 500, 0, 1000, 0);
testValue("pm3", "0%", 0, 0, 1, 0);
// scale
testValue("sc1", "500", 500, 0, 1000, 10);
testValue("sc2", "", 0, 0, 0, 0);
// aria progressbar
testValue("ariapb1", "500", 500, 0, 1000, 0);
testValue("ariapb2", "", 0, 0, 0, 0);
SimpleTest.finish();
}
@ -65,8 +55,19 @@
</pre>
</body>
<!-- progressmeter -->
<progressmeter id="pm1" value="50"/>
<progressmeter id="pm2" value="500" max="1000"/>
<progressmeter id="pm3"/>
<!-- scale -->
<scale id="sc1" value="500" max="1000" increment="10"/>
<scale id="sc2"/>
<!-- aria -->
<description id="ariapb1" role="progressbar"
aria-valuenow="500" aria-valuemin="0" aria-valuemax="1000"/>
<description id="ariapb2" role="progressbar"/>
</hbox>
</window>

Просмотреть файл

@ -0,0 +1,32 @@
////////////////////////////////////////////////////////////////////////////////
// Public methods
/**
* Tests nsIAccessibleValue interface.
*
* @param aAccOrElmOrId [in] identifier of accessible
* @param aValue [in] accessible value (nsIAccessible::value)
* @param aCurrValue [in] current value (nsIAccessibleValue::currentValue)
* @param aMinValue [in] minimum value (nsIAccessibleValue::minimumValue)
* @param aMaxValue [in] maximumn value (nsIAccessibleValue::maximumValue)
* @param aMinIncr [in] minimum increment value
* (nsIAccessibleValue::minimumIncrement)
*/
function testValue(aAccOrElmOrId, aValue, aCurrValue,
aMinValue, aMaxValue, aMinIncr)
{
var acc = getAccessible(aAccOrElmOrId, [nsIAccessibleValue]);
if (!acc)
return;
is(acc.value, aValue, "Wrong value of " + prettyName(aAccOrElmOrId));
is(acc.currentValue, aCurrValue,
"Wrong current value of " + prettyName(aAccOrElmOrId));
is(acc.minimumValue, aMinValue,
"Wrong minimum value of " + prettyName(aAccOrElmOrId));
is(acc.maximumValue, aMaxValue,
"Wrong maximum value of " + prettyName(aAccOrElmOrId));
is(acc.minimumIncrement, aMinIncr,
"Wrong minimum increment value of " + prettyName(aAccOrElmOrId));
}