Bug 659596 - option.label should be reflected like option.value. r=smaug sr=bz

This commit is contained in:
Mounir Lamouri 2011-05-27 12:32:59 +02:00
Родитель 5dd032c71d
Коммит 79635f2c9e
3 изменённых файлов: 120 добавлений и 21 удалений

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

@ -67,6 +67,26 @@
using namespace mozilla::dom;
/**
* This macro is similar to NS_IMPL_STRING_ATTR except that the getter method
* falls back to GetText if the content attribute isn't set. GetText returns a
* whitespace compressed .textContent value.
*/
#define NS_IMPL_STRING_ATTR_WITH_TEXTCONTENT(_class, _method, _atom) \
NS_IMETHODIMP \
_class::Get##_method(nsAString& aValue) \
{ \
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue)) { \
GetText(aValue); \
} \
return NS_OK; \
} \
NS_IMETHODIMP \
_class::Set##_method(const nsAString& aValue) \
{ \
return SetAttrHelper(nsGkAtoms::_atom, aValue); \
}
/**
* Implementation of <option>
*/
@ -160,25 +180,6 @@ nsHTMLOptionElement::SetSelectedInternal(PRBool aValue, PRBool aNotify)
}
}
NS_IMETHODIMP
nsHTMLOptionElement::SetValue(const nsAString& aValue)
{
SetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLOptionElement::GetValue(nsAString& aValue)
{
// If the value attr is there, that is *exactly* what we use. If it is
// not, we compress whitespace .text.
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue)) {
GetText(aValue);
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLOptionElement::GetSelected(PRBool* aValue)
{
@ -216,8 +217,8 @@ nsHTMLOptionElement::SetSelected(PRBool aValue)
}
NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, DefaultSelected, selected)
NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Label, label)
//NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Value, value)
NS_IMPL_STRING_ATTR_WITH_TEXTCONTENT(nsHTMLOptionElement, Label, label)
NS_IMPL_STRING_ATTR_WITH_TEXTCONTENT(nsHTMLOptionElement, Value, value)
NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, Disabled, disabled)
NS_IMETHODIMP

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

@ -277,6 +277,7 @@ _TEST_FILES = \
test_bug560112.html \
test_bug649134.html \
test_bug658746.html \
test_bug659596.html \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,97 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=659596
-->
<head>
<title>Test for Bug 659596</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=659596">Mozilla Bug 659596</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 659596 **/
function checkReflection(option, attribute) {
/**
* Getting.
*/
// When attribute isn't present.
var tests = [ "", "foo" ];
for each (var test in tests) {
option.removeAttribute(attribute);
option.textContent = test;
is(option.getAttribute(attribute), null,
"option " + attribute + "'s value should be null");
is(option[attribute], option.textContent,
"option." + attribute + " should reflect the text content when the attribute isn't set");
}
// When attribute is present.
tests = [
[ "", "" ],
[ "", "foo" ],
[ "foo", "bar" ],
[ "foo", "" ],
];
for each (var test in tests) {
option.setAttribute(attribute, test[0]);
option.textContent = test[1];
is(option[attribute], option.getAttribute(attribute),
"option." + attribute + " should reflect the content attribute when it is set");
}
/**
* Setting.
*/
// When attribute isn't present.
tests = [
[ "", "new" ],
[ "foo", "new" ],
];
for each (var test in tests) {
option.removeAttribute(attribute);
option.textContent = test[0];
option[attribute] = test[1]
is(option.getAttribute(attribute), test[1],
"when setting, the content attribute should change");
is(option.textContent, test[0],
"when setting, the text content should not change");
}
// When attribute is present.
tests = [
[ "", "", "new" ],
[ "", "foo", "new" ],
[ "foo", "bar", "new" ],
[ "foo", "", "new" ],
];
for each (var test in tests) {
option.setAttribute(attribute, test[0]);
option.textContent = test[1];
option[attribute] = test[2];
is(option.getAttribute(attribute), test[2],
"when setting, the content attribute should change");
is(option.textContent, test[1],
"when setting, the text content should not change");
}
}
var option = document.createElement("option");
checkReflection(option, "value");
checkReflection(option, "label");
</script>
</pre>
</body>
</html>