No Description

support.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. QUnit.module( "support", { afterEach: moduleTeardown } );
  2. var computedSupport = getComputedSupport( jQuery.support );
  3. function getComputedSupport( support ) {
  4. var prop,
  5. result = {};
  6. for ( prop in support ) {
  7. if ( typeof support[ prop ] === "function" ) {
  8. result[ prop ] = support[ prop ]();
  9. } else {
  10. result[ prop ] = support[ prop ];
  11. }
  12. }
  13. return result;
  14. }
  15. if ( jQuery.css ) {
  16. testIframe(
  17. "body background is not lost if set prior to loading jQuery (#9239)",
  18. "support/bodyBackground.html",
  19. function( assert, jQuery, window, document, color, support ) {
  20. assert.expect( 2 );
  21. var okValue = {
  22. "#000000": true,
  23. "rgb(0, 0, 0)": true
  24. };
  25. assert.ok( okValue[ color ], "color was not reset (" + color + ")" );
  26. assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
  27. "Same support properties" );
  28. }
  29. );
  30. }
  31. // This test checks CSP only for browsers with "Content-Security-Policy" header support
  32. // i.e. no old WebKit or old Firefox
  33. testIframe(
  34. "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
  35. "mock.php?action=cspFrame",
  36. function( assert, jQuery, window, document, support ) {
  37. var done = assert.async();
  38. assert.expect( 2 );
  39. assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
  40. "No violations of CSP polices" );
  41. supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) {
  42. assert.equal( data, "", "No log request should be sent" );
  43. supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
  44. } );
  45. }
  46. );
  47. ( function() {
  48. var browserKey, expected,
  49. userAgent = window.navigator.userAgent,
  50. expectedMap = {
  51. edge: {
  52. "ajax": true,
  53. "boxSizingReliable": true,
  54. "checkClone": true,
  55. "checkOn": true,
  56. "clearCloneStyle": true,
  57. "cors": true,
  58. "createHTMLDocument": true,
  59. "focusin": false,
  60. "noCloneChecked": true,
  61. "option": true,
  62. "optSelected": true,
  63. "pixelBoxStyles": true,
  64. "pixelPosition": true,
  65. "radioValue": true,
  66. "reliableMarginLeft": true,
  67. "reliableTrDimensions": false,
  68. "scrollboxSize": true
  69. },
  70. ie_10_11: {
  71. "ajax": true,
  72. "boxSizingReliable": false,
  73. "checkClone": true,
  74. "checkOn": true,
  75. "clearCloneStyle": false,
  76. "cors": true,
  77. "createHTMLDocument": true,
  78. "focusin": true,
  79. "noCloneChecked": false,
  80. "option": true,
  81. "optSelected": false,
  82. "pixelBoxStyles": true,
  83. "pixelPosition": true,
  84. "radioValue": false,
  85. "reliableMarginLeft": true,
  86. "reliableTrDimensions": false,
  87. "scrollboxSize": true
  88. },
  89. ie_9: {
  90. "ajax": true,
  91. "boxSizingReliable": false,
  92. "checkClone": true,
  93. "checkOn": true,
  94. "clearCloneStyle": false,
  95. "cors": false,
  96. "createHTMLDocument": true,
  97. "focusin": true,
  98. "noCloneChecked": false,
  99. "option": false,
  100. "optSelected": false,
  101. "pixelBoxStyles": true,
  102. "pixelPosition": true,
  103. "radioValue": false,
  104. "reliableMarginLeft": true,
  105. "reliableTrDimensions": false,
  106. "scrollboxSize": false
  107. },
  108. chrome: {
  109. "ajax": true,
  110. "boxSizingReliable": true,
  111. "checkClone": true,
  112. "checkOn": true,
  113. "clearCloneStyle": true,
  114. "cors": true,
  115. "createHTMLDocument": true,
  116. "focusin": false,
  117. "noCloneChecked": true,
  118. "option": true,
  119. "optSelected": true,
  120. "pixelBoxStyles": true,
  121. "pixelPosition": true,
  122. "radioValue": true,
  123. "reliableMarginLeft": true,
  124. "reliableTrDimensions": true,
  125. "scrollboxSize": true
  126. },
  127. safari: {
  128. "ajax": true,
  129. "boxSizingReliable": true,
  130. "checkClone": true,
  131. "checkOn": true,
  132. "clearCloneStyle": true,
  133. "cors": true,
  134. "createHTMLDocument": true,
  135. "focusin": false,
  136. "noCloneChecked": true,
  137. "option": true,
  138. "optSelected": true,
  139. "pixelBoxStyles": true,
  140. "pixelPosition": true,
  141. "radioValue": true,
  142. "reliableMarginLeft": true,
  143. "reliableTrDimensions": true,
  144. "scrollboxSize": true
  145. },
  146. safari_9_10: {
  147. "ajax": true,
  148. "boxSizingReliable": true,
  149. "checkClone": true,
  150. "checkOn": true,
  151. "clearCloneStyle": true,
  152. "cors": true,
  153. "createHTMLDocument": true,
  154. "focusin": false,
  155. "noCloneChecked": true,
  156. "option": true,
  157. "optSelected": true,
  158. "pixelBoxStyles": false,
  159. "pixelPosition": false,
  160. "radioValue": true,
  161. "reliableMarginLeft": true,
  162. "reliableTrDimensions": true,
  163. "scrollboxSize": true
  164. },
  165. firefox: {
  166. "ajax": true,
  167. "boxSizingReliable": true,
  168. "checkClone": true,
  169. "checkOn": true,
  170. "clearCloneStyle": true,
  171. "cors": true,
  172. "createHTMLDocument": true,
  173. "focusin": false,
  174. "noCloneChecked": true,
  175. "option": true,
  176. "optSelected": true,
  177. "pixelBoxStyles": true,
  178. "pixelPosition": true,
  179. "radioValue": true,
  180. "reliableMarginLeft": true,
  181. "reliableTrDimensions": false,
  182. "scrollboxSize": true
  183. },
  184. firefox_60: {
  185. "ajax": true,
  186. "boxSizingReliable": true,
  187. "checkClone": true,
  188. "checkOn": true,
  189. "clearCloneStyle": true,
  190. "cors": true,
  191. "createHTMLDocument": true,
  192. "focusin": false,
  193. "noCloneChecked": true,
  194. "option": true,
  195. "optSelected": true,
  196. "pixelBoxStyles": true,
  197. "pixelPosition": true,
  198. "radioValue": true,
  199. "reliableMarginLeft": false,
  200. "reliableTrDimensions": true,
  201. "scrollboxSize": true
  202. },
  203. ios: {
  204. "ajax": true,
  205. "boxSizingReliable": true,
  206. "checkClone": true,
  207. "checkOn": true,
  208. "clearCloneStyle": true,
  209. "cors": true,
  210. "createHTMLDocument": true,
  211. "focusin": false,
  212. "noCloneChecked": true,
  213. "option": true,
  214. "optSelected": true,
  215. "pixelBoxStyles": true,
  216. "pixelPosition": true,
  217. "radioValue": true,
  218. "reliableMarginLeft": true,
  219. "reliableTrDimensions": true,
  220. "scrollboxSize": true
  221. },
  222. ios_9_10: {
  223. "ajax": true,
  224. "boxSizingReliable": true,
  225. "checkClone": true,
  226. "checkOn": true,
  227. "clearCloneStyle": true,
  228. "cors": true,
  229. "createHTMLDocument": true,
  230. "focusin": false,
  231. "noCloneChecked": true,
  232. "option": true,
  233. "optSelected": true,
  234. "pixelBoxStyles": false,
  235. "pixelPosition": false,
  236. "radioValue": true,
  237. "reliableMarginLeft": true,
  238. "reliableTrDimensions": true,
  239. "scrollboxSize": true
  240. },
  241. ios_8: {
  242. "ajax": true,
  243. "boxSizingReliable": true,
  244. "checkClone": true,
  245. "checkOn": true,
  246. "clearCloneStyle": true,
  247. "cors": true,
  248. "createHTMLDocument": false,
  249. "focusin": false,
  250. "noCloneChecked": true,
  251. "option": true,
  252. "optSelected": true,
  253. "pixelBoxStyles": false,
  254. "pixelPosition": false,
  255. "radioValue": true,
  256. "reliableMarginLeft": true,
  257. "reliableTrDimensions": true,
  258. "scrollboxSize": true
  259. },
  260. ios_7: {
  261. "ajax": true,
  262. "boxSizingReliable": true,
  263. "checkClone": true,
  264. "checkOn": true,
  265. "clearCloneStyle": true,
  266. "cors": true,
  267. "createHTMLDocument": true,
  268. "focusin": false,
  269. "noCloneChecked": true,
  270. "option": true,
  271. "optSelected": true,
  272. "pixelBoxStyles": false,
  273. "pixelPosition": false,
  274. "radioValue": true,
  275. "reliableMarginLeft": true,
  276. "reliableTrDimensions": true,
  277. "scrollboxSize": true
  278. },
  279. android: {
  280. "ajax": true,
  281. "boxSizingReliable": true,
  282. "checkClone": false,
  283. "checkOn": false,
  284. "clearCloneStyle": true,
  285. "cors": true,
  286. "createHTMLDocument": true,
  287. "focusin": false,
  288. "noCloneChecked": true,
  289. "option": true,
  290. "optSelected": true,
  291. "pixelBoxStyles": false,
  292. "pixelPosition": false,
  293. "radioValue": true,
  294. "reliableMarginLeft": false,
  295. "reliableTrDimensions": true,
  296. "scrollboxSize": true
  297. }
  298. };
  299. // Make the slim build pass tests.
  300. for ( browserKey in expectedMap ) {
  301. if ( !jQuery.ajax ) {
  302. delete expectedMap[ browserKey ].ajax;
  303. delete expectedMap[ browserKey ].cors;
  304. }
  305. }
  306. if ( /edge\//i.test( userAgent ) ) {
  307. expected = expectedMap.edge;
  308. } else if ( /(msie 10\.0|trident\/7\.0)/i.test( userAgent ) ) {
  309. expected = expectedMap.ie_10_11;
  310. } else if ( /msie 9\.0/i.test( userAgent ) ) {
  311. expected = expectedMap.ie_9;
  312. } else if ( /chrome/i.test( userAgent ) ) {
  313. // Catches Chrome on Android as well (i.e. the default
  314. // Android browser on Android >= 4.4).
  315. expected = expectedMap.chrome;
  316. } else if ( /\b(?:9|10)\.\d+(\.\d+)* safari/i.test( userAgent ) ) {
  317. expected = expectedMap.safari_9_10;
  318. } else if ( /firefox\/(?:4\d|5\d|60)/i.test( userAgent ) ) {
  319. expected = expectedMap.firefox_60;
  320. } else if ( /firefox/i.test( userAgent ) ) {
  321. expected = expectedMap.firefox;
  322. } else if ( /android 4\.[0-3]/i.test( userAgent ) ) {
  323. expected = expectedMap.android;
  324. } else if ( /iphone os (?:9|10)_/i.test( userAgent ) ) {
  325. expected = expectedMap.ios_9_10;
  326. } else if ( /iphone os 8_/i.test( userAgent ) ) {
  327. expected = expectedMap.ios_8;
  328. } else if ( /iphone os 7_/i.test( userAgent ) ) {
  329. expected = expectedMap.ios_7;
  330. } else if ( /(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) {
  331. expected = expectedMap.ios;
  332. } else if ( /\b\d+(\.\d+)+ safari/i.test( userAgent ) ) {
  333. expected = expectedMap.safari;
  334. }
  335. QUnit.test( "Verify that support tests resolve as expected per browser", function( assert ) {
  336. if ( !expected ) {
  337. assert.expect( 1 );
  338. assert.ok( false, "Known client: " + userAgent );
  339. }
  340. var i, prop,
  341. j = 0;
  342. for ( prop in computedSupport ) {
  343. j++;
  344. }
  345. assert.expect( j );
  346. for ( i in expected ) {
  347. if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
  348. assert.equal( computedSupport[ i ], expected[ i ],
  349. "jQuery.support['" + i + "']: " + computedSupport[ i ] +
  350. ", expected['" + i + "']: " + expected[ i ] );
  351. } else {
  352. assert.ok( true, "no ajax; skipping jQuery.support['" + i + "']" );
  353. }
  354. }
  355. } );
  356. QUnit.test( "Verify most support tests are failing in one " +
  357. "of tested browsers", function( assert ) {
  358. var prop, browserKey, supportTestName,
  359. i = 0,
  360. supportProps = {},
  361. failingSupportProps = {},
  362. whitelist = {
  363. ajax: true
  364. };
  365. for ( prop in computedSupport ) {
  366. i++;
  367. }
  368. assert.expect( i );
  369. // Record all support props and the failing ones and ensure everyone
  370. // except a few on a whitelist are failing at least once.
  371. for ( browserKey in expectedMap ) {
  372. for ( supportTestName in expectedMap[ browserKey ] ) {
  373. supportProps[ supportTestName ] = true;
  374. if ( expectedMap[ browserKey ][ supportTestName ] !== true ) {
  375. failingSupportProps[ supportTestName ] = true;
  376. }
  377. }
  378. }
  379. for ( supportTestName in supportProps ) {
  380. assert.ok( whitelist[ supportTestName ] || failingSupportProps[ supportTestName ],
  381. "jQuery.support['" + supportTestName + "'] always succeeds; remove it?" );
  382. }
  383. } );
  384. } )();