aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-01-09 06:01:00 +0100
committerjaubourg <j@ubourg.net>2011-01-09 06:01:00 +0100
commitafefb4f3d28f47c0a93cc9dfddfcbadb595a8efb (patch)
tree73c20f0ba02aa86f892755b46b3e294c8eb77ad3 /test/unit/ajax.js
parentd515068ee807efef29b6c8406171be4725d7154f (diff)
downloadjquery-afefb4f3d28f47c0a93cc9dfddfcbadb595a8efb.tar.gz
jquery-afefb4f3d28f47c0a93cc9dfddfcbadb595a8efb.zip
Fixes #7465. Reworked the regexp and associated test for cross-domain detection so that it now includes ports. Added cross-domain detection tests for protocol, hostname and port.
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index adf589e1a..14f892857 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -358,6 +358,58 @@ test(".ajax() - hash", function() {
});
});
+test("jQuery ajax - cross-domain detection", function() {
+
+ expect( 3 );
+
+ var loc = document.location,
+ otherPort = loc.port === 666 ? 667 : 666,
+ otherProtocol = loc.protocol === "http:" ? "https:" : "http:",
+ protocolFlag,
+ hostFlag,
+ portFlag;
+
+ if ( jQuery.ajax({
+ url: otherProtocol + "//" + loc.host,
+ beforeSend: function( _ , s ) {
+ protocolFlag = 1;
+ ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
+ return false;
+ }
+ }) === false ) {
+ if ( ! protocolFlag ) {
+ ok( ! jQuery.support.cors , "Test different protocols are detected as cross-domain (no transport)" );
+ }
+ }
+
+ if ( jQuery.ajax({
+ url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
+ beforeSend: function( _ , s ) {
+ hostFlag = 1;
+ ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
+ return false;
+ }
+ }) === false ) {
+ if ( ! hostFlag ) {
+ ok( ! jQuery.support.cors , "Test different hostnames are detected as cross-domain (no transport)" );
+ }
+ }
+
+ if ( jQuery.ajax({
+ url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
+ beforeSend: function( _ , s ) {
+ portFlag = 1;
+ ok( s.crossDomain , "Test different ports are detected as cross-domain" );
+ return false;
+ }
+ }) === false ) {
+ if ( ! portFlag ) {
+ ok( ! jQuery.support.cors , "Test different ports are detected as cross-domain (no transport)" );
+ }
+ }
+
+});
+
test(".ajax() - 304", function() {
expect( 1 );
stop();