Skip to content
Permalink
Browse files

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)
  • Loading branch information...
wycats committed Apr 15, 2012
1 parent 5181ce0 commit 6bc08c2b2f04629114ae7ca79c3c2c54320e4908
Showing with 78 additions and 47 deletions.
  1. +50 −1 test/data/testinit.js
  2. +7 −12 test/unit/attributes.js
  3. +13 −21 test/unit/core.js
  4. +8 −13 test/unit/manipulation.js
@@ -1,3 +1,5 @@
/*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() {

This comment has been minimized.

Copy link
@mikesherov

mikesherov Apr 16, 2012

Member

Where is this function being used?

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 ) {
@@ -159,4 +208,4 @@ function url(value) {
window.start = function() {
oldStart();
};
})();
})();
@@ -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() {
expect(3);
stop();
jQuery.get("data/dashboard.xml", function( xml ) {
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) in XML Files", function() {
expect(3);
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" );
});

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) {
ok( jQuery.isXMLDoc( xml ), "XML document" );
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
start();
});
var xml = createXMLDocument();

This comment has been minimized.

Copy link
@Krinkle

Krinkle Apr 20, 2012

Member

Introduced failure in all browsers: http://swarm.jquery.org/job/40/ ; http://swarm.jquery.org/user/jquery/

Died on test #1: createXMLDocument is not defined - { "stack": "()@./test/unit/core.js:555  ./.. }

Expected 3 assertions, but 1 were run

This comment has been minimized.

Copy link
@Krinkle
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" );
});
}

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) {
// 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();
});

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" );
});
}

test("end()", function() {
expect(3);
@@ -1245,22 +1245,17 @@ 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 root = jQuery(xml.documentElement).clone();
var origTab = jQuery("tab", xml).eq(0);
var cloneTab = jQuery("tab", root).eq(0);
origTab.text("origval");
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();
});
var xml = createDashboardXML();
var root = jQuery(xml.documentElement).clone();
var origTab = jQuery("tab", xml).eq(0);
var cloneTab = jQuery("tab", root).eq(0);
origTab.text("origval");
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");
});
}

test("clone() on local XML nodes with html5 nodename", function() {
expect(2);

0 comments on commit 6bc08c2

Please sign in to comment.
You can’t perform that action at this time.