forked from jquery/jquery
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrusted-types-attributes.html
61 lines (55 loc) · 1.46 KB
/
trusted-types-attributes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Trusted HTML attribute tests</title>
</head>
<body>
<div id="qunit-fixture"></div>
<script src="../../dist/jquery.js"></script>
<script src="iframeTest.js"></script>
<script>
var i, input, elem, policy,
results = [];
function runTests( messagePrefix, getTrustedScriptUrlWrapper ) {
try {
elem = jQuery( "<script><\/script>" )
.attr( "src", getTrustedScriptUrlWrapper( "trusted-types-attributes.js" ) );
elem.appendTo( document.body );
results.push( {
actual: elem.attr( "src" ),
expected: "trusted-types-attributes.js",
message: messagePrefix + ": script URL properly set"
} );
} catch ( e ) {
results.push( {
actual: "error thrown",
expected: "",
message: messagePrefix + ": error has been thrown"
} );
}
}
if ( typeof trustedTypes !== "undefined" ) {
policy = trustedTypes.createPolicy( "jquery-test-policy", {
createScriptURL: function( html ) {
return html;
}
} );
runTests( "TrustedScriptURL", function wrapInTrustedScriptUrl( input ) {
return policy.createScriptURL( input );
} );
} else {
// No TrustedScriptURL support so let's at least run tests with object wrappers
// with a proper `toString` function. See trusted-html.html for more context.
runTests( "Object wrapper", function( input ) {
return {
toString: function toString() {
return input;
}
};
} );
}
startIframeTest( results );
</script>
</body>
</html>