diff options
author | Yehuda Katz <wycats@gmail.com> | 2012-04-15 17:41:54 -0400 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2012-04-15 17:41:54 -0400 |
commit | 6bc08c2b2f04629114ae7ca79c3c2c54320e4908 (patch) | |
tree | 48dd57b8575a5abee26e1cc4870cd78fd1ce49ca /test | |
parent | 5181ce0f35cf941ae2d7f5da2cf98ebcc638daff (diff) | |
download | jquery-6bc08c2b2f04629114ae7ca79c3c2c54320e4908.tar.gz jquery-6bc08c2b2f04629114ae7ca79c3c2c54320e4908.zip |
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)
Diffstat (limited to 'test')
-rw-r--r-- | test/data/testinit.js | 51 | ||||
-rw-r--r-- | test/unit/attributes.js | 19 | ||||
-rw-r--r-- | test/unit/core.js | 34 | ||||
-rw-r--r-- | test/unit/manipulation.js | 21 |
4 files changed, 78 insertions, 47 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js index 43244e7eb..1f775c1d7 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.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() { + 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 +})(); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9fc6ac61f..5554beea4 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -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); diff --git a/test/unit/core.js b/test/unit/core.js index e87c10664..b0e9e5b9a 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 9209b1dd9..4aae3e28e 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -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); |