Skip to content

Commit a467f86

Browse files
committed
Manipulation: improve test for data-URI
Some environments do not support data-uri in "src" attribute of script element. Mitigate it with equality assertion
1 parent ef93f95 commit a467f86

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

test/unit/manipulation.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,15 +2462,28 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1,
24622462
equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
24632463
});
24642464

2465-
// IE8 doesn't support data-URI in src attribute of script element
2466-
// Relevant - http://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx
2467-
if ( !/msie 8\.0/i.test( navigator.userAgent ) ) {
2468-
asyncTest( "Insert script with data-URI (gh-1887)", 1, function() {
2469-
Globals.register( "testFoo" );
2470-
jQuery( "#qunit-fixture" ).append( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" );
2471-
setTimeout(function (){
2472-
strictEqual( window[ "testFoo" ], "foo", "data-URI script executed" );
2473-
start();
2474-
}, 100 );
2465+
asyncTest( "Insert script with data-URI (gh-1887)", 1, function() {
2466+
Globals.register( "testFoo" );
2467+
Globals.register( "testSrcFoo" );
2468+
2469+
var script = document.createElement( "script" ),
2470+
fixture = document.getElementById( "qunit-fixture" );
2471+
2472+
script.src = "data:text/javascript,testSrcFoo = 'foo';";
2473+
2474+
fixture.appendChild( script );
2475+
2476+
jQuery( fixture ).append( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" );
2477+
2478+
setTimeout(function() {
2479+
if ( window[ "testSrcFoo" ] === "foo" ) {
2480+
strictEqual( window[ "testFoo" ], window[ "testSrcFoo" ], "data-URI script executed" );
2481+
2482+
} else {
2483+
ok( true, "data-URI script is not supported by this environment" );
2484+
}
2485+
2486+
start();
24752487
});
2476-
}
2488+
});
2489+

0 commit comments

Comments
 (0)