JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css">
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
JavaScript
test("jQuery ajax - cross-domain detection", function() {
expect( 7 );
var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666,
defaultPort = loc.protocol === "http:" ? 80 : 443,
otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
jQuery.ajax({
dataType: "jsonp",
url: otherProtocol + "//" + loc.host,
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: "app:/path",
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + "//somewebsitethatdoesnotexist-656329477541.com:" + ( loc.port || 80 ),
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test different ports are detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + "//" + loc.hostname + ":" + defaultPort,
beforeSend: function( _ , s ) {
ok( !s.crossDomain , "Test default ports are detected as not cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: "about:blank",
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test about:blank is detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url:...