Build: Bump the github-actions group across 1 directory with 2 updates
[jquery.git] / test / unit / support.js
blobbf3f4d26d4fda3f110de2867a6a8e0cd0fa28830
1 QUnit.module( "support", { afterEach: moduleTeardown } );
3 var computedSupport = getComputedSupport( jQuery.support );
5 function getComputedSupport( support ) {
6 var prop,
7 result = {};
9 for ( prop in support ) {
10 if ( typeof support[ prop ] === "function" ) {
11 result[ prop ] = support[ prop ]();
12 } else {
13 result[ prop ] = support[ prop ];
17 return result;
20 if ( includesModule( "css" ) ) {
21 testIframe(
22 "body background is not lost if set prior to loading jQuery (trac-9239)",
23 "support/bodyBackground.html",
24 function( assert, jQuery, window, document, color, support ) {
25 assert.expect( 2 );
26 var okValue = {
27 "#000000": true,
28 "rgb(0, 0, 0)": true
30 assert.ok( okValue[ color ], "color was not reset (" + color + ")" );
32 assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
33 "Same support properties" );
38 // This test checks CSP only for browsers with "Content-Security-Policy" header support
39 // i.e. no IE
40 testIframe(
41 "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
42 "mock.php?action=cspFrame",
43 function( assert, jQuery, window, document, support ) {
44 var done = assert.async();
46 assert.expect( 2 );
47 assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
48 "No violations of CSP polices" );
50 supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) {
51 assert.equal( data, "", "No log request should be sent" );
52 supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
53 } );
57 testIframe(
58 "Verify correctness of support tests with bootstrap CSS on the page",
59 "support/bootstrap.html",
60 function( assert, jQuery, window, document, bodyStyle, support ) {
61 assert.expect( 2 );
62 assert.strictEqual( bodyStyle.boxSizing, "border-box",
63 "border-box applied on body by Bootstrap" );
64 assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
65 "Same support properties" );
69 testIframe(
70 "Verify correctness of support tests with CSS zoom on the root element",
71 "support/zoom.html",
72 function( assert, jQuery, window, document, htmlStyle, support ) {
73 assert.expect( 1 );
74 assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
75 "Same support properties" );
79 ( function() {
80 var expected, browserKey,
81 userAgent = window.navigator.userAgent,
82 expectedMap = {
83 ie_11: {
84 cssHas: true,
85 reliableTrDimensions: false
87 chrome_111: {
88 cssHas: false,
89 reliableTrDimensions: true
91 chrome: {
92 cssHas: true,
93 reliableTrDimensions: true
95 safari_16_3: {
96 cssHas: false,
97 reliableTrDimensions: true
99 safari: {
100 cssHas: true,
101 reliableTrDimensions: true
103 firefox: {
104 cssHas: true,
105 reliableTrDimensions: false
107 ios_14_15_3: {
108 cssHas: true,
109 reliableTrDimensions: true
111 ios_15_4_16_3: {
112 cssHas: false,
113 reliableTrDimensions: true
115 ios: {
116 cssHas: true,
117 reliableTrDimensions: true
121 // Make the selector-native build pass tests.
122 for ( browserKey in expectedMap ) {
123 if ( !includesModule( "selector" ) ) {
124 delete expectedMap[ browserKey ].cssHas;
128 if ( document.documentMode ) {
129 expected = expectedMap.ie_11;
130 } else if ( /\b(?:headless)?chrome\/(?:10\d|11[01])\b/i.test( userAgent ) ) {
131 expected = expectedMap.chrome_111;
132 } else if ( /\b(?:headless)?chrome\//i.test( userAgent ) ) {
134 // Catches Edge, Chrome on Android & Opera as well.
135 expected = expectedMap.chrome;
136 } else if ( /\bfirefox\//i.test( userAgent ) ) {
137 expected = expectedMap.firefox;
138 } else if ( /\biphone os (?:14_|15_[0123])/i.test( userAgent ) ) {
139 expected = expectedMap.ios_14_15_3;
140 } else if ( /\biphone os (?:15_|16_[0123])/i.test( userAgent ) ) {
141 expected = expectedMap.ios_15_4_16_3;
142 } else if ( /\b(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) {
143 expected = expectedMap.ios;
144 } else if ( /\bversion\/(?:15|16\.[0123])(?:\.\d+)* safari/i.test( userAgent ) ) {
145 expected = expectedMap.safari_16_3;
146 } else if ( /\bversion\/\d+(?:\.\d+)+ safari/i.test( userAgent ) ) {
147 expected = expectedMap.safari;
150 QUnit.test( "Verify that support tests resolve as expected per browser", function( assert ) {
151 if ( !expected ) {
152 assert.expect( 1 );
153 assert.ok( false, "Known client: " + userAgent );
156 var i, prop,
157 j = 0;
159 for ( prop in computedSupport ) {
160 j++;
163 // Add an assertion per undefined support prop as it may
164 // not even exist on computedSupport but we still want to run
165 // the check.
166 for ( prop in expected ) {
167 if ( expected[ prop ] === undefined ) {
168 j++;
172 assert.expect( j );
174 for ( i in expected ) {
175 assert.equal( computedSupport[ i ], expected[ i ],
176 "jQuery.support['" + i + "']: " + computedSupport[ i ] +
177 ", expected['" + i + "']: " + expected[ i ] +
178 ";\nUser Agent: " + navigator.userAgent );
180 } );
182 QUnit.test( "Verify support tests are failing in one of tested browsers",
183 function( assert ) {
185 var prop, browserKey, supportTestName,
186 i = 0,
187 supportProps = {},
188 failingSupportProps = {};
190 for ( prop in computedSupport ) {
191 i++;
194 // Add an assertion per undefined support prop as it may
195 // not even exist on computedSupport but we still want to run
196 // the check.
197 for ( prop in expected ) {
198 if ( expected[ prop ] === undefined ) {
199 i++;
203 assert.expect( i );
205 // Record all support props and the failing ones and ensure every test
206 // is failing at least once.
207 for ( browserKey in expectedMap ) {
208 for ( supportTestName in expectedMap[ browserKey ] ) {
209 supportProps[ supportTestName ] = true;
210 if ( !expectedMap[ browserKey ][ supportTestName ] ) {
211 failingSupportProps[ supportTestName ] = true;
216 for ( supportTestName in supportProps ) {
217 assert.ok( failingSupportProps[ supportTestName ],
218 "jQuery.support['" + supportTestName +
219 "'] is expected to fail at least in one browser" );
221 } );
223 } )();