diff options
author | John Resig <jeresig@gmail.com> | 2007-07-09 03:08:20 +0000 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2007-07-09 03:08:20 +0000 |
commit | d776dc9d5c5322e81b56272728325990ed6892bb (patch) | |
tree | 6cefa18ab59919ecd6f872d749874b9df997d45f /build | |
parent | de71a046e619884292b122ddcf1401ad9932a5c7 (diff) | |
download | jquery-d776dc9d5c5322e81b56272728325990ed6892bb.tar.gz jquery-d776dc9d5c5322e81b56272728325990ed6892bb.zip |
Got some XHR tests to run, still some hanging threads (need to investigate). Started moving some Ajax tests away from using PHP (more portable this way). Fixed a number of XHR env bugs.
Diffstat (limited to 'build')
-rw-r--r-- | build/runtest/env.js | 43 | ||||
-rw-r--r-- | build/runtest/test.js | 1 | ||||
-rw-r--r-- | build/runtest/testrunner.js | 13 | ||||
-rw-r--r-- | build/test/data/json_obj.js | 1 | ||||
-rw-r--r-- | build/test/data/name.html | 1 |
5 files changed, 43 insertions, 16 deletions
diff --git a/build/runtest/env.js b/build/runtest/env.js index 23ffaeddd..b2a94ff06 100644 --- a/build/runtest/env.js +++ b/build/runtest/env.js @@ -17,17 +17,21 @@ var window = this; } }; + var curLocation = (new java.io.File("./")).toURL(); + window.__defineSetter__("location", function(url){ + curLocation = new java.net.URL( curLocation, url ); + window.document = new DOMDocument( new Packages.org.xml.sax.InputSource( new java.io.InputStreamReader( - new java.io.FileInputStream(url)))); + new java.io.FileInputStream( url )))); }); window.__defineGetter__("location", function(url){ return { get protocol(){ - return "file:"; + return curLocation.getProtocol() + ":"; } }; }); @@ -490,28 +494,30 @@ var window = this; }, getResponseHeader: function(header){ }, send: function(data){ + var self = this; + function makeRequest(){ - var url = new java.net.URL(this.url), + var url = new java.net.URL(curLocation, self.url), connection = url.openConnection(); // Add headers to Java connection - for (var header in this.headers) - connection.addRequestProperty(header, this.headers[header]); + for (var header in self.headers) + connection.addRequestProperty(header, self.headers[header]); connection.connect(); // Stick the response headers into responseHeaders - for (i=0; ; i++) { + for (var i=0; ; i++) { var headerName = connection.getHeaderFieldKey(i); var headerValue = connection.getHeaderField(i); if (!headerName && !headerValue) break; if (headerName) - this.responseHeaders[headerName] = headerValue; + self.responseHeaders[headerName] = headerValue; } - this.readyState = 4; - this.status = parseInt(connection.responseCode); - this.statusText = connection.responseMessage; + self.readyState = 4; + self.status = parseInt(connection.responseCode); + self.statusText = connection.responseMessage; var stream = new java.io.InputStreamReader( connection.getInputStream()), @@ -519,15 +525,20 @@ var window = this; line; while ((line = buffer.readLine()) != null) - this.responseText += line; + self.responseText += line; + + self.responseXML = null; - try { - this.responseXML = new DOMDocument(this.responseText); - } catch(e) { - this.responseXML = null; + if ( self.responseText.match(/^\s*</) ) { + try { + self.responseXML = new DOMDocument( + new java.io.ByteArrayInputStream( + (new java.lang.String( + self.responseText)).getBytes("UTF8"))); + } catch(e) {} } - this.onreadystatechange(); + self.onreadystatechange(); } if (this.async) diff --git a/build/runtest/test.js b/build/runtest/test.js index 1831e2f04..1bc9ac125 100644 --- a/build/runtest/test.js +++ b/build/runtest/test.js @@ -11,6 +11,7 @@ load( "src/selector/selectorTest.js", "src/event/eventTest.js", "src/fx/fxTest.js" + //"src/ajax/ajaxTest.js" ); // Display the results diff --git a/build/runtest/testrunner.js b/build/runtest/testrunner.js index 27822f9e3..363cd9bd9 100644 --- a/build/runtest/testrunner.js +++ b/build/runtest/testrunner.js @@ -181,4 +181,17 @@ function triggerEvent( elem, type, event ) { elem.fireEvent("on"+type); } */ +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); }
\ No newline at end of file diff --git a/build/test/data/json_obj.js b/build/test/data/json_obj.js new file mode 100644 index 000000000..7fa61820f --- /dev/null +++ b/build/test/data/json_obj.js @@ -0,0 +1 @@ +{ "data": {"lang": "en", "length": 25} } diff --git a/build/test/data/name.html b/build/test/data/name.html new file mode 100644 index 000000000..0fa32d1a8 --- /dev/null +++ b/build/test/data/name.html @@ -0,0 +1 @@ +ERROR <script type="text/javascript">ok( true, "name.html retrieved" );</script> |