From d776dc9d5c5322e81b56272728325990ed6892bb Mon Sep 17 00:00:00 2001 From: John Resig Date: Mon, 9 Jul 2007 03:08:20 +0000 Subject: 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. --- build/runtest/env.js | 43 +++++++++++++++++++++++++++---------------- build/runtest/test.js | 1 + build/runtest/testrunner.js | 13 +++++++++++++ build/test/data/json_obj.js | 1 + build/test/data/name.html | 1 + 5 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 build/test/data/json_obj.js create mode 100644 build/test/data/name.html (limited to 'build') 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*ok( true, "name.html retrieved" ); -- cgit v1.2.3