]> source.dussan.org Git - jquery.git/commitdiff
Remove Ajax requirement for simple XML tests
authorYehuda Katz <wycats@gmail.com>
Sun, 15 Apr 2012 21:41:54 +0000 (17:41 -0400)
committerYehuda Katz <wycats@gmail.com>
Sun, 15 Apr 2012 21:41:54 +0000 (17:41 -0400)
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)

test/data/testinit.js
test/unit/attributes.js
test/unit/core.js
test/unit/manipulation.js

index 43244e7eb69e5181782ea28cdb0d34f5983d00f5..1f775c1d716c1df0068798e15db750bb943f926c 100644 (file)
@@ -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() {
+       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();
        };
-})();
\ No newline at end of file
+})();
index 9fc6ac61f33410da8f05f542ace7e572348329d7..5554beea46aaf8f2b46ed44f2dd4af65dfa17967 100644 (file)
@@ -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);
index e87c10664e2537372a5cd2e995fc49b12788c526..b0e9e5b9afb2290fc972ac72db64d87412fd3e13 100644 (file)
@@ -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();
+       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);
index 9209b1dd98d7c698b3a9c46e4dfc4f8c7456a989..4aae3e28ea6e73f787e2586aa552b850fb7ed558 100644 (file)
@@ -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);