mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bugs 393629 and 436094. Fix document.all.length and make us honor the name attribute for the same set of elements as IE in the document.all implementation. r/sr=jst
This commit is contained in:
parent
8a69f6fb57
commit
2ac0cf8903
@ -3158,12 +3158,19 @@ DocAllResultMatch(nsIContent* aContent, PRInt32 aNamespaceID, nsIAtom* aAtom,
|
||||
}
|
||||
|
||||
nsIAtom* tag = elm->Tag();
|
||||
if (tag != nsGkAtoms::img &&
|
||||
tag != nsGkAtoms::form &&
|
||||
if (tag != nsGkAtoms::a &&
|
||||
tag != nsGkAtoms::applet &&
|
||||
tag != nsGkAtoms::embed &&
|
||||
tag != nsGkAtoms::button &&
|
||||
tag != nsGkAtoms::embed &&
|
||||
tag != nsGkAtoms::form &&
|
||||
tag != nsGkAtoms::iframe &&
|
||||
tag != nsGkAtoms::img &&
|
||||
tag != nsGkAtoms::input &&
|
||||
tag != nsGkAtoms::map &&
|
||||
tag != nsGkAtoms::meta &&
|
||||
tag != nsGkAtoms::object &&
|
||||
tag != nsGkAtoms::input) {
|
||||
tag != nsGkAtoms::select &&
|
||||
tag != nsGkAtoms::textarea) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ _TEST_FILES = test_bug1682.html \
|
||||
test_bug404320.html \
|
||||
test_form-parsing.html \
|
||||
test_viewport.html \
|
||||
test_documentAll.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
155
content/html/document/test/test_documentAll.html
Normal file
155
content/html/document/test/test_documentAll.html
Normal file
@ -0,0 +1,155 @@
|
||||
<html>
|
||||
<!--
|
||||
Tests for document.all
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Tests for document.all</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/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=259332">Mozilla Bug 259332</a>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=393629">Mozilla Bug 393629</a>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=448904">Mozilla Bug 448904</a>
|
||||
<p id="display">
|
||||
</p>
|
||||
<div id="content" style="display: none">
|
||||
<a id="id1">A</a>
|
||||
<a id="id2">B</a>
|
||||
<a id="id2">C</a>
|
||||
<a id="id3">D</a>
|
||||
<a id="id3">E</a>
|
||||
<a id="id3">F</a>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
p = document.getElementById("content");
|
||||
|
||||
// Test that several elements with the same id or name behave correctly
|
||||
function testNumSame() {
|
||||
is(document.all.id0, null, "no ids");
|
||||
is(document.all.id1, p.children[0], "one id");
|
||||
is(document.all.id2[0], p.children[1], "two ids");
|
||||
is(document.all.id2[1], p.children[2], "two ids");
|
||||
is(document.all.id2.length, 2, "two length");
|
||||
is(document.all.id3[0], p.children[3], "three ids");
|
||||
is(document.all.id3[1], p.children[4], "three ids");
|
||||
is(document.all.id3[2], p.children[5], "three ids");
|
||||
is(document.all.id3.length, 3, "three length");
|
||||
}
|
||||
testNumSame();
|
||||
p.innerHTML = p.innerHTML.replace("id=", "name=", "g");
|
||||
testNumSame();
|
||||
|
||||
|
||||
// Test that dynamic changes behave properly
|
||||
|
||||
// Add two elements and check that they are added to the correct lists
|
||||
child = Array.prototype.slice.call(p.children);
|
||||
child[6] = document.createElement("a");
|
||||
child[6].id = "id0";
|
||||
p.appendChild(child[6]);
|
||||
child[7] = document.createElement("a");
|
||||
child[7].id = "id1";
|
||||
p.appendChild(child[7]);
|
||||
is(document.all.id0, child[6], "now one id");
|
||||
is(document.all.id1[0], child[0], "now two ids");
|
||||
is(document.all.id1[1], child[7], "now two ids");
|
||||
is(document.all.id1.length, 2, "now two length");
|
||||
|
||||
// Remove and element and check that the list shrinks
|
||||
rC(child[1]);
|
||||
is(document.all.id2, child[2], "now just one id");
|
||||
|
||||
// Change an id and check that its removed and added to the correct lists
|
||||
child[4].name = "id1";
|
||||
is(document.all.id1[0], child[0], "now three ids");
|
||||
is(document.all.id1[1], child[4], "now three ids");
|
||||
is(document.all.id1[2], child[7], "now three ids");
|
||||
is(document.all.id1.length, 3, "now three length");
|
||||
is(document.all.id3[1], child[5], "now just two ids");
|
||||
is(document.all.id3.length, 2, "now two length");
|
||||
|
||||
// Remove all elements from a list and check that it goes empty
|
||||
id3list = document.all.id3;
|
||||
rC(child[3]);
|
||||
is(id3list.length, 1, "now one length");
|
||||
rC(child[5]);
|
||||
is(document.all.id3, null, "now none");
|
||||
is(id3list.length, 0, "now none length");
|
||||
|
||||
// Give an element both a name and id and check that it appears in two lists
|
||||
p.insertBefore(child[1], child[2]); // restore previously removed
|
||||
id1list = document.all.id1;
|
||||
id2list = document.all.id2;
|
||||
child[1].id = "id1";
|
||||
is(id1list[0], child[0], "now four ids");
|
||||
is(id1list[1], child[1], "now four ids");
|
||||
is(id1list[2], child[4], "now four ids");
|
||||
is(id1list[3], child[7], "now four ids");
|
||||
is(id1list.length, 4, "now four length");
|
||||
is(id2list[0], child[1], "still two ids");
|
||||
is(id2list[1], child[2], "still two ids");
|
||||
is(id2list.length, 2, "still two length");
|
||||
|
||||
|
||||
// Check that document.all behaves list a list of all elements
|
||||
allElems = document.getElementsByTagName("*");
|
||||
ok(testArraysSame(document.all, allElems), "arrays same");
|
||||
length = document.all.length;
|
||||
expectedLength = length + p.getElementsByTagName("*").length + 1;
|
||||
p.appendChild(p.cloneNode(true));
|
||||
ok(testArraysSame(document.all, allElems), "arrays still same");
|
||||
is(document.all.length, expectedLength, "grew correctly");
|
||||
|
||||
// Check which elements the 'name' attribute works on
|
||||
var elementNames =
|
||||
['applet','abbr','acronym','address','area','a','b','base','basefont',
|
||||
'bgsound','big','blink','blockquote','br','canvas','center','cite','code',
|
||||
'col','colgroup','dd','del','dfn','dir','div','dir','dl','dt','em','embed',
|
||||
'fieldset','font','form','frame','frameset','head','i','iframe','img',
|
||||
'input','ins','isindex','kbd','keygen','label','li','legend','link','menu',
|
||||
'multicol','noscript','noframes','object','spacer','table','td','td','th',
|
||||
'thead','tfoot','tr','textarea','select','option','spacer','param',
|
||||
'marquee','hr','title','hx','tt','u','ul','var','wbr','sub','sup','cite',
|
||||
'code','q','nobr','ol','p','pre','s','samp','small','body','html','map',
|
||||
'bdo','legend','listing','style','script','tbody','caption','meta',
|
||||
'optgroup','button','span','strike','strong','td'].sort();
|
||||
var hasName =
|
||||
['applet','a','embed','form','iframe','img','input','object','textarea',
|
||||
'select','map','meta','button'].sort();
|
||||
|
||||
elementNames.forEach(function (name) {
|
||||
nameval = 'namefor' + name;
|
||||
|
||||
e = document.createElement(name);
|
||||
p.appendChild(e);
|
||||
e.setAttribute('name', nameval);
|
||||
|
||||
if (name == hasName[0]) {
|
||||
is(document.all[nameval], e, "should have name");
|
||||
hasName.shift();
|
||||
}
|
||||
else {
|
||||
is(document.all[nameval], null, "shouldn't have name");
|
||||
}
|
||||
});
|
||||
is(hasName.length, 0, "found all names");
|
||||
|
||||
// Utility functions
|
||||
function rC(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
function testArraysSame(a1, a2) {
|
||||
return Array.prototype.every.call(a1, function(e, index) {
|
||||
return a2[index] === e;
|
||||
}) && a1.length == a2.length;
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -8172,6 +8172,8 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj,
|
||||
}
|
||||
|
||||
*vp = INT_TO_JSVAL(length);
|
||||
|
||||
return JS_TRUE;
|
||||
} else if (id != sTags_id) {
|
||||
// For all other strings, look for an element by id or name.
|
||||
|
||||
@ -8185,7 +8187,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj,
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
} else if (JSVAL_TO_INT(id) >= 0) {
|
||||
} else if (JSVAL_IS_INT(id) && JSVAL_TO_INT(id) >= 0) {
|
||||
// Map document.all[n] (where n is a number) to the n:th item in
|
||||
// the document.all node list.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user