Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79b74e0

Browse files
authored
Selector: Port Sizzle tests to jQuery
Apart from porting most Sizzle tests to jQuery (mostly to its selector module),this commit fixes selector-native so that a jQuery custom compilation thatexcludes Sizzle passes all tests as well.Closesgh-4406
1 parent438b1a3 commit79b74e0

File tree

11 files changed

+1884
-160
lines changed

11 files changed

+1884
-160
lines changed

‎src/selector-native.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define( [
3434
*/
3535

3636
varhasDuplicate,sortInput,
37+
rhtmlSuffix=/HTML$/i,
3738
sortStable=jQuery.expando.split("").sort(sortOrder).join("")===jQuery.expando,
3839

3940
// Support: IE 9 - 11+
@@ -199,11 +200,14 @@ jQuery.extend( {
199200
returna===bup||!!(bup&&bup.nodeType===1&&adown.contains(bup));
200201
},
201202
isXMLDoc:function(elem){
202-
203-
// documentElement is verified for cases where it doesn't yet exist
204-
// (such as loading iframes in IE - #4833)
205-
vardocumentElement=elem&&(elem.ownerDocument||elem).documentElement;
206-
returndocumentElement ?documentElement.nodeName!=="HTML" :false;
203+
varnamespace=elem.namespaceURI,
204+
documentElement=(elem.ownerDocument||elem).documentElement;
205+
206+
// Assume HTML when documentElement doesn't yet exist, such as inside
207+
// document fragments.
208+
return!rhtmlSuffix.test(namespace||
209+
documentElement&&documentElement.nodeName||
210+
"HTML");
207211
},
208212
expr:{
209213
attrHandle:{},

‎test/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ajaxTest":false,
1919
"testIframe":false,
2020
"createDashboardXML":false,
21+
"createWithFriesXML":false,
2122
"createXMLFragment":false,
2223
"moduleTeardown":false,
2324
"url":false,

‎test/data/qunit-fixture.html

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<pid="firstp">See<aid="simon1"href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector"rel="bookmark">this blog entry</a> for more information.</p>
22
<pid="ap">
3-
Here are some links in a normal paragraph:<aid="google"href="http://www.google.com/"title="Google!">Google</a>,
3+
Here are some[links] in a normal paragraph:<aid="google"href="http://www.google.com/"title="Google!">Google</a>,
44
<aid="groups"href="http://groups.google.com/"class="GROUPS">Google Groups (Link)</a>.
5-
This link has<code><ahref="http://smin"id="anchor1">class="blog"</a></code>:
5+
This link has<codeid="code1"><ahref="http://smin"id="anchor1">class="blog"</a></code>:
66
<ahref="http://diveintomark.org/"class="blog"hreflang="en"id="mark">diveintomark</a>
77

88
</p>
@@ -78,11 +78,11 @@
7878
<paramname="p2"value="x2"/>
7979
</object>
8080

81-
<spanid="台北Táiběi"></span>
81+
<spanid="台北Táiběi"><spanid="台北Táiběi-child"></span></span>
8282
<spanid="台北"lang="中文"></span>
83-
<spanid="utf8class1"class="台北Táiběi 台北"></span>
83+
<spanid="utf8class1"class="台北Táiběi 台北">"'台北Táiběi"'</span>
8484
<spanid="utf8class2"class="台北"></span>
85-
<spanid="foo:bar"class="foo:bar"></span>
85+
<spanid="foo:bar"class="foo:bar"><spanid="foo_descendant"></span></span>
8686
<spanid="test.foo[5]bar"class="test.foo[5]bar"></span>
8787

8888
<foo_barid="foobar">test element</foo_bar>
@@ -163,7 +163,26 @@
163163
<divid="t6652">
164164
<div></div>
165165
</div>
166+
<divid="t12087">
167+
<inputtype="hidden"id="el12087"data-comma="0,1"/>
168+
</div>
166169
<divid="no-clone-exception"><object><embed></embed></object></div>
170+
<divid="names-group">
171+
<spanid="name-is-example"name="example"></span>
172+
<spanid="name-is-div"name="div"></span>
173+
</div>
174+
<divid="id-name-tests">
175+
<aid="tName1ID"name="tName1"><span></span></a>
176+
<aid="tName2ID"name="tName2"><span></span></a>
177+
<divid="tName1"><spanid="tName1-span">C</span></div>
178+
</div>
179+
<divid="whitespace-lists">
180+
<inputid="t15233-single"data-15233="foo"/>
181+
<inputid="t15233-double"data-15233="foo bar"/>
182+
<inputid="t15233-double-tab"data-15233="foobar"/>
183+
<inputid="t15233-double-nl"data-15233="foo&#xA;bar"/>
184+
<inputid="t15233-triple"data-15233="foo bar baz"/>
185+
</div>
167186
</div>
168187

169188
<divid="tabindex-tests">
@@ -194,6 +213,53 @@
194213
<spanid="liveSpan2"><ahref="#"id="liveLink2"></a></span>
195214
</div>
196215

216+
<formid="disabled-tests">
217+
<fieldsetid="disabled-fieldset"disabled="disabled">
218+
<aid="disabled-fieldset-a"href="#"></a>
219+
<inputid="disabled-fieldset-input"name="disabled-fieldset-input"type="text"/>
220+
<textareaid="disabled-fieldset-textarea"name="disabled-fieldset-textarea"></textarea>
221+
<buttonid="disabled-fieldset-button"name="disabled-fieldset-button">Go</button>
222+
<!-- exclude <select> because IE6 is bugged and fails
223+
<select id="disabled-fieldset-select" name="disabled-fieldset-select"></select>
224+
-->
225+
<spanid="disabled-fieldset-span">Neither enabled nor disabled</span>
226+
</fieldset>
227+
<fieldsetid="enabled-fieldset">
228+
<aid="disabled-a"href="#"disabled="disabled"></a>
229+
<inputid="disabled-input"name="disabled-input"type="text"disabled="disabled"/>
230+
<textareaid="disabled-textarea"name="disabled-textarea"disabled="disabled"></textarea>
231+
<buttonid="disabled-button"name="disabled-button"disabled="disabled">Go</button>
232+
<selectid="disabled-select"name="disabled-select"disabled="disabled">
233+
<optgroupid="disabled-optgroup"label="and"disabled="disabled">
234+
<optionid="disabled-option"disabled="disabled">Black</option>
235+
</optgroup>
236+
</select>
237+
<inputid="enabled-input"name="enabled-input"type="text"/>
238+
<textareaid="enabled-textarea"name="enabled-textarea"></textarea>
239+
<buttonid="enabled-button"name="enabled-button">Go</button>
240+
<selectid="enabled-select"name="enabled-select">
241+
<optgroupid="enabled-optgroup"label="and">
242+
<optionid="enabled-option">Gold</option>
243+
</optgroup>
244+
</select>
245+
<spanid="enabled-fieldset-span">Neither enabled nor disabled</span>
246+
</fieldset>
247+
<selectid="disabled-select-inherit"name="disabled-select-inherit"disabled="disabled">
248+
<optgroupid="disabled-optgroup-inherit"label="and"disabled="disabled">
249+
<optionid="disabled-optgroup-option">Black</option>
250+
</optgroup>
251+
<optgroupid="enabled-optgroup-inherit"label="and">
252+
<optionid="enabled-optgroup-option">Gold</option>
253+
</optgroup>
254+
</select>
255+
<selectid="enabled-select-inherit"name="enabled-select-inherit">
256+
<optgroupid="en_disabled-optgroup-inherit"label="and"disabled="disabled">
257+
<optionid="en_disabled-optgroup-option">Black</option>
258+
</optgroup>
259+
<optionid="enabled-select-option">Black</option>
260+
</select>
261+
</form>
262+
197263
<divid="siblingTest">
198264
<emid="siblingfirst">1</em>
199265
<emid="siblingnext">2</em>
@@ -208,7 +274,7 @@
208274
</div>
209275
<divid="fx-test-group"style="position: absolute; width: 1px; height: 1px; overflow: hidden;">
210276
<divid="fx-queue"name="test">
211-
<divid="fadein"class='chain-test'name='div'>fadeIn<div>fadeIn</div></div>
277+
<divid="fadein"class='chain-test'>fadeIn<div>fadeIn</div></div>
212278
<divid="fadeout"class='chain-test chain-test-out'>fadeOut<div>fadeOut</div></div>
213279

214280
<divid="show"class='chain-test'>show<div>show</div></div>
@@ -235,3 +301,4 @@
235301
<divid="fx-tests"></div>
236302
<spanid="display"></span>
237303
</div>
304+
<brid="last"/>

‎test/data/qunit-fixture.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎test/data/selector/mixed_sort.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<htmllang="en">
3+
<head>
4+
<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>
5+
<title>jQuery selector - cross-window uniqueSort</title>
6+
7+
<scriptsrc="../../jquery.js"></script>
8+
<scriptsrc="../iframeTest.js"></script>
9+
</head>
10+
<body>
11+
<script>
12+
vardoc=parent.document,
13+
unframed=[doc.getElementById("qunit-fixture"),doc.body,doc.documentElement],
14+
framed=jQuery.find("*");
15+
parent.console.log(unframed);
16+
17+
startIframeTest(
18+
jQuery.uniqueSort(unframed.concat(framed)),
19+
framed.concat(unframed.slice(0).reverse())
20+
);
21+
</script>
22+
</body>
23+
</html>

‎test/data/testinit.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,9 @@ this.q = function() {
5151
*@example match("Check for something", "p", ["foo", "bar"]);
5252
*/
5353
functionmatch(message,selector,expectedIds,context,assert){
54-
varf=jQuery(selector,context).get(),
55-
s="",
56-
i=0;
57-
58-
for(;i<f.length;i++){
59-
s+=(s&&",")+"\""+f[i].id+"\"";
60-
}
54+
varelems=jQuery(selector,context).get();
6155

62-
assert.deepEqual(f,q.apply(q,expectedIds),message+" ("+selector+")");
56+
assert.deepEqual(elems,q.apply(q,expectedIds),message+" ("+selector+")");
6357
}
6458

6559
/**
@@ -102,6 +96,36 @@ this.createDashboardXML = function() {
10296
returnjQuery.parseXML(string);
10397
};
10498

99+
this.createWithFriesXML=function(){
100+
varstring="<?xml version='1.0' encoding='UTF-8'?> \
101+
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' \
102+
xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
103+
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> \
104+
<soap:Body> \
105+
<jsconf xmlns='http://www.example.com/ns1'> \
106+
<response xmlns:ab='http://www.example.com/ns2'> \
107+
<meta> \
108+
<component id='seite1' class='component'> \
109+
<properties xmlns:cd='http://www.example.com/ns3'> \
110+
<property name='prop1'> \
111+
<thing /> \
112+
<value>1</value> \
113+
</property> \
114+
<property name='prop2'> \
115+
<thing att='something' /> \
116+
</property> \
117+
<foo_bar>foo</foo_bar> \
118+
</properties> \
119+
</component> \
120+
</meta> \
121+
</response> \
122+
</jsconf> \
123+
</soap:Body> \
124+
</soap:Envelope>";
125+
126+
returnjQuery.parseXML(string);
127+
};
128+
105129
this.createXMLFragment=function(){
106130
varfrag,
107131
xml=document.implementation.createDocument("","",null);

‎test/unit/attributes.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,18 +1278,16 @@ QUnit.test( "addClass(Array)", function( assert ) {
12781278
});
12791279

12801280
QUnit.test("addClass(Function) with incoming value",function(assert){
1281-
assert.expect(52);
1281+
assert.expect(57);
12821282
varpass,i,
12831283
div=jQuery("#qunit-fixture div"),
12841284
old=div.map(function(){
12851285
returnjQuery(this).attr("class")||"";
12861286
});
12871287

12881288
div.addClass(function(i,val){
1289-
if(this.id!=="_firebugConsole"){
1290-
assert.equal(val,old[i],"Make sure the incoming value is correct.");
1291-
return"test";
1292-
}
1289+
assert.equal(val,old[i],"Make sure the incoming value is correct.");
1290+
return"test";
12931291
});
12941292

12951293
pass=true;
@@ -1355,17 +1353,15 @@ QUnit.test( "removeClass(Array) - simple", function( assert ) {
13551353
});
13561354

13571355
QUnit.test("removeClass(Function) with incoming value",function(assert){
1358-
assert.expect(52);
1356+
assert.expect(57);
13591357

13601358
var$divs=jQuery("#qunit-fixture div").addClass("test"),old=$divs.map(function(){
13611359
returnjQuery(this).attr("class");
13621360
});
13631361

13641362
$divs.removeClass(function(i,val){
1365-
if(this.id!=="_firebugConsole"){
1366-
assert.equal(val,old[i],"Make sure the incoming value is correct.");
1367-
return"test";
1368-
}
1363+
assert.equal(val,old[i],"Make sure the incoming value is correct.");
1364+
return"test";
13691365
});
13701366

13711367
assert.ok(!$divs.is(".test"),"Remove Class");

‎test/unit/core.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,52 @@ QUnit.test( "isXMLDoc - HTML", function( assert ) {
380380
document.body.removeChild(iframe);
381381
});
382382

383+
QUnit.test("isXMLDoc - embedded SVG",function(assert){
384+
assert.expect(6);
385+
386+
varhtmlTree=jQuery("<div>"+
387+
"<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'>"+
388+
"<desc></desc>"+
389+
"</svg>"+
390+
"</div>"
391+
)[0];
392+
393+
assert.strictEqual(jQuery.isXMLDoc(htmlTree),false,"disconnected div element");
394+
assert.strictEqual(jQuery.isXMLDoc(htmlTree.firstChild),true,
395+
"disconnected HTML-embedded SVG root element");
396+
397+
assert.strictEqual(jQuery.isXMLDoc(htmlTree.firstChild.firstChild),true,
398+
"disconnected HTML-embedded SVG child element");
399+
400+
document.getElementById("qunit-fixture").appendChild(htmlTree);
401+
assert.strictEqual(jQuery.isXMLDoc(htmlTree),false,"connected div element");
402+
assert.strictEqual(jQuery.isXMLDoc(htmlTree.firstChild),true,
403+
"connected HTML-embedded SVG root element");
404+
405+
assert.strictEqual(jQuery.isXMLDoc(htmlTree.firstChild.firstChild),true,
406+
"disconnected HTML-embedded SVG child element");
407+
});
408+
409+
QUnit.test("isXMLDoc - XML",function(assert){
410+
assert.expect(8);
411+
412+
varxml=createDashboardXML();
413+
varsvg=jQuery.parseXML(
414+
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "+
415+
"\"http://www.w3.org/Gaphics/SVG/1.1/DTD/svg11.dtd\">"+
416+
"<svg version='1.1' xmlns='http://www.w3.org/2000/svg'><desc/></svg>"
417+
);
418+
assert.ok(jQuery.isXMLDoc(xml),"XML document");
419+
assert.ok(jQuery.isXMLDoc(xml.documentElement),"XML documentElement");
420+
assert.ok(jQuery.isXMLDoc(xml.documentElement.firstChild),"XML child element");
421+
assert.ok(jQuery.isXMLDoc(jQuery("tab",xml)[0]),"XML tab Element");
422+
423+
assert.ok(jQuery.isXMLDoc(svg),"SVG document");
424+
assert.ok(jQuery.isXMLDoc(svg.documentElement),"SVG documentElement");
425+
assert.ok(jQuery.isXMLDoc(svg.documentElement.firstChild),"SVG child element");
426+
assert.ok(jQuery.isXMLDoc(jQuery("desc",svg)[0]),"XML desc Element");
427+
});
428+
383429
QUnit.test("XSS via location.hash",function(assert){
384430
vardone=assert.async();
385431
assert.expect(1);
@@ -399,14 +445,6 @@ QUnit.test( "XSS via location.hash", function( assert ) {
399445
}
400446
});
401447

402-
QUnit.test("isXMLDoc - XML",function(assert){
403-
assert.expect(3);
404-
varxml=createDashboardXML();
405-
assert.ok(jQuery.isXMLDoc(xml),"XML document");
406-
assert.ok(jQuery.isXMLDoc(xml.documentElement),"XML documentElement");
407-
assert.ok(jQuery.isXMLDoc(jQuery("tab",xml)[0]),"XML Tab Element");
408-
});
409-
410448
QUnit.test("jQuery('html')",function(assert){
411449
assert.expect(18);
412450

‎test/unit/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function testAppendForObject( valueObj, isFragment, assert ) {
193193

194194
functiontestAppend(valueObj,assert){
195195

196-
assert.expect(78);
196+
assert.expect(82);
197197

198198
testAppendForObject(valueObj,false,assert);
199199
testAppendForObject(valueObj,true,assert);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp