aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/runtest/env.js43
-rw-r--r--build/runtest/test.js1
-rw-r--r--build/runtest/testrunner.js13
-rw-r--r--build/test/data/json_obj.js1
-rw-r--r--build/test/data/name.html1
-rw-r--r--src/ajax/ajaxTest.js62
6 files changed, 74 insertions, 47 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>
diff --git a/src/ajax/ajaxTest.js b/src/ajax/ajaxTest.js
index 851be5163..200376c00 100644
--- a/src/ajax/ajaxTest.js
+++ b/src/ajax/ajaxTest.js
@@ -1,7 +1,5 @@
module("ajax");
-if ( location.protocol != "file:" ) {
-
test("serialize()", function() {
expect(1);
var data = $(':input').not('button').serialize();
@@ -24,6 +22,31 @@ test("param", function() {
ok( $.param(params) == "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All%20your%20base%20are%20belong%20to%20us", "even more arrays" );
});
+test("evalScripts() with no script elements", function() {
+ expect(2);
+
+ var data = "this is just some bogus text";
+ $('#foo').html(data);
+ ok ( true, 'before evalScripts()');
+ try {
+ $('#foo').evalScripts();
+ } catch(e) {
+ ok (false, 'exception evaluating scripts: ' + e.message);
+ }
+ ok ( true, 'after evalScripts()');
+});
+
+test("synchronous request", function() {
+ ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
+});
+
+test("synchronous request with callbacks", function() {
+ expect(2);
+ var result;
+ $.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
+ ok( /^{ "data"/.test( result ), "check returned text" );
+});
+
test("pass-through request object", function() {
expect(7);
stop(true);
@@ -32,30 +55,19 @@ test("pass-through request object", function() {
if(count++ == 6)
start();
}
- var target = "data/name.php";
+ var target = "data/name.html";
ok( $.get(url(target), success), "get" );
ok( $.getIfModified(url(target), success), "getIfModified" );
ok( $.post(url(target), success), "post" );
ok( $.getScript(url("data/test.js"), success), "script" );
- ok( $.getJSON(url("data/json.php"), success), "json" );
+ ok( $.getJSON(url("data/json_obj.js"), success), "json" );
ok( $.ajax({url: url(target), success: success}), "generic" );
});
-test("synchronous request", function() {
- ok( /^{ "data"/.test( $.ajax({url: url("data/json.php"), async: false}).responseText ), "check returned text" );
-});
-
-test("synchronous request with callbacks", function() {
- expect(2);
- var result;
- $.ajax({url: url("data/json.php"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
- ok( /^{ "data"/.test( result ), "check returned text" );
-});
-
test("load(String, Object, Function) - simple: inject text into DOM", function() {
expect(2);
stop();
- $('#first').load(url("data/name.php"), function() {
+ $('#first').load(url("data/name.html"), function() {
ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' );
start();
});
@@ -64,9 +76,11 @@ test("load(String, Object, Function) - simple: inject text into DOM", function()
test("load(String, Object, Function) - inject without callback", function() {
expect(1);
stop(true); // check if load can be called with only url
- $('#first').load("data/name.php");
+ $('#first').load("data/name.html");
});
+if ( location.protocol != "file:" ) {
+
test("load(String, Object, Function) - check scripts", function() {
expect(7);
stop();
@@ -365,20 +379,6 @@ test("ajaxSetup()", function() {
$.ajax();
});
-test("evalScripts() with no script elements", function() {
- expect(2);
-
- var data = "this is just some bogus text";
- $('#foo').html(data);
- ok ( true, 'before evalScripts()');
- try {
- $('#foo').evalScripts();
- } catch(e) {
- ok (false, 'exception evaluating scripts: ' + e.message);
- }
- ok ( true, 'after evalScripts()');
-});
-
test("custom timeout does not set error message when timeout occurs, see #970", function() {
stop();
$.ajax({