Commit 6bc08c2b authored by Yehuda Katz's avatar Yehuda Katz

Remove Ajax requirement for simple XML tests

Previously, all jQuery tests that wanted an XML
document would make an Ajax request to go through
jQuery's XML parsing logic in jQuery.ajax. Now,
use jQuery.parseXML instead.

This removes the need for the Ajax server for
these tests, improves their performance, and
decouples simple core tests from Ajax.

(with scottgonzalez)
parent 5181ce0f
/*jshint multistr:true*/
var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$",
originaljQuery = jQuery,
......@@ -45,6 +47,53 @@ function t(a,b,c) {
deepEqual(f, q.apply(q,c), a + " (" + b + ")");
}
var createDashboardXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \
<locations class="foo"> \
<location for="bar" checked="different"> \
<infowindowtab> \
<tab title="Location"><![CDATA[blabla]]></tab> \
<tab title="Users"><![CDATA[blublu]]></tab> \
</infowindowtab> \
</location> \
</locations> \
</dashboard>';
return jQuery.parseXML(string);
};
var createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \
<soap:Body> \
<jsconf xmlns="http://www.example.com/ns1"> \
<response xmlns:ab="http://www.example.com/ns2"> \
<meta> \
<component id="seite1" class="component"> \
<properties xmlns:cd="http://www.example.com/ns3"> \
<property name="prop1"> \
<thing /> \
<value>1</value> \
</property> \
<property name="prop2"> \
<thing att="something" /> \
</property> \
<foo_bar>foo</foo_bar> \
</properties> \
</component> \
</meta> \
</response> \
</jsconf> \
</soap:Body> \
</soap:Envelope>';
return jQuery.parseXML(string);
};
var fireNative;
if ( document.createEvent ) {
fireNative = function( node, type ) {
......
......@@ -127,18 +127,13 @@ test("attr(String)", function() {
equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
});
if ( !isLocal ) {
test("attr(String) in XML Files", function() {
test("attr(String) in XML Files", function() {
expect(3);
stop();
jQuery.get("data/dashboard.xml", function( xml ) {
var xml = createDashboardXML();
equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
start();
});
});
}
});
test("attr(String, Function)", function() {
expect(2);
......
......@@ -547,21 +547,17 @@ test("XSS via location.hash", function() {
jQuery( '#<img id="check9521" src="no-such-.gif" onerror="jQuery._check9521(false)">' ).appendTo("#qunit-fixture");
} catch (err) {
jQuery._check9521(true);
};
}
});
if ( !isLocal ) {
test("isXMLDoc - XML", function() {
expect(3);
stop();
jQuery.get("data/dashboard.xml", function(xml) {
var xml = createXMLDocument();
xml.documentElement.appendChild( xml.createElement( "tab" ) );
ok( jQuery.isXMLDoc( xml ), "XML document" );
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
start();
});
});
}
test("isWindow", function() {
expect( 14 );
......@@ -638,20 +634,16 @@ test("jQuery('html', context)", function() {
equal($span.length, 1, "Verify a span created with a div context works, #1763");
});
if ( !isLocal ) {
test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
expect(2);
stop();
jQuery.get("data/dashboard.xml", function(xml) {
var xml = createDashboardXML();
// tests for #1419 where IE was a problem
var tab = jQuery("tab", xml).eq(0);
equal( tab.text(), "blabla", "Verify initial text correct" );
tab.text("newtext");
equal( tab.text(), "newtext", "Verify new text correct" );
start();
});
});
}
test("end()", function() {
expect(3);
......
......@@ -1245,11 +1245,9 @@ test("clone(multiple selected options) (Bug #8129)", function() {
});
if (!isLocal) {
test("clone() on XML nodes", function() {
expect(2);
stop();
jQuery.get("data/dashboard.xml", function (xml) {
var xml = createDashboardXML();
var root = jQuery(xml.documentElement).clone();
var origTab = jQuery("tab", xml).eq(0);
var cloneTab = jQuery("tab", root).eq(0);
......@@ -1257,10 +1255,7 @@ test("clone() on XML nodes", function() {
cloneTab.text("cloneval");
equal(origTab.text(), "origval", "Check original XML node was correctly set");
equal(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
start();
});
});
}
test("clone() on local XML nodes with html5 nodename", function() {
expect(2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment