lady_josephine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/app/assets/fonts/lady_josephine/icons/icons.eot +0 -0
  5. data/app/assets/fonts/lady_josephine/icons/icons.svg +215 -0
  6. data/app/assets/fonts/lady_josephine/icons/icons.ttf +0 -0
  7. data/app/assets/fonts/lady_josephine/icons/icons.woff +0 -0
  8. data/app/assets/javascripts/lady_josephine/blocks/facebook.js +25 -0
  9. data/app/assets/javascripts/lady_josephine/blocks/instagram.js +22 -0
  10. data/app/assets/javascripts/lady_josephine/blocks/soundcloud.js +24 -0
  11. data/app/assets/javascripts/lady_josephine/blocks/twitter.js +25 -0
  12. data/app/assets/javascripts/lady_josephine/blocks/vimeo.js +55 -0
  13. data/app/assets/javascripts/lady_josephine/blocks/youtube.js +64 -0
  14. data/app/assets/javascripts/lady_josephine/editor.js +40 -0
  15. data/app/assets/javascripts/lady_josephine/lady_josephine.js +4 -0
  16. data/app/assets/javascripts/lady_josephine/lady_josephine_view.js +6 -0
  17. data/app/assets/stylesheets/lady_josephine/content.sass +33 -0
  18. data/app/assets/stylesheets/lady_josephine/icons.sass +175 -0
  19. data/app/assets/stylesheets/lady_josephine/lady_josephine.sass +6 -0
  20. data/app/assets/stylesheets/lady_josephine/sir_trevor.sass +619 -0
  21. data/app/assets/stylesheets/lady_josephine/vars.sass +36 -0
  22. data/app/controllers/lady_josephine/application_controller.rb +4 -0
  23. data/app/controllers/lady_josephine/editor_controller.rb +40 -0
  24. data/app/controllers/lady_josephine/images_controller.rb +26 -0
  25. data/app/helpers/lady_josephine/helper.rb +25 -0
  26. data/app/helpers/lady_josephine/sir_trevor_helper.rb +172 -0
  27. data/app/models/lady_josephine/concerns/model.rb +29 -0
  28. data/app/models/lady_josephine/concerns/pingable.rb +28 -0
  29. data/app/models/lady_josephine/concerns/server_uuid.rb +24 -0
  30. data/app/models/lady_josephine/concerns/sir_trevor_images.rb +38 -0
  31. data/app/models/lady_josephine/image.rb +41 -0
  32. data/app/uploader/lady_josephine/base_uploader.rb +47 -0
  33. data/app/uploader/lady_josephine/image_uploader.rb +149 -0
  34. data/app/views/lady_josephine/blocks/_audio_block.haml +2 -0
  35. data/app/views/lady_josephine/blocks/_definition_block.haml +4 -0
  36. data/app/views/lady_josephine/blocks/_divider_block.haml +2 -0
  37. data/app/views/lady_josephine/blocks/_extended_image_block.haml +63 -0
  38. data/app/views/lady_josephine/blocks/_extended_quote_block.haml +5 -0
  39. data/app/views/lady_josephine/blocks/_extended_tweet_block.haml +2 -0
  40. data/app/views/lady_josephine/blocks/_facebook_post_block.haml +2 -0
  41. data/app/views/lady_josephine/blocks/_heading_block.haml +2 -0
  42. data/app/views/lady_josephine/blocks/_html_block.haml +1 -0
  43. data/app/views/lady_josephine/blocks/_instagram_block.haml +2 -0
  44. data/app/views/lady_josephine/blocks/_list_block.haml +3 -0
  45. data/app/views/lady_josephine/blocks/_quote_block.haml +5 -0
  46. data/app/views/lady_josephine/blocks/_text_block.html.haml +2 -0
  47. data/app/views/lady_josephine/blocks/_video_block.haml +9 -0
  48. data/config/routes.rb +9 -0
  49. data/db/migrate/20160222151500_lady_josephine_image.rb +18 -0
  50. data/lib/generators/lady_josephine_migration/USAGE +9 -0
  51. data/lib/generators/lady_josephine_migration/lady_josephine_migration_generator.rb +17 -0
  52. data/lib/generators/lady_josephine_migration/templates/migration.rb +9 -0
  53. data/lib/lady_josephine.rb +18 -0
  54. data/lib/lady_josephine/engine.rb +18 -0
  55. data/lib/lady_josephine/redcarpet/custom_markdown_formatter.rb +63 -0
  56. data/lib/lady_josephine/renderer/sir_trevor_renderer.rb +16 -0
  57. data/lib/lady_josephine/version.rb +3 -0
  58. data/lib/lady_josephine/whitelist.rb +26 -0
  59. data/lib/tasks/lady_josephine_tasks.rake +4 -0
  60. data/spec/controllers/lady_josephine/editor_controller_spec.rb +58 -0
  61. data/spec/dummy/README.rdoc +28 -0
  62. data/spec/dummy/Rakefile +6 -0
  63. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  65. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  66. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  67. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/spec/dummy/bin/bundle +3 -0
  69. data/spec/dummy/bin/rails +4 -0
  70. data/spec/dummy/bin/rake +4 -0
  71. data/spec/dummy/bin/setup +29 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/config/application.rb +26 -0
  74. data/spec/dummy/config/boot.rb +5 -0
  75. data/spec/dummy/config/database.yml +25 -0
  76. data/spec/dummy/config/environment.rb +5 -0
  77. data/spec/dummy/config/environments/development.rb +41 -0
  78. data/spec/dummy/config/environments/production.rb +79 -0
  79. data/spec/dummy/config/environments/test.rb +42 -0
  80. data/spec/dummy/config/initializers/assets.rb +11 -0
  81. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/spec/dummy/config/initializers/inflections.rb +16 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  86. data/spec/dummy/config/initializers/session_store.rb +3 -0
  87. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/spec/dummy/config/locales/en.yml +23 -0
  89. data/spec/dummy/config/routes.rb +4 -0
  90. data/spec/dummy/config/secrets.yml +22 -0
  91. data/spec/dummy/db/development.sqlite3 +0 -0
  92. data/spec/dummy/db/schema.rb +16 -0
  93. data/spec/dummy/db/test.sqlite3 +0 -0
  94. data/spec/dummy/log/bla +0 -0
  95. data/spec/dummy/public/404.html +67 -0
  96. data/spec/dummy/public/422.html +67 -0
  97. data/spec/dummy/public/500.html +66 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/spec_helper.rb +17 -0
  100. data/vendor/assets/components/Eventable/README.md +12 -0
  101. data/vendor/assets/components/Eventable/bower.json +10 -0
  102. data/vendor/assets/components/Eventable/component.json +11 -0
  103. data/vendor/assets/components/Eventable/eventable.js +207 -0
  104. data/vendor/assets/components/Eventable/package.json +15 -0
  105. data/vendor/assets/components/jquery-autosize/bower.json +30 -0
  106. data/vendor/assets/components/jquery-autosize/demo.html +36 -0
  107. data/vendor/assets/components/jquery-autosize/jquery.autosize.js +273 -0
  108. data/vendor/assets/components/jquery-autosize/jquery.autosize.min.js +6 -0
  109. data/vendor/assets/components/jquery-autosize/package.json +32 -0
  110. data/vendor/assets/components/jquery-autosize/readme.md +216 -0
  111. data/vendor/assets/components/jquery/AUTHORS.txt +163 -0
  112. data/vendor/assets/components/jquery/CONTRIBUTING.md +216 -0
  113. data/vendor/assets/components/jquery/Gruntfile.js +496 -0
  114. data/vendor/assets/components/jquery/MIT-LICENSE.txt +21 -0
  115. data/vendor/assets/components/jquery/README.md +415 -0
  116. data/vendor/assets/components/jquery/build/release-notes.js +59 -0
  117. data/vendor/assets/components/jquery/build/release.js +246 -0
  118. data/vendor/assets/components/jquery/component.json +13 -0
  119. data/vendor/assets/components/jquery/composer.json +35 -0
  120. data/vendor/assets/components/jquery/jquery-migrate.js +496 -0
  121. data/vendor/assets/components/jquery/jquery-migrate.min.js +3 -0
  122. data/vendor/assets/components/jquery/jquery.js +9597 -0
  123. data/vendor/assets/components/jquery/jquery.min.js +5 -0
  124. data/vendor/assets/components/jquery/jquery.min.map +1 -0
  125. data/vendor/assets/components/jquery/package.json +39 -0
  126. data/vendor/assets/components/jquery/speed/benchmark.js +15 -0
  127. data/vendor/assets/components/jquery/speed/benchmarker.css +65 -0
  128. data/vendor/assets/components/jquery/speed/benchmarker.js +181 -0
  129. data/vendor/assets/components/jquery/speed/closest.html +39 -0
  130. data/vendor/assets/components/jquery/speed/css.html +82 -0
  131. data/vendor/assets/components/jquery/speed/event.html +58 -0
  132. data/vendor/assets/components/jquery/speed/filter.html +183 -0
  133. data/vendor/assets/components/jquery/speed/find.html +179 -0
  134. data/vendor/assets/components/jquery/speed/index.html +72 -0
  135. data/vendor/assets/components/jquery/speed/jquery-basis.js +6238 -0
  136. data/vendor/assets/components/jquery/speed/slice.vs.concat.html +47 -0
  137. data/vendor/assets/components/jquery/src/ajax.js +851 -0
  138. data/vendor/assets/components/jquery/src/ajax/jsonp.js +80 -0
  139. data/vendor/assets/components/jquery/src/ajax/script.js +86 -0
  140. data/vendor/assets/components/jquery/src/ajax/xhr.js +207 -0
  141. data/vendor/assets/components/jquery/src/attributes.js +661 -0
  142. data/vendor/assets/components/jquery/src/callbacks.js +196 -0
  143. data/vendor/assets/components/jquery/src/core.js +949 -0
  144. data/vendor/assets/components/jquery/src/css.js +679 -0
  145. data/vendor/assets/components/jquery/src/data.js +340 -0
  146. data/vendor/assets/components/jquery/src/deferred.js +141 -0
  147. data/vendor/assets/components/jquery/src/deprecated.js +4 -0
  148. data/vendor/assets/components/jquery/src/dimensions.js +41 -0
  149. data/vendor/assets/components/jquery/src/effects.js +730 -0
  150. data/vendor/assets/components/jquery/src/event-alias.js +15 -0
  151. data/vendor/assets/components/jquery/src/event.js +991 -0
  152. data/vendor/assets/components/jquery/src/exports.js +18 -0
  153. data/vendor/assets/components/jquery/src/intro.js +20 -0
  154. data/vendor/assets/components/jquery/src/manipulation.js +796 -0
  155. data/vendor/assets/components/jquery/src/offset.js +169 -0
  156. data/vendor/assets/components/jquery/src/outro.js +2 -0
  157. data/vendor/assets/components/jquery/src/queue.js +147 -0
  158. data/vendor/assets/components/jquery/src/serialize.js +99 -0
  159. data/vendor/assets/components/jquery/src/sizzle-jquery.js +9 -0
  160. data/vendor/assets/components/jquery/src/support.js +241 -0
  161. data/vendor/assets/components/jquery/src/traversing.js +275 -0
  162. data/vendor/assets/components/jquery/test/csp.php +16 -0
  163. data/vendor/assets/components/jquery/test/data/1x1.jpg +0 -0
  164. data/vendor/assets/components/jquery/test/data/ajax/unreleasedXHR.html +25 -0
  165. data/vendor/assets/components/jquery/test/data/atom+xml.php +4 -0
  166. data/vendor/assets/components/jquery/test/data/badcall.js +1 -0
  167. data/vendor/assets/components/jquery/test/data/badjson.js +1 -0
  168. data/vendor/assets/components/jquery/test/data/cleanScript.html +10 -0
  169. data/vendor/assets/components/jquery/test/data/core/cc_on.html +22 -0
  170. data/vendor/assets/components/jquery/test/data/dashboard.xml +11 -0
  171. data/vendor/assets/components/jquery/test/data/dimensions/documentLarge.html +17 -0
  172. data/vendor/assets/components/jquery/test/data/dimensions/documentSmall.html +21 -0
  173. data/vendor/assets/components/jquery/test/data/echoData.php +1 -0
  174. data/vendor/assets/components/jquery/test/data/echoQuery.php +1 -0
  175. data/vendor/assets/components/jquery/test/data/errorWithText.php +5 -0
  176. data/vendor/assets/components/jquery/test/data/etag.php +21 -0
  177. data/vendor/assets/components/jquery/test/data/evalScript.php +1 -0
  178. data/vendor/assets/components/jquery/test/data/event/longLoadScript.php +4 -0
  179. data/vendor/assets/components/jquery/test/data/event/promiseReady.html +17 -0
  180. data/vendor/assets/components/jquery/test/data/event/syncReady.html +23 -0
  181. data/vendor/assets/components/jquery/test/data/headers.php +18 -0
  182. data/vendor/assets/components/jquery/test/data/if_modified_since.php +20 -0
  183. data/vendor/assets/components/jquery/test/data/iframe.html +8 -0
  184. data/vendor/assets/components/jquery/test/data/jquery-1.8.2.ajax_xhr.min.js +2 -0
  185. data/vendor/assets/components/jquery/test/data/json.php +13 -0
  186. data/vendor/assets/components/jquery/test/data/json_obj.js +1 -0
  187. data/vendor/assets/components/jquery/test/data/jsonp.php +14 -0
  188. data/vendor/assets/components/jquery/test/data/manipulation/iframe-denied.html +36 -0
  189. data/vendor/assets/components/jquery/test/data/name.html +1 -0
  190. data/vendor/assets/components/jquery/test/data/name.php +24 -0
  191. data/vendor/assets/components/jquery/test/data/nocontent.php +5 -0
  192. data/vendor/assets/components/jquery/test/data/offset/absolute.html +41 -0
  193. data/vendor/assets/components/jquery/test/data/offset/body.html +26 -0
  194. data/vendor/assets/components/jquery/test/data/offset/fixed.html +34 -0
  195. data/vendor/assets/components/jquery/test/data/offset/relative.html +31 -0
  196. data/vendor/assets/components/jquery/test/data/offset/scroll.html +39 -0
  197. data/vendor/assets/components/jquery/test/data/offset/static.html +31 -0
  198. data/vendor/assets/components/jquery/test/data/offset/table.html +43 -0
  199. data/vendor/assets/components/jquery/test/data/params_html.php +12 -0
  200. data/vendor/assets/components/jquery/test/data/readywaitasset.js +1 -0
  201. data/vendor/assets/components/jquery/test/data/readywaitloader.js +25 -0
  202. data/vendor/assets/components/jquery/test/data/script.php +11 -0
  203. data/vendor/assets/components/jquery/test/data/selector/html5_selector.html +114 -0
  204. data/vendor/assets/components/jquery/test/data/selector/sizzle_cache.html +21 -0
  205. data/vendor/assets/components/jquery/test/data/statusText.php +5 -0
  206. data/vendor/assets/components/jquery/test/data/support/bodyBackground.html +28 -0
  207. data/vendor/assets/components/jquery/test/data/support/shrinkWrapBlocks.html +23 -0
  208. data/vendor/assets/components/jquery/test/data/support/testElementCrash.html +17 -0
  209. data/vendor/assets/components/jquery/test/data/test.html +7 -0
  210. data/vendor/assets/components/jquery/test/data/test.js +3 -0
  211. data/vendor/assets/components/jquery/test/data/test.php +7 -0
  212. data/vendor/assets/components/jquery/test/data/test2.html +5 -0
  213. data/vendor/assets/components/jquery/test/data/test3.html +3 -0
  214. data/vendor/assets/components/jquery/test/data/testinit.js +269 -0
  215. data/vendor/assets/components/jquery/test/data/testrunner.js +368 -0
  216. data/vendor/assets/components/jquery/test/data/testsuite.css +155 -0
  217. data/vendor/assets/components/jquery/test/data/text.php +12 -0
  218. data/vendor/assets/components/jquery/test/data/ua.txt +272 -0
  219. data/vendor/assets/components/jquery/test/data/with_fries.xml +25 -0
  220. data/vendor/assets/components/jquery/test/data/with_fries_over_jsonp.php +7 -0
  221. data/vendor/assets/components/jquery/test/delegatetest.html +228 -0
  222. data/vendor/assets/components/jquery/test/hovertest.html +158 -0
  223. data/vendor/assets/components/jquery/test/index.html +330 -0
  224. data/vendor/assets/components/jquery/test/localfile.html +75 -0
  225. data/vendor/assets/components/jquery/test/networkerror.html +84 -0
  226. data/vendor/assets/components/jquery/test/polluted.php +110 -0
  227. data/vendor/assets/components/jquery/test/readywait.html +70 -0
  228. data/vendor/assets/components/jquery/test/unit/ajax.js +1971 -0
  229. data/vendor/assets/components/jquery/test/unit/attributes.js +1332 -0
  230. data/vendor/assets/components/jquery/test/unit/callbacks.js +326 -0
  231. data/vendor/assets/components/jquery/test/unit/core.js +1332 -0
  232. data/vendor/assets/components/jquery/test/unit/css.js +1036 -0
  233. data/vendor/assets/components/jquery/test/unit/data.js +636 -0
  234. data/vendor/assets/components/jquery/test/unit/deferred.js +440 -0
  235. data/vendor/assets/components/jquery/test/unit/deprecated.js +1 -0
  236. data/vendor/assets/components/jquery/test/unit/dimensions.js +461 -0
  237. data/vendor/assets/components/jquery/test/unit/effects.js +2050 -0
  238. data/vendor/assets/components/jquery/test/unit/event.js +2690 -0
  239. data/vendor/assets/components/jquery/test/unit/exports.js +7 -0
  240. data/vendor/assets/components/jquery/test/unit/manipulation.js +2242 -0
  241. data/vendor/assets/components/jquery/test/unit/offset.js +549 -0
  242. data/vendor/assets/components/jquery/test/unit/queue.js +316 -0
  243. data/vendor/assets/components/jquery/test/unit/selector.js +185 -0
  244. data/vendor/assets/components/jquery/test/unit/serialize.js +146 -0
  245. data/vendor/assets/components/jquery/test/unit/support.js +384 -0
  246. data/vendor/assets/components/jquery/test/unit/traversing.js +667 -0
  247. data/vendor/assets/components/jquery/test/xhtml.php +5 -0
  248. data/vendor/assets/components/sir-trevor-js/CHANGELOG.md +44 -0
  249. data/vendor/assets/components/sir-trevor-js/Gemfile +3 -0
  250. data/vendor/assets/components/sir-trevor-js/Gemfile.lock +10 -0
  251. data/vendor/assets/components/sir-trevor-js/Gruntfile.js +109 -0
  252. data/vendor/assets/components/sir-trevor-js/MIT-LICENCE +20 -0
  253. data/vendor/assets/components/sir-trevor-js/Readme.md +84 -0
  254. data/vendor/assets/components/sir-trevor-js/bower.json +21 -0
  255. data/vendor/assets/components/sir-trevor-js/component.json +42 -0
  256. data/vendor/assets/components/sir-trevor-js/contributing.md +74 -0
  257. data/vendor/assets/components/sir-trevor-js/examples-component/component.json +14 -0
  258. data/vendor/assets/components/sir-trevor-js/examples-component/index.html +33 -0
  259. data/vendor/assets/components/sir-trevor-js/examples-component/index.js +29 -0
  260. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/example_block.js +203 -0
  261. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/limit_chars.js +46 -0
  262. data/vendor/assets/components/sir-trevor-js/examples-component/sir-trevor.gif +0 -0
  263. data/vendor/assets/components/sir-trevor-js/locales/cn.js +51 -0
  264. data/vendor/assets/components/sir-trevor-js/locales/de.js +51 -0
  265. data/vendor/assets/components/sir-trevor-js/locales/es.js +51 -0
  266. data/vendor/assets/components/sir-trevor-js/locales/fi.js +51 -0
  267. data/vendor/assets/components/sir-trevor-js/locales/fr.js +51 -0
  268. data/vendor/assets/components/sir-trevor-js/locales/pt.js +52 -0
  269. data/vendor/assets/components/sir-trevor-js/package.json +23 -0
  270. data/vendor/assets/components/sir-trevor-js/sir-trevor-icons.css +6 -0
  271. data/vendor/assets/components/sir-trevor-js/sir-trevor.css +393 -0
  272. data/vendor/assets/components/sir-trevor-js/sir-trevor.css.map +7 -0
  273. data/vendor/assets/components/sir-trevor-js/sir-trevor.js +5481 -0
  274. data/vendor/assets/components/sir-trevor-js/sir-trevor.min.js +13 -0
  275. data/vendor/assets/components/underscore/CNAME +1 -0
  276. data/vendor/assets/components/underscore/CONTRIBUTING.md +9 -0
  277. data/vendor/assets/components/underscore/LICENSE +22 -0
  278. data/vendor/assets/components/underscore/README.md +19 -0
  279. data/vendor/assets/components/underscore/Rakefile +10 -0
  280. data/vendor/assets/components/underscore/docs/docco.css +192 -0
  281. data/vendor/assets/components/underscore/docs/favicon.ico +0 -0
  282. data/vendor/assets/components/underscore/docs/images/background.png +0 -0
  283. data/vendor/assets/components/underscore/docs/images/underscore.png +0 -0
  284. data/vendor/assets/components/underscore/docs/underscore.html +823 -0
  285. data/vendor/assets/components/underscore/favicon.ico +0 -0
  286. data/vendor/assets/components/underscore/index.html +2467 -0
  287. data/vendor/assets/components/underscore/index.js +1 -0
  288. data/vendor/assets/components/underscore/package.json +16 -0
  289. data/vendor/assets/components/underscore/test/arrays.js +200 -0
  290. data/vendor/assets/components/underscore/test/chaining.js +59 -0
  291. data/vendor/assets/components/underscore/test/collections.js +453 -0
  292. data/vendor/assets/components/underscore/test/functions.js +265 -0
  293. data/vendor/assets/components/underscore/test/index.html +44 -0
  294. data/vendor/assets/components/underscore/test/objects.js +570 -0
  295. data/vendor/assets/components/underscore/test/speed.js +75 -0
  296. data/vendor/assets/components/underscore/test/utility.js +266 -0
  297. data/vendor/assets/components/underscore/test/vendor/jquery.js +9404 -0
  298. data/vendor/assets/components/underscore/test/vendor/jslitmus.js +670 -0
  299. data/vendor/assets/components/underscore/test/vendor/qunit.css +235 -0
  300. data/vendor/assets/components/underscore/test/vendor/qunit.js +1977 -0
  301. data/vendor/assets/components/underscore/test/vendor/runner.js +98 -0
  302. data/vendor/assets/components/underscore/underscore-min.js +1 -0
  303. data/vendor/assets/components/underscore/underscore.js +1226 -0
  304. metadata +473 -0
@@ -0,0 +1,75 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>jQuery Local File Test</title>
6
+ <!-- Includes -->
7
+ <script src="../dist/jquery.min.js"></script>
8
+ <style>
9
+ .error { color: red; }
10
+ .success { color: green; }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <h1>jQuery Local File Test</h1>
15
+ <h2>
16
+ Introduction
17
+ </h2>
18
+ <ul>
19
+ <li>
20
+ Access this file using the "file:" protocol,
21
+ </li>
22
+ <li>
23
+ two green "OK" strings must appear below,
24
+ </li>
25
+ <li>
26
+ Empty local files will issue errors, it's a known limitation.
27
+ </li>
28
+ </ul>
29
+ <h2>
30
+ Results
31
+ </h2>
32
+ <ul>
33
+ <li>
34
+ Success:
35
+ <span id="success">
36
+ </span>
37
+ </li>
38
+ <li>
39
+ Error:
40
+ <span id="error">
41
+ </span>
42
+ </li>
43
+ </ul>
44
+ <h2>
45
+ Logs:
46
+ </h2>
47
+ <ul id="log">
48
+ </ul>
49
+ <script>
50
+ var logUL = jQuery( "#log" );
51
+ function doLog( message, args ) {
52
+ jQuery( "<li />").appendTo( logUL ).text( message + ': "' + Array.prototype.join.call( args, '" - "' ) + '"' );
53
+ }
54
+ jQuery.ajax( "./data/badjson.js" , {
55
+ context: jQuery( "#success" ),
56
+ dataType: "text"
57
+ }).success(function( data, _, xhr ) {
58
+ doLog( "Success (" + xhr.status + ")" , arguments );
59
+ this.addClass( data ? "success" : "error" ).text( "OK" );
60
+ }).error(function( xhr ) {
61
+ doLog( "Success (" + xhr.status + ")" , arguments );
62
+ this.addClass( "error" ).text( "FAIL" );
63
+ });
64
+ jQuery.ajax( "./data/doesnotexist.ext" , {
65
+ context: jQuery( "#error" ),
66
+ dataType: "text"
67
+ }).error(function( xhr ) {
68
+ doLog( "Error (" + xhr.status + ")" , arguments );
69
+ this.addClass( "success" ).text( "OK" );
70
+ }).success(function( data, _, xhr ) {
71
+ doLog( "Error (" + xhr.status + ")" , arguments );
72
+ this.addClass( "error" ).text( "FAIL" );
73
+ });
74
+ </script>
75
+ </body>
@@ -0,0 +1,84 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!--
4
+ Test for #8135
5
+
6
+ Thanks John Firebaugh for this test page based on his gist
7
+ https://gist.github.com/807090
8
+
9
+ Access this page through a web server, then stop said server and click the button.
10
+ -->
11
+ <head>
12
+ <title>
13
+ jQuery Network Error Test for Firefox
14
+ </title>
15
+ <style>
16
+ div { margin-top: 10px; }
17
+ </style>
18
+ <script src="../dist/jquery.min.js"></script>
19
+ <script type="text/javascript">
20
+ $('button').live('click', function () {
21
+ $.ajax({
22
+ url: '/',
23
+ error: function() {
24
+ console.log( "abort", arguments );
25
+ }
26
+ }).abort();
27
+ $.ajax({
28
+ url: '/',
29
+ error: function() {
30
+ console.log( "complete", arguments );
31
+ }
32
+ });
33
+ return false;
34
+ })
35
+ </script>
36
+ </head>
37
+ <body>
38
+ <h1>
39
+ jQuery Network Error Test for Firefox
40
+ </h1>
41
+ <div>
42
+ This is a test page for
43
+ <a href="http://bugs.jquery.com/ticket/8135">
44
+ #8135
45
+ </a>
46
+ which was reported in Firefox when accessing properties
47
+ of an XMLHttpRequest object after a network error occured.
48
+ </div>
49
+ <div>Take the following steps:</div>
50
+ <ol>
51
+ <li>
52
+ make sure you accessed this page through a web server,
53
+ </li>
54
+ <li>
55
+ stop the web server,
56
+ </li>
57
+ <li>
58
+ open the console,
59
+ </li>
60
+ <li>
61
+ click this
62
+ <button>button</button>
63
+ ,
64
+ </li>
65
+ <li>
66
+ wait for both requests to fail.
67
+ </li>
68
+ </ol>
69
+ <div>
70
+ Test passes if you get two log lines:
71
+ <ul>
72
+ <li>
73
+ the first starting with "abort",
74
+ </li>
75
+ <li>
76
+ the second starting with "complete",
77
+ </li>
78
+ </ul>
79
+ </div>
80
+ <div>
81
+ Test fails if the browser notifies an exception.
82
+ </div>
83
+ </body>
84
+ </html>
@@ -0,0 +1,110 @@
1
+ <?php
2
+ $baseURL = "http://ajax.googleapis.com/ajax/libs/";
3
+ $libraries = array(
4
+ "Dojo" => array(
5
+ "versions" => array( "1.1.1", "1.2.0", "1.2.3", "1.3.0", "1.3.1", "1.3.2", "1.4.0", "1.4.1", "1.4.3", "1.5.0" ),
6
+ "url" => "dojo/XYZ/dojo/dojo.xd.js"
7
+ ),
8
+ "ExtCore" => array(
9
+ "versions" => array( "3.0.0", "3.1.0" ),
10
+ "url" => "ext-core/XYZ/ext-core.js"
11
+ ),
12
+ "jQuery" => array(
13
+ "versions" => array( "1.2.3", "1.2.6", "1.3.0", "1.3.1", "1.3.2", "1.4.0", "1.4.1", "1.4.2", "1.4.3", "1.4.4", "1.5.0" ),
14
+ "url" => "jquery/XYZ/jquery.min.js"
15
+ ),
16
+ "jQueryUI" => array(
17
+ "versions" => array( "1.5.2", "1.5.3", "1.6.0", "1.7.0", "1.7.1", "1.7.2", "1.7.3", "1.8.0", "1.8.1", "1.8.2", "1.8.4", "1.8.5", "1.8.6", "1.8.7", "1.8.8", "1.8.9" ),
18
+ "url" => "jqueryui/XYZ/jquery-ui.min.js"
19
+ ),
20
+ "MooTools" => array(
21
+ "versions" => array( "1.1.1", "1.1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.2.5", "1.3.0" ),
22
+ "url" => "mootools/XYZ/mootools-yui-compressed.js"
23
+ ),
24
+ "Prototype" => array(
25
+ "versions" => array( "1.6.0.2", "1.6.0.3", "1.6.1.0", "1.7.0.0" ),
26
+ "url" => "prototype/XYZ/prototype.js"
27
+ ),
28
+ "scriptaculous" => array(
29
+ "versions" => array( "1.8.1", "1.8.2", "1.8.3" ),
30
+ "url" => "scriptaculous/XYZ/scriptaculous.js"
31
+ ),
32
+ "SWFObject" => array(
33
+ "versions" => array( "2.1", "2.2" ),
34
+ "url" => "swfobject/XYZ/swfobject.js"
35
+ ),
36
+ "YUI" => array(
37
+ "versions" => array( "2.6.0", "2.7.0", "2.8.0r4", "2.8.1", "2.8.2", "3.3.0" ),
38
+ "url" => "yui/XYZ/build/yui/yui-min.js"
39
+ )
40
+ );
41
+
42
+ if( count($_POST) ) {
43
+ $includes = array();
44
+ foreach( $_POST as $name => $ver ){
45
+ if ( empty( $libraries[ $name ] )) {
46
+ echo "unsupported library ". $name;
47
+ exit;
48
+ }
49
+
50
+ $url = $libraries[ $name ][ "url" ];
51
+ if( $name == "YUI" && $ver[0] == "2" ) {
52
+ $url = str_replace( "/yui", "/yuiloader", $url);
53
+ }
54
+
55
+ if ( empty( $libraries[ $name ][ "versions" ][ $ver ] )) {
56
+ echo "library ". $name ." not supported in version ". $ver;
57
+ exit;
58
+ }
59
+
60
+ $include = "<script src='$baseURL".str_replace("XYZ", $ver, $url)."'></script>\n";
61
+ if( $lib == "prototype" ) { // prototype must be included first
62
+ array_unshift( $includes, $include );
63
+ } else {
64
+ array_push( $includes, $include );
65
+ }
66
+ }
67
+
68
+ $includes = implode( "\n", $includes );
69
+ $suite = file_get_contents( "index.html" );
70
+ echo str_replace( "<!-- Includes -->", $includes, $suite );
71
+ exit;
72
+ }
73
+ ?>
74
+ <!DOCTYPE html>
75
+ <html>
76
+ <head>
77
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
78
+ <title>Run jQuery Test Suite Polluted</title>
79
+ <style type="text/css">
80
+ .otherlibs fieldset {
81
+ width: 400px
82
+ }
83
+ .otherlibs label{
84
+ margin: 5px 0px 5px 20px;
85
+ }
86
+ </style>
87
+ </head>
88
+
89
+ <body id="body">
90
+ <h1 id="header">jQuery Test Suite</h1>
91
+ <h2 id="banner" class="fail"></h2>
92
+ <h2 id="userAgent">Choose other libraries to include</h2>
93
+
94
+ <form class="otherlibs" action="./polluted.php" method="POST">
95
+ <?php
96
+ foreach( $libraries as $name => $data ) {
97
+ echo "<fieldset><legend>$name</legend>";
98
+ $i = 0;
99
+ foreach( $data[ "versions" ] as $ver ) {
100
+ $i++;
101
+ echo "<label><input type='radio' name='$name' value='$ver' />$ver</label>";
102
+ if( !($i % 4) ) echo "<br />";
103
+ }
104
+ echo "</fieldset>";
105
+ }
106
+ ?>
107
+ <input type="submit" value=" Run " class="submit" />
108
+ </form>
109
+ </body>
110
+ </html>
@@ -0,0 +1,70 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!--
4
+ Test for jQuery.holdReady. Needs to be a
5
+ standalone test since it deals with DOM
6
+ ready.
7
+ -->
8
+ <head>
9
+ <title>
10
+ jQuery.holdReady Test
11
+ </title>
12
+ <style>
13
+ div { margin-top: 10px; }
14
+ #output { background-color: green }
15
+ #expectedOutput { background-color: green }
16
+ </style>
17
+ <script src="../dist/jquery.min.js"></script>
18
+
19
+ <!-- Load the script loader that uses
20
+ jQuery.readyWait -->
21
+ <script src="data/readywaitloader.js"></script>
22
+
23
+ <script type="text/javascript">
24
+ jQuery(function() {
25
+ // The delayedMessage is defined by
26
+ // the readywaitasset.js file, so the
27
+ // next line will only work if this DOM
28
+ // ready callback is called after readyWait
29
+ // has been decremented by readywaitloader.js
30
+ // If an error occurs.
31
+ jQuery("#output").append(delayedMessage);
32
+ });
33
+ </script>
34
+ </head>
35
+ <body>
36
+ <h1>
37
+ jQuery.holdReady Test
38
+ </h1>
39
+ <p>
40
+ This is a test page for jQuery.readyWait and jQuery.holdReady,
41
+ see
42
+ <a href="http://bugs.jquery.com/ticket/6781">#6781</a>
43
+ and
44
+ <a href="http://bugs.jquery.com/ticket/8803">#8803</a>.
45
+ </p>
46
+ <p>
47
+ Test for jQuery.holdReady, which can be used
48
+ by plugins and other scripts to indicate something
49
+ important to the page is still loading and needs
50
+ to block the DOM ready callbacks that are registered
51
+ with jQuery.
52
+ </p>
53
+ <p>
54
+ Script loaders are the most likely kind of script
55
+ to use jQuery.holdReady, but it could be used by
56
+ other things like a script that loads a CSS file
57
+ and wants to pause the DOM ready callbacks.
58
+ </p>
59
+ <p>
60
+ <strong>Expected Result</strong>: The text
61
+ <span id="expectedOutput">It Worked!</span>
62
+ appears below after about <strong>2 seconds.</strong>
63
+ </p>
64
+ <p>
65
+ If there is an error in the console,
66
+ or the text does not show up, then the test failed.
67
+ </p>
68
+ <div id="output"></div>
69
+ </body>
70
+ </html>
@@ -0,0 +1,1971 @@
1
+ module( "ajax", {
2
+ setup: function() {
3
+ var jsonpCallback = this.jsonpCallback = jQuery.ajaxSettings.jsonpCallback;
4
+ jQuery.ajaxSettings.jsonpCallback = function() {
5
+ var callback = jsonpCallback.apply( this, arguments );
6
+ Globals.register( callback );
7
+ return callback;
8
+ };
9
+ },
10
+ teardown: function() {
11
+ jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
12
+ moduleTeardown.apply( this, arguments );
13
+ }
14
+ });
15
+
16
+ (function() {
17
+
18
+ if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
19
+ return;
20
+ }
21
+
22
+ function addGlobalEvents( expected ) {
23
+ return function() {
24
+ expected = expected || "";
25
+ jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
26
+ ok( expected.indexOf(e.type) !== -1, e.type );
27
+ });
28
+ };
29
+ }
30
+
31
+ //----------- jQuery.ajax()
32
+
33
+ ajaxTest( "jQuery.ajax() - success callbacks", 8, {
34
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
35
+ url: url("data/name.html"),
36
+ beforeSend: function() {
37
+ ok( true, "beforeSend" );
38
+ },
39
+ success: function() {
40
+ ok( true, "success" );
41
+ },
42
+ complete: function() {
43
+ ok( true, "complete");
44
+ }
45
+ });
46
+
47
+ ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, {
48
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
49
+ create: function( options ) {
50
+ return jQuery.ajax( url("data/name.html"), options );
51
+ },
52
+ beforeSend: function() {
53
+ ok( true, "beforeSend" );
54
+ },
55
+ success: function() {
56
+ ok( true, "success" );
57
+ },
58
+ complete: function() {
59
+ ok( true, "complete" );
60
+ }
61
+ });
62
+
63
+ ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, {
64
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
65
+ url: url("data/name.html"),
66
+ beforeSend: function() {
67
+ ok( true, "beforeSend" );
68
+ },
69
+ success: true,
70
+ afterSend: function( request ) {
71
+ request.complete(function() {
72
+ ok( true, "complete" );
73
+ }).success(function() {
74
+ ok( true, "success" );
75
+ }).error(function() {
76
+ ok( false, "error" );
77
+ });
78
+ }
79
+ });
80
+
81
+ ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, {
82
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
83
+ url: url("data/name.html"),
84
+ beforeSend: function() {
85
+ ok( true, "beforeSend" );
86
+ },
87
+ success: true,
88
+ complete: function( xhr ) {
89
+ xhr.complete(function() {
90
+ ok( true, "complete" );
91
+ }).success(function() {
92
+ ok( true, "success" );
93
+ }).error(function() {
94
+ ok( false, "error" );
95
+ });
96
+ }
97
+ });
98
+
99
+ ajaxTest( "jQuery.ajax() - error callbacks", 8, {
100
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"),
101
+ url: url("data/name.php?wait=5"),
102
+ beforeSend: function() {
103
+ ok( true, "beforeSend" );
104
+ },
105
+ afterSend: function( request ) {
106
+ request.abort();
107
+ },
108
+ error: function() {
109
+ ok( true, "error" );
110
+ },
111
+ complete: function() {
112
+ ok( true, "complete" );
113
+ }
114
+ });
115
+
116
+ ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [
117
+ {
118
+ url: url("data/name.php?wait=5"),
119
+ error: function( _, textStatus, errorThrown ) {
120
+ strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
121
+ strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
122
+ },
123
+ afterSend: function( request ) {
124
+ request.abort();
125
+ }
126
+ },
127
+ {
128
+ url: url("data/name.php?wait=5"),
129
+ error: function( _, textStatus, errorThrown ) {
130
+ strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
131
+ strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
132
+ },
133
+ afterSend: function( request ) {
134
+ request.abort("mystatus");
135
+ }
136
+ }
137
+ ]);
138
+
139
+ ajaxTest( "jQuery.ajax() - responseText on error", 1, {
140
+ url: url("data/errorWithText.php"),
141
+ error: function( xhr ) {
142
+ strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
143
+ }
144
+ });
145
+
146
+ asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() {
147
+ var previousUrl,
148
+ firstTime = true;
149
+ jQuery.ajax({
150
+ url: url("data/errorWithText.php"),
151
+ error: function() {
152
+ if ( firstTime ) {
153
+ firstTime = false;
154
+ jQuery.ajax( this );
155
+ } else {
156
+ ok ( true, "Test retrying with jQuery.ajax(this) works" );
157
+ jQuery.ajax({
158
+ url: url("data/errorWithText.php"),
159
+ data: {
160
+ "x": 1
161
+ },
162
+ beforeSend: function() {
163
+ if ( !previousUrl ) {
164
+ previousUrl = this.url;
165
+ } else {
166
+ strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
167
+ start();
168
+ return false;
169
+ }
170
+ },
171
+ error: function() {
172
+ jQuery.ajax( this );
173
+ }
174
+ });
175
+ }
176
+ }
177
+ });
178
+ });
179
+
180
+ ajaxTest( "jQuery.ajax() - headers", 4, {
181
+ setup: function() {
182
+ jQuery( document ).ajaxSend(function( evt, xhr ) {
183
+ xhr.setRequestHeader( "ajax-send", "test" );
184
+ });
185
+ },
186
+ url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_ajax-send"),
187
+ headers: {
188
+ "siMPle": "value",
189
+ "SometHing-elsE": "other value",
190
+ "OthEr": "something else"
191
+ },
192
+ success: function( data, _, xhr ) {
193
+ var i, emptyHeader,
194
+ requestHeaders = jQuery.extend( this.headers, {
195
+ "ajax-send": "test"
196
+ }),
197
+ tmp = [];
198
+ for ( i in requestHeaders ) {
199
+ tmp.push( i, ": ", requestHeaders[ i ], "\n" );
200
+ }
201
+ tmp = tmp.join("");
202
+
203
+ strictEqual( data, tmp, "Headers were sent" );
204
+ strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" );
205
+
206
+ emptyHeader = xhr.getResponseHeader("Empty-Header");
207
+ if ( emptyHeader === null ) {
208
+ ok( true, "Firefox doesn't support empty headers" );
209
+ } else {
210
+ strictEqual( emptyHeader, "", "Empty header received" );
211
+ }
212
+ strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" );
213
+ }
214
+ });
215
+
216
+ ajaxTest( "jQuery.ajax() - Accept header", 1, {
217
+ url: url("data/headers.php?keys=accept"),
218
+ headers: {
219
+ Accept: "very wrong accept value"
220
+ },
221
+ beforeSend: function( xhr ) {
222
+ xhr.setRequestHeader("Accept", "*/*");
223
+ },
224
+ success: function( data ) {
225
+ strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
226
+ }
227
+ });
228
+
229
+ ajaxTest( "jQuery.ajax() - contentType", 2, [
230
+ {
231
+ url: url("data/headers.php?keys=content-type"),
232
+ contentType: "test",
233
+ success: function( data ) {
234
+ strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
235
+ }
236
+ },
237
+ {
238
+ url: url("data/headers.php?keys=content-type"),
239
+ contentType: false,
240
+ success: function( data ) {
241
+ strictEqual( data, "content-type: \n", "Test content-type is not sent when options.contentType===false" );
242
+ }
243
+ }
244
+ ]);
245
+
246
+ ajaxTest( "jQuery.ajax() - protocol-less urls", 1, {
247
+ url: "//somedomain.com",
248
+ beforeSend: function( xhr, settings ) {
249
+ equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." );
250
+ return false;
251
+ },
252
+ error: true
253
+ });
254
+
255
+ ajaxTest( "jQuery.ajax() - hash", 3, [
256
+ {
257
+ url: "data/name.html#foo",
258
+ beforeSend: function( xhr, settings ) {
259
+ equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." );
260
+ return false;
261
+ },
262
+ error: true
263
+ },
264
+ {
265
+ url: "data/name.html?abc#foo",
266
+ beforeSend: function( xhr, settings ) {
267
+ equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." );
268
+ return false;
269
+ },
270
+ error: true
271
+ },
272
+ {
273
+ url: "data/name.html?abc#foo",
274
+ data: {
275
+ "test": 123
276
+ },
277
+ beforeSend: function( xhr, settings ) {
278
+ equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." );
279
+ return false;
280
+ },
281
+ error: true
282
+ }
283
+ ]);
284
+
285
+ ajaxTest( "jQuery.ajax() - cross-domain detection", 7, function() {
286
+ function request( url, title, crossDomainOrOptions ) {
287
+ return jQuery.extend( {
288
+ dataType: "jsonp",
289
+ url: url,
290
+ beforeSend: function( _, s ) {
291
+ ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title );
292
+ return false;
293
+ },
294
+ error: true
295
+ }, crossDomainOrOptions );
296
+ }
297
+
298
+ var loc = document.location,
299
+ samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
300
+ otherPort = loc.port === 666 ? 667 : 666,
301
+ otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
302
+
303
+ return [
304
+ request(
305
+ loc.protocol + "//" + loc.host + ":" + samePort,
306
+ "Test matching ports are not detected as cross-domain",
307
+ false
308
+ ),
309
+ request(
310
+ otherProtocol + "//" + loc.host,
311
+ "Test different protocols are detected as cross-domain"
312
+ ),
313
+ request(
314
+ "app:/path",
315
+ "Adobe AIR app:/ URL detected as cross-domain"
316
+ ),
317
+ request(
318
+ loc.protocol + "//example.invalid:" + ( loc.port || 80 ),
319
+ "Test different hostnames are detected as cross-domain"
320
+ ),
321
+ request(
322
+ loc.protocol + "//" + loc.hostname + ":" + otherPort,
323
+ "Test different ports are detected as cross-domain"
324
+ ),
325
+ request(
326
+ "about:blank",
327
+ "Test about:blank is detected as cross-domain"
328
+ ),
329
+ request(
330
+ loc.protocol + "//" + loc.host,
331
+ "Test forced crossDomain is detected as cross-domain",
332
+ {
333
+ crossDomain: true
334
+ }
335
+ )
336
+ ];
337
+ });
338
+
339
+ ajaxTest( "jQuery.ajax() - abort", 9, {
340
+ setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"),
341
+ url: url("data/name.php?wait=5"),
342
+ beforeSend: function() {
343
+ ok( true, "beforeSend" );
344
+ },
345
+ afterSend: function( xhr ) {
346
+ strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
347
+ xhr.abort();
348
+ strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
349
+ },
350
+ error: true,
351
+ complete: function() {
352
+ ok( true, "complete" );
353
+ }
354
+ });
355
+
356
+ ajaxTest( "jQuery.ajax() - events with context", 12, function() {
357
+
358
+ var context = document.createElement("div");
359
+
360
+ function event( e ) {
361
+ equal( this, context, e.type );
362
+ }
363
+
364
+ function callback( msg ) {
365
+ return function() {
366
+ equal( this, context, "context is preserved on callback " + msg );
367
+ };
368
+ }
369
+
370
+ return {
371
+ setup: function() {
372
+ jQuery( context ).appendTo("#foo")
373
+ .ajaxSend( event )
374
+ .ajaxComplete( event )
375
+ .ajaxError( event )
376
+ .ajaxSuccess( event );
377
+ },
378
+ requests: [{
379
+ url: url("data/name.html"),
380
+ context: context,
381
+ beforeSend: callback("beforeSend"),
382
+ success: callback("success"),
383
+ complete: callback("complete")
384
+ }, {
385
+ url: url("data/404.html"),
386
+ context: context,
387
+ beforeSend: callback("beforeSend"),
388
+ error: callback("error"),
389
+ complete: callback("complete")
390
+ }]
391
+ };
392
+ });
393
+
394
+ ajaxTest( "jQuery.ajax() - events without context", 3, function() {
395
+ function nocallback( msg ) {
396
+ return function() {
397
+ equal( typeof this.url, "string", "context is settings on callback " + msg );
398
+ };
399
+ }
400
+ return {
401
+ url: url("data/404.html"),
402
+ beforeSend: nocallback("beforeSend"),
403
+ error: nocallback("error"),
404
+ complete: nocallback("complete")
405
+ };
406
+ });
407
+
408
+ ajaxTest( "jQuery.ajax() - context modification", 1, {
409
+ url: url("data/name.html"),
410
+ context: {},
411
+ beforeSend: function() {
412
+ this.test = "foo";
413
+ },
414
+ afterSend: function() {
415
+ strictEqual( this.context.test, "foo", "Make sure the original object is maintained." );
416
+ },
417
+ success: true
418
+ });
419
+
420
+ ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() {
421
+ var obj = {};
422
+ return {
423
+ setup: function() {
424
+ jQuery.ajaxSetup({
425
+ context: obj
426
+ });
427
+ strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
428
+ },
429
+ requests: [{
430
+ url: url("data/name.html"),
431
+ success: function() {
432
+ strictEqual( this, obj, "Make sure the original object is maintained." );
433
+ }
434
+ }, {
435
+ url: url("data/name.html"),
436
+ context: {},
437
+ success: function() {
438
+ ok( this !== obj, "Make sure overidding context is possible." );
439
+ }
440
+ }]
441
+ };
442
+ });
443
+
444
+ ajaxTest( "jQuery.ajax() - disabled globals", 3, {
445
+ setup: addGlobalEvents(""),
446
+ global: false,
447
+ url: url("data/name.html"),
448
+ beforeSend: function() {
449
+ ok( true, "beforeSend" );
450
+ },
451
+ success: function() {
452
+ ok( true, "success" );
453
+ },
454
+ complete: function() {
455
+ ok( true, "complete" );
456
+ }
457
+ });
458
+
459
+ ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, {
460
+ url: url("data/with_fries.xml"),
461
+ dataType: "xml",
462
+ success: function( resp ) {
463
+ equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
464
+ equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
465
+ equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
466
+ }
467
+ });
468
+
469
+ ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, {
470
+ url: url("data/with_fries_over_jsonp.php"),
471
+ dataType: "jsonp xml",
472
+ success: function( resp ) {
473
+ equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
474
+ equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
475
+ equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
476
+ }
477
+ });
478
+
479
+ ajaxTest( "jQuery.ajax() - HEAD requests", 2, [
480
+ {
481
+ url: url("data/name.html"),
482
+ type: "HEAD",
483
+ success: function( data, status, xhr ) {
484
+ ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
485
+ }
486
+ },
487
+ {
488
+ url: url("data/name.html"),
489
+ data: {
490
+ "whip_it": "good"
491
+ },
492
+ type: "HEAD",
493
+ success: function( data, status, xhr ) {
494
+ ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" );
495
+ }
496
+ }
497
+ ]);
498
+
499
+ ajaxTest( "jQuery.ajax() - beforeSend", 1, {
500
+ url: url("data/name.html"),
501
+ beforeSend: function( xml ) {
502
+ this.check = true;
503
+ },
504
+ success: function( data ) {
505
+ ok( this.check, "check beforeSend was executed" );
506
+ }
507
+ });
508
+
509
+ ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, {
510
+ create: function() {
511
+ return jQuery.ajax({
512
+ url: url("data/name.html"),
513
+ beforeSend: function( xhr ) {
514
+ ok( true, "beforeSend got called, canceling" );
515
+ xhr.abort();
516
+ },
517
+ success: function() {
518
+ ok( false, "request didn't get canceled" );
519
+ },
520
+ complete: function() {
521
+ ok( false, "request didn't get canceled" );
522
+ },
523
+ error: function() {
524
+ ok( false, "request didn't get canceled" );
525
+ }
526
+ });
527
+ },
528
+ fail: function( _, reason ) {
529
+ strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
530
+ }
531
+ });
532
+
533
+ ajaxTest( "jQuery.ajax() - dataType html", 5, {
534
+ setup: function() {
535
+ Globals.register("testFoo");
536
+ Globals.register("testBar");
537
+ },
538
+ dataType: "html",
539
+ url: url("data/test.html"),
540
+ success: function( data ) {
541
+ ok( data.match( /^html text/ ), "Check content for datatype html" );
542
+ jQuery("#ap").html( data );
543
+ strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" );
544
+ strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" );
545
+ }
546
+ });
547
+
548
+ ajaxTest( "jQuery.ajax() - synchronous request", 1, {
549
+ url: url("data/json_obj.js"),
550
+ dataType: "text",
551
+ async: false,
552
+ success: true,
553
+ afterSend: function( xhr ) {
554
+ ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
555
+ }
556
+ });
557
+
558
+ ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, {
559
+ url: url("data/json_obj.js"),
560
+ async: false,
561
+ dataType: "text",
562
+ success: true,
563
+ afterSend: function( xhr ) {
564
+ var result;
565
+ xhr.done(function( data ) {
566
+ ok( true, "success callback executed" );
567
+ result = data;
568
+ });
569
+ ok( /^\{ "data"/.test( result ), "check returned text" );
570
+ }
571
+ });
572
+
573
+ asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() {
574
+ var target = "data/name.html";
575
+ var successCount = 0;
576
+ var errorCount = 0;
577
+ var errorEx = "";
578
+ var success = function() {
579
+ successCount++;
580
+ };
581
+ jQuery( document ).on( "ajaxError.passthru", function( e, xml, s, ex ) {
582
+ errorCount++;
583
+ errorEx += ": " + xml.status;
584
+ });
585
+ jQuery( document ).one( "ajaxStop", function() {
586
+ equal( successCount, 5, "Check all ajax calls successful" );
587
+ equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
588
+ jQuery( document ).off("ajaxError.passthru");
589
+ start();
590
+ });
591
+ Globals.register("testBar");
592
+
593
+ ok( jQuery.get( url(target), success ), "get" );
594
+ ok( jQuery.post( url(target), success ), "post" );
595
+ ok( jQuery.getScript( url("data/test.js"), success ), "script" );
596
+ ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" );
597
+ ok( jQuery.ajax({
598
+ url: url( target ),
599
+ success: success
600
+ }), "generic" );
601
+ });
602
+
603
+ ajaxTest( "jQuery.ajax() - cache", 12, function() {
604
+
605
+ var re = /_=(.*?)(&|$)/g;
606
+
607
+ function request( url, title ) {
608
+ return {
609
+ url: url,
610
+ cache: false,
611
+ beforeSend: function() {
612
+ var parameter, tmp;
613
+ while(( tmp = re.exec( this.url ) )) {
614
+ strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
615
+ parameter = tmp[ 1 ];
616
+ notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
617
+ }
618
+ return false;
619
+ },
620
+ error: true
621
+ };
622
+ }
623
+
624
+ return [
625
+ request(
626
+ "data/text.php",
627
+ "no parameter"
628
+ ),
629
+ request(
630
+ "data/text.php?pizza=true",
631
+ "1 parameter"
632
+ ),
633
+ request(
634
+ "data/text.php?_=tobereplaced555",
635
+ "_= parameter"
636
+ ),
637
+ request(
638
+ "data/text.php?pizza=true&_=tobereplaced555",
639
+ "1 parameter and _="
640
+ ),
641
+ request(
642
+ "data/text.php?_=tobereplaced555&tv=false",
643
+ "_= and 1 parameter"
644
+ ),
645
+ request(
646
+ "data/text.php?name=David&_=tobereplaced555&washere=true",
647
+ "2 parameters surrounding _="
648
+ )
649
+ ];
650
+ });
651
+
652
+ jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
653
+
654
+ ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, [
655
+ {
656
+ url: "data/jsonp.php?callback=?",
657
+ dataType: "jsonp",
658
+ crossDomain: crossDomain,
659
+ success: function( data ) {
660
+ ok( data.data, "JSON results returned (GET, url callback)" );
661
+ }
662
+ },
663
+ {
664
+ url: "data/jsonp.php?callback=??",
665
+ dataType: "jsonp",
666
+ crossDomain: crossDomain,
667
+ success: function( data ) {
668
+ ok( data.data, "JSON results returned (GET, url context-free callback)" );
669
+ }
670
+ },
671
+ {
672
+ url: "data/jsonp.php/??",
673
+ dataType: "jsonp",
674
+ crossDomain: crossDomain,
675
+ success: function( data ) {
676
+ ok( data.data, "JSON results returned (GET, REST-like)" );
677
+ }
678
+ },
679
+ {
680
+ url: "data/jsonp.php/???json=1",
681
+ dataType: "jsonp",
682
+ crossDomain: crossDomain,
683
+ success: function( data ) {
684
+ strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" );
685
+ }
686
+ }
687
+ ]);
688
+
689
+ ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 9, {
690
+ setup: function() {
691
+ Globals.register("functionToCleanUp");
692
+ Globals.register("XXX");
693
+ Globals.register("jsonpResults");
694
+ window["jsonpResults"] = function( data ) {
695
+ ok( data["data"], "JSON results returned (GET, custom callback function)" );
696
+ };
697
+ },
698
+ requests: [{
699
+ url: "data/jsonp.php",
700
+ dataType: "jsonp",
701
+ crossDomain: crossDomain,
702
+ jsonp: "callback",
703
+ success: function( data ) {
704
+ ok( data["data"], "JSON results returned (GET, data obj callback)" );
705
+ }
706
+ }, {
707
+ url: "data/jsonp.php",
708
+ dataType: "jsonp",
709
+ crossDomain: crossDomain,
710
+ jsonpCallback: "jsonpResults",
711
+ success: function( data ) {
712
+ ok( data.data, "JSON results returned (GET, custom callback name)" );
713
+ }
714
+ }, {
715
+ url: "data/jsonp.php",
716
+ dataType: "jsonp",
717
+ crossDomain: crossDomain,
718
+ jsonpCallback: "functionToCleanUp",
719
+ success: function( data ) {
720
+ ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" );
721
+ strictEqual( window["functionToCleanUp"], undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
722
+ var xhr;
723
+ jQuery.ajax({
724
+ url: "data/jsonp.php",
725
+ dataType: "jsonp",
726
+ crossDomain: crossDomain,
727
+ jsonpCallback: "functionToCleanUp",
728
+ beforeSend: function( jqXHR ) {
729
+ xhr = jqXHR;
730
+ return false;
731
+ }
732
+ });
733
+ xhr.fail(function() {
734
+ ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
735
+ strictEqual( window["functionToCleanUp"], undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
736
+ });
737
+ }
738
+ }, {
739
+ url: "data/jsonp.php?callback=XXX",
740
+ dataType: "jsonp",
741
+ jsonp: false,
742
+ jsonpCallback: "XXX",
743
+ crossDomain: crossDomain,
744
+ beforeSend: function() {
745
+ ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
746
+ },
747
+ success: function( data ) {
748
+ ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
749
+ }
750
+ }]
751
+ });
752
+
753
+ ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [
754
+ {
755
+ url: "data/jsonp.php",
756
+ dataType: "jsonp",
757
+ crossDomain: crossDomain,
758
+ data: "callback=?",
759
+ success: function( data ) {
760
+ ok( data.data, "JSON results returned (GET, data callback)" );
761
+ }
762
+ },
763
+ {
764
+ url: "data/jsonp.php",
765
+ dataType: "jsonp",
766
+ crossDomain: crossDomain,
767
+ data: "callback=??",
768
+ success: function( data ) {
769
+ ok( data.data, "JSON results returned (GET, data context-free callback)" );
770
+ }
771
+ }
772
+ ]);
773
+
774
+
775
+ ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [
776
+ {
777
+ type: "POST",
778
+ url: "data/jsonp.php",
779
+ dataType: "jsonp",
780
+ crossDomain: crossDomain,
781
+ success: function( data ) {
782
+ ok( data["data"], "JSON results returned (POST, no callback)" );
783
+ }
784
+ },
785
+ {
786
+ type: "POST",
787
+ url: "data/jsonp.php",
788
+ data: "callback=?",
789
+ dataType: "jsonp",
790
+ crossDomain: crossDomain,
791
+ success: function( data ) {
792
+ ok( data["data"], "JSON results returned (POST, data callback)" );
793
+ }
794
+ },
795
+ {
796
+ type: "POST",
797
+ url: "data/jsonp.php",
798
+ jsonp: "callback",
799
+ dataType: "jsonp",
800
+ crossDomain: crossDomain,
801
+ success: function( data ) {
802
+ ok( data["data"], "JSON results returned (POST, data obj callback)" );
803
+ }
804
+ }
805
+ ]);
806
+
807
+ ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [
808
+ {
809
+ url: "data/jsonp.php",
810
+ dataType: "jsonp",
811
+ crossDomain: crossDomain,
812
+ success: function( data ) {
813
+ ok( data.data, "JSON results returned (GET, no callback)" );
814
+ }
815
+ },
816
+ {
817
+ create: function( options ) {
818
+ var request = jQuery.ajax( options ),
819
+ promise = request.then(function( data ) {
820
+ ok( data.data, "first request: JSON results returned (GET, no callback)" );
821
+ request = jQuery.ajax( this ).done(function( data ) {
822
+ ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
823
+ });
824
+ promise.abort = request.abort;
825
+ return request;
826
+ });
827
+ promise.abort = request.abort;
828
+ return promise;
829
+ },
830
+ url: "data/jsonp.php",
831
+ dataType: "jsonp",
832
+ crossDomain: crossDomain,
833
+ success: true
834
+ }
835
+ ]);
836
+
837
+ });
838
+
839
+ ajaxTest( "jQuery.ajax() - script, Remote", 2, {
840
+ setup: function() {
841
+ Globals.register("testBar");
842
+ },
843
+ url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js",
844
+ dataType: "script",
845
+ success: function( data ) {
846
+ strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
847
+ }
848
+ });
849
+
850
+ ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, {
851
+ setup: function() {
852
+ Globals.register("testBar");
853
+ },
854
+ url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js",
855
+ type: "POST",
856
+ dataType: "script",
857
+ success: function( data, status ) {
858
+ strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" );
859
+ strictEqual( status, "success", "Script results returned (POST, no callback)" );
860
+ }
861
+ });
862
+
863
+ ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, {
864
+ setup: function() {
865
+ Globals.register("testBar");
866
+ },
867
+ url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/test.js",
868
+ dataType: "script",
869
+ success: function( data ) {
870
+ strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
871
+ }
872
+ });
873
+
874
+ ajaxTest( "jQuery.ajax() - malformed JSON", 2, {
875
+ url: "data/badjson.js",
876
+ dataType: "json",
877
+ error: function( xhr, msg, detailedMsg ) {
878
+ strictEqual( msg, "parsererror", "A parse error occurred." );
879
+ ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
880
+ }
881
+ });
882
+
883
+ ajaxTest( "jQuery.ajax() - script by content-type", 2, [
884
+ {
885
+ url: "data/script.php",
886
+ data: {
887
+ "header": "script"
888
+ },
889
+ success: true
890
+ },
891
+ {
892
+ url: "data/script.php",
893
+ data: {
894
+ "header": "ecma"
895
+ },
896
+ success: true
897
+ }
898
+ ]);
899
+
900
+ ajaxTest( "jQuery.ajax() - JSON by content-type", 5, {
901
+ url: "data/json.php",
902
+ data: {
903
+ "header": "json",
904
+ "json": "array"
905
+ },
906
+ success: function( json ) {
907
+ ok( json.length >= 2, "Check length" );
908
+ strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
909
+ strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
910
+ strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
911
+ strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
912
+ }
913
+ });
914
+
915
+ ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, {
916
+ url: url("data/json.php"),
917
+ data: {
918
+ "header": "json",
919
+ "json": "array"
920
+ },
921
+ contents: {
922
+ "json": false
923
+ },
924
+ success: function( text ) {
925
+ strictEqual( typeof text, "string", "json wasn't auto-determined" );
926
+ var json = jQuery.parseJSON( text );
927
+ ok( json.length >= 2, "Check length");
928
+ strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
929
+ strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
930
+ strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
931
+ strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
932
+ }
933
+ });
934
+
935
+ ajaxTest( "jQuery.ajax() - simple get", 1, {
936
+ type: "GET",
937
+ url: url("data/name.php?name=foo"),
938
+ success: function( msg ) {
939
+ strictEqual( msg, "bar", "Check for GET" );
940
+ }
941
+ });
942
+
943
+ ajaxTest( "jQuery.ajax() - simple post", 1, {
944
+ type: "POST",
945
+ url: url("data/name.php"),
946
+ data: "name=peter",
947
+ success: function( msg ) {
948
+ strictEqual( msg, "pan", "Check for POST" );
949
+ }
950
+ });
951
+
952
+ ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, {
953
+ url: "data/echoData.php",
954
+ data: undefined,
955
+ type: "post",
956
+ success: function( result ) {
957
+ strictEqual( result, "" );
958
+ }
959
+ });
960
+
961
+ var ifModifiedNow = new Date();
962
+
963
+ jQuery.each(
964
+ /* jQuery.each arguments start */
965
+ {
966
+ " (cache)": true,
967
+ " (no cache)": false
968
+ },
969
+ function( label, cache ) {
970
+ var isOpera = !!window.opera;
971
+
972
+ asyncTest( "jQuery.ajax() - If-Modified-Since support" + label, 3, function() {
973
+ var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
974
+
975
+ jQuery.ajax({
976
+ url: url,
977
+ ifModified: true,
978
+ cache: cache,
979
+ success: function( data, status ) {
980
+ strictEqual( status, "success" );
981
+
982
+ jQuery.ajax({
983
+ url: url,
984
+ ifModified: true,
985
+ cache: cache,
986
+ success: function( data, status ) {
987
+ if ( data === "FAIL" ) {
988
+ ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
989
+ ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
990
+ } else {
991
+ strictEqual( status, "notmodified" );
992
+ ok( data == null, "response body should be empty" );
993
+ }
994
+ start();
995
+ },
996
+ error: function() {
997
+ // Do this because opera simply refuses to implement 304 handling :(
998
+ // A feature-driven way of detecting this would be appreciated
999
+ // See: http://gist.github.com/599419
1000
+ ok( isOpera, "error" );
1001
+ ok( isOpera, "error" );
1002
+ start();
1003
+ }
1004
+ });
1005
+ },
1006
+ error: function() {
1007
+ strictEqual( false, "error" );
1008
+ // Do this because opera simply refuses to implement 304 handling :(
1009
+ // A feature-driven way of detecting this would be appreciated
1010
+ // See: http://gist.github.com/599419
1011
+ ok( isOpera, "error" );
1012
+ start();
1013
+ }
1014
+ });
1015
+ });
1016
+
1017
+ asyncTest( "jQuery.ajax() - Etag support" + label, 3, function() {
1018
+ var url = "data/etag.php?ts=" + ifModifiedNow++;
1019
+
1020
+ jQuery.ajax({
1021
+ url: url,
1022
+ ifModified: true,
1023
+ cache: cache,
1024
+ success: function( data, status ) {
1025
+ strictEqual( status, "success" );
1026
+
1027
+ jQuery.ajax({
1028
+ url: url,
1029
+ ifModified: true,
1030
+ cache: cache,
1031
+ success: function( data, status ) {
1032
+ if ( data === "FAIL" ) {
1033
+ ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1034
+ ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1035
+ } else {
1036
+ strictEqual( status, "notmodified" );
1037
+ ok( data == null, "response body should be empty" );
1038
+ }
1039
+ start();
1040
+ },
1041
+ error: function() {
1042
+ // Do this because opera simply refuses to implement 304 handling :(
1043
+ // A feature-driven way of detecting this would be appreciated
1044
+ // See: http://gist.github.com/599419
1045
+ ok( isOpera, "error" );
1046
+ ok( isOpera, "error" );
1047
+ start();
1048
+ }
1049
+ });
1050
+ },
1051
+ error: function() {
1052
+ // Do this because opera simply refuses to implement 304 handling :(
1053
+ // A feature-driven way of detecting this would be appreciated
1054
+ // See: http://gist.github.com/599419
1055
+ ok( isOpera, "error" );
1056
+ start();
1057
+ }
1058
+ });
1059
+ });
1060
+ }
1061
+ /* jQuery.each arguments end */
1062
+ );
1063
+
1064
+ ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, {
1065
+ // see RFC 2606
1066
+ url: "http://example.invalid",
1067
+ error: function( xhr, _, e ) {
1068
+ ok( true, "file not found: " + xhr.status + " => " + e );
1069
+ }
1070
+ });
1071
+
1072
+ ajaxTest( "jQuery.ajax() - failing cross-domain", 1, {
1073
+ url: "http://" + externalHost,
1074
+ error: function( xhr, _, e ) {
1075
+ ok( true, "access denied: " + xhr.status + " => " + e );
1076
+ }
1077
+ });
1078
+
1079
+ ajaxTest( "jQuery.ajax() - atom+xml", 1, {
1080
+ url: url("data/atom+xml.php"),
1081
+ success: function() {
1082
+ ok( true, "success" );
1083
+ }
1084
+ });
1085
+
1086
+ asyncTest( "jQuery.ajax() - statusText", 3, function() {
1087
+ jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) {
1088
+ strictEqual( statusText, "success", "callback status text ok for success" );
1089
+ ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
1090
+ jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) {
1091
+ strictEqual( statusText, "error", "callback status text ok for error" );
1092
+ // ok( jqXHR.statusText === "World" || jQuery.browser.safari && jqXHR.statusText === "Not Found", "jqXHR status text ok for error (" + jqXHR.statusText + ")" );
1093
+ start();
1094
+ });
1095
+ });
1096
+ });
1097
+
1098
+ asyncTest( "jQuery.ajax() - statusCode", 20, function() {
1099
+
1100
+ var count = 12;
1101
+
1102
+ function countComplete() {
1103
+ if ( ! --count ) {
1104
+ start();
1105
+ }
1106
+ }
1107
+
1108
+ function createStatusCodes( name, isSuccess ) {
1109
+ name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
1110
+ return {
1111
+ 200: function() {
1112
+ ok( isSuccess, name );
1113
+ },
1114
+ 404: function() {
1115
+ ok( !isSuccess, name );
1116
+ }
1117
+ };
1118
+ }
1119
+
1120
+ jQuery.each(
1121
+ /* jQuery.each arguments start */
1122
+ {
1123
+ "data/name.html": true,
1124
+ "data/someFileThatDoesNotExist.html": false
1125
+ },
1126
+ function( uri, isSuccess ) {
1127
+
1128
+ jQuery.ajax( url(uri), {
1129
+ statusCode: createStatusCodes( "in options", isSuccess ),
1130
+ complete: countComplete
1131
+ });
1132
+
1133
+ jQuery.ajax( url(uri), {
1134
+ complete: countComplete
1135
+ }).statusCode( createStatusCodes("immediately with method", isSuccess) );
1136
+
1137
+ jQuery.ajax( url(uri), {
1138
+ complete: function( jqXHR ) {
1139
+ jqXHR.statusCode( createStatusCodes("on complete", isSuccess) );
1140
+ countComplete();
1141
+ }
1142
+ });
1143
+
1144
+ jQuery.ajax( url(uri), {
1145
+ complete: function( jqXHR ) {
1146
+ setTimeout(function() {
1147
+ jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) );
1148
+ countComplete();
1149
+ }, 100 );
1150
+ }
1151
+ });
1152
+
1153
+ jQuery.ajax( url(uri), {
1154
+ statusCode: createStatusCodes( "all (options)", isSuccess ),
1155
+ complete: function( jqXHR ) {
1156
+ jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) );
1157
+ setTimeout(function() {
1158
+ jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) );
1159
+ countComplete();
1160
+ }, 100 );
1161
+ }
1162
+ }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) );
1163
+
1164
+ var testString = "";
1165
+
1166
+ jQuery.ajax( url(uri), {
1167
+ success: function( a, b, jqXHR ) {
1168
+ ok( isSuccess, "success" );
1169
+ var statusCode = {};
1170
+ statusCode[ jqXHR.status ] = function() {
1171
+ testString += "B";
1172
+ };
1173
+ jqXHR.statusCode( statusCode );
1174
+ testString += "A";
1175
+ },
1176
+ error: function( jqXHR ) {
1177
+ ok( !isSuccess, "error" );
1178
+ var statusCode = {};
1179
+ statusCode[ jqXHR.status ] = function() {
1180
+ testString += "B";
1181
+ };
1182
+ jqXHR.statusCode( statusCode );
1183
+ testString += "A";
1184
+ },
1185
+ complete: function() {
1186
+ strictEqual(
1187
+ testString,
1188
+ "AB",
1189
+ "Test statusCode callbacks are ordered like " + ( isSuccess ? "success" : "error" ) + " callbacks"
1190
+ );
1191
+ countComplete();
1192
+ }
1193
+ });
1194
+
1195
+ }
1196
+ /* jQuery.each arguments end*/
1197
+ );
1198
+ });
1199
+
1200
+ ajaxTest( "jQuery.ajax() - transitive conversions", 8, [
1201
+ {
1202
+ url: url("data/json.php"),
1203
+ converters: {
1204
+ "json myJson": function( data ) {
1205
+ ok( true, "converter called" );
1206
+ return data;
1207
+ }
1208
+ },
1209
+ dataType: "myJson",
1210
+ success: function() {
1211
+ ok( true, "Transitive conversion worked" );
1212
+ strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" );
1213
+ strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" );
1214
+ }
1215
+ },
1216
+ {
1217
+ url: url("data/json.php"),
1218
+ converters: {
1219
+ "json myJson": function( data ) {
1220
+ ok( true, "converter called (*)" );
1221
+ return data;
1222
+ }
1223
+ },
1224
+ contents: false, /* headers are wrong so we ignore them */
1225
+ dataType: "* myJson",
1226
+ success: function() {
1227
+ ok( true, "Transitive conversion worked (*)" );
1228
+ strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" );
1229
+ strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" );
1230
+ }
1231
+ }
1232
+ ]);
1233
+
1234
+ ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [
1235
+ {
1236
+ url: url("data/json.php"),
1237
+ beforeSend: function( xhr ) {
1238
+ xhr.overrideMimeType( "application/json" );
1239
+ },
1240
+ success: function( json ) {
1241
+ ok( json.data, "Mimetype overriden using beforeSend" );
1242
+ }
1243
+ },
1244
+ {
1245
+ url: url("data/json.php"),
1246
+ mimeType: "application/json",
1247
+ success: function( json ) {
1248
+ ok( json.data, "Mimetype overriden using mimeType option" );
1249
+ }
1250
+ }
1251
+ ]);
1252
+
1253
+ ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, {
1254
+ url: url("data/echoData.php"),
1255
+ error: function( _, __, error ) {
1256
+ equal( typeof error === "object", true, "Didn't get back error object for empty json response" );
1257
+ },
1258
+ dataType: "json"
1259
+ });
1260
+
1261
+ ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, {
1262
+ create: function() {
1263
+ return jQuery.ajax({
1264
+ url: url("data/name.html"),
1265
+ beforeSend: function() {
1266
+ ok( true, "beforeSend got called, canceling" );
1267
+ return false;
1268
+ },
1269
+ success: function() {
1270
+ ok( false, "request didn't get canceled" );
1271
+ },
1272
+ complete: function() {
1273
+ ok( false, "request didn't get canceled" );
1274
+ },
1275
+ error: function() {
1276
+ ok( false, "request didn't get canceled" );
1277
+ }
1278
+ });
1279
+ },
1280
+ fail: function( _, reason ) {
1281
+ strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
1282
+ }
1283
+ });
1284
+
1285
+ ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, {
1286
+ url: "data/echoQuery.php",
1287
+ data: {
1288
+ key: function() {
1289
+ return "value";
1290
+ }
1291
+ },
1292
+ success: function( result ) {
1293
+ strictEqual( result, "key=value" );
1294
+ }
1295
+ });
1296
+
1297
+ test( "#7531 - jQuery.ajax() - Location object as url", 1, function () {
1298
+ var success = false;
1299
+ try {
1300
+ var xhr = jQuery.ajax({
1301
+ url: window.location
1302
+ });
1303
+ success = true;
1304
+ xhr.abort();
1305
+ } catch (e) {
1306
+
1307
+ }
1308
+ ok( success, "document.location did not generate exception" );
1309
+ });
1310
+
1311
+ jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1312
+ ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, {
1313
+ url: "data/jsonp.php",
1314
+ dataType: "jsonp",
1315
+ crossDomain: crossDomain,
1316
+ beforeSend: function( jqXHR, s ) {
1317
+ strictEqual( this.cache, false, "cache must be false on JSON request" );
1318
+ return false;
1319
+ },
1320
+ error: true
1321
+ });
1322
+ });
1323
+
1324
+ ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [
1325
+ {
1326
+ create: function() {
1327
+ return jQuery.ajax();
1328
+ },
1329
+ done: function() {
1330
+ ok( true, "With no arguments" );
1331
+ }
1332
+ },
1333
+ {
1334
+ create: function() {
1335
+ return jQuery.ajax("data/name.html");
1336
+ },
1337
+ done: function() {
1338
+ ok( true, "With only string URL argument" );
1339
+ }
1340
+ },
1341
+ {
1342
+ create: function() {
1343
+ return jQuery.ajax( "data/name.html", {});
1344
+ },
1345
+ done: function() {
1346
+ ok( true, "With string URL param and map" );
1347
+ }
1348
+ },
1349
+ {
1350
+ create: function( options ) {
1351
+ return jQuery.ajax( options );
1352
+ },
1353
+ url: "data/name.html",
1354
+ success: function() {
1355
+ ok( true, "With only map" );
1356
+ }
1357
+ }
1358
+ ]);
1359
+
1360
+ jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1361
+ ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 2, {
1362
+ url: "data/jsonp.php",
1363
+ dataType: "jsonp",
1364
+ crossDomain: crossDomain,
1365
+ beforeSend: function( jqXHR, s ) {
1366
+ s.callback = s.jsonpCallback;
1367
+ },
1368
+ success: function() {
1369
+ var previous = this;
1370
+ strictEqual( previous.jsonpCallback, undefined, "jsonpCallback option is set back to default in callbacks" );
1371
+ jQuery.ajax({
1372
+ url: "data/jsonp.php",
1373
+ dataType: "jsonp",
1374
+ crossDomain: crossDomain,
1375
+ beforeSend: function() {
1376
+ strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
1377
+ return false;
1378
+ }
1379
+ });
1380
+ }
1381
+ });
1382
+ });
1383
+
1384
+ test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", 2, function () {
1385
+ var success = false,
1386
+ context = {};
1387
+ context.field = context;
1388
+ try {
1389
+ jQuery.ajax( "non-existing", {
1390
+ context: context,
1391
+ beforeSend: function() {
1392
+ ok( this === context, "context was not deep extended" );
1393
+ return false;
1394
+ }
1395
+ });
1396
+ success = true;
1397
+ } catch ( e ) {
1398
+ console.log( e );
1399
+ }
1400
+ ok( success, "context with circular reference did not generate an exception" );
1401
+ });
1402
+
1403
+ jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {
1404
+
1405
+ function request( url, test ) {
1406
+ return {
1407
+ create: function() {
1408
+ return jQuery.ajax( inSetting ? { url: url } : url );
1409
+ },
1410
+ done: function() {
1411
+ ok( true, ( test || url ) + " " + title );
1412
+ }
1413
+ };
1414
+ }
1415
+
1416
+ ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, [
1417
+ request( "", "empty string" ),
1418
+ request( false ),
1419
+ request( null ),
1420
+ request( undefined )
1421
+ ]);
1422
+
1423
+ });
1424
+
1425
+ ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, {
1426
+ url: url("data/1x1.jpg"),
1427
+ success: function( data ) {
1428
+ ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
1429
+ }
1430
+ });
1431
+
1432
+ test( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
1433
+ raises(function() {
1434
+ jQuery.ajax({
1435
+ url: "data/badjson.js",
1436
+ dataType: "script",
1437
+ throws: true,
1438
+ // TODO find a way to test this asynchronously, too
1439
+ async: false,
1440
+ // Global events get confused by the exception
1441
+ global: false,
1442
+ success: function() {
1443
+ ok( false, "Success." );
1444
+ },
1445
+ error: function() {
1446
+ ok( false, "Error." );
1447
+ }
1448
+ });
1449
+ }, "exception bubbled" );
1450
+ });
1451
+
1452
+ jQuery.each( [ "method", "type" ], function( _, globalOption ) {
1453
+
1454
+ function request( option ) {
1455
+ var options = {
1456
+ url: url("data/echoData.php"),
1457
+ data: "hello",
1458
+ success: function( msg ) {
1459
+ strictEqual( msg, "hello", "Check for POST (no override)" );
1460
+ }
1461
+ };
1462
+ if ( option ) {
1463
+ options[ option ] = "GET";
1464
+ options.success = function( msg ) {
1465
+ strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" );
1466
+ };
1467
+ }
1468
+ return options;
1469
+ }
1470
+
1471
+ ajaxTest( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally", 3, {
1472
+ setup: function() {
1473
+ var options = {};
1474
+ options[ globalOption ] = "POST";
1475
+ jQuery.ajaxSetup( options );
1476
+ },
1477
+ requests: [
1478
+ request("type"),
1479
+ request("method"),
1480
+ request()
1481
+ ]
1482
+ });
1483
+
1484
+ });
1485
+
1486
+ ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, {
1487
+ url: "data/dashboard.xml",
1488
+ dataType: "xml",
1489
+ success: function( ajaxXML ) {
1490
+ var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab");
1491
+ ajaxXML = jQuery( ajaxXML );
1492
+ try {
1493
+ ajaxXML.find("infowindowtab").append( parsedXML );
1494
+ } catch( e ) {
1495
+ strictEqual( e, undefined, "error" );
1496
+ return;
1497
+ }
1498
+ strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" );
1499
+ }
1500
+ });
1501
+
1502
+ ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, {
1503
+ url: "data/nocontent.php",
1504
+ dataType: "testing",
1505
+ converters: {
1506
+ "* testing": function() {
1507
+ throw "converter was called";
1508
+ }
1509
+ },
1510
+ success: function( data, status, jqXHR ) {
1511
+ strictEqual( jqXHR.status, 204, "status code is 204" );
1512
+ strictEqual( status, "nocontent", "status text is 'nocontent'" );
1513
+ strictEqual( data, undefined, "data is undefined" );
1514
+ },
1515
+ error: function( _, status, error ) {
1516
+ ok( false, "error" );
1517
+ strictEqual( status, "parsererror", "Parser Error" );
1518
+ strictEqual( error, "converter was called", "Converter was called" );
1519
+ }
1520
+ });
1521
+
1522
+ //----------- jQuery.ajaxPrefilter()
1523
+
1524
+ ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {
1525
+ setup: function() {
1526
+ jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
1527
+ if ( options.abortInPrefilter ) {
1528
+ jqXHR.abort();
1529
+ }
1530
+ });
1531
+ },
1532
+ abortInPrefilter: true,
1533
+ error: function() {
1534
+ ok( false, "error callback called" );
1535
+ },
1536
+ fail: function( _, reason ) {
1537
+ strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
1538
+ }
1539
+ });
1540
+
1541
+ //----------- jQuery.ajaxSetup()
1542
+
1543
+ asyncTest( "jQuery.ajaxSetup()", 1, function() {
1544
+ jQuery.ajaxSetup({
1545
+ url: url("data/name.php?name=foo"),
1546
+ success: function( msg ) {
1547
+ strictEqual( msg, "bar", "Check for GET" );
1548
+ start();
1549
+ }
1550
+ });
1551
+ jQuery.ajax();
1552
+ });
1553
+
1554
+ asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() {
1555
+ var passed = 0,
1556
+ pass = function() {
1557
+ ok( passed++ < 2, "Error callback executed" );
1558
+ if ( passed == 2 ) {
1559
+ jQuery( document ).off("ajaxError.setupTest");
1560
+ start();
1561
+ }
1562
+ },
1563
+ fail = function( a, b, c ) {
1564
+ ok( false, "Check for timeout failed " + a + " " + b );
1565
+ start();
1566
+ };
1567
+
1568
+ jQuery( document ).on( "ajaxError.setupTest", pass );
1569
+
1570
+ jQuery.ajaxSetup({
1571
+ timeout: 1000
1572
+ });
1573
+
1574
+ jQuery.ajax({
1575
+ type: "GET",
1576
+ url: url("data/name.php?wait=5"),
1577
+ error: pass,
1578
+ success: fail
1579
+ });
1580
+ });
1581
+
1582
+ asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() {
1583
+ jQuery.ajaxSetup({
1584
+ timeout: 50
1585
+ });
1586
+ jQuery.ajax({
1587
+ type: "GET",
1588
+ timeout: 15000,
1589
+ url: url("data/name.php?wait=1"),
1590
+ error: function() {
1591
+ ok( false, "Check for local timeout failed" );
1592
+ start();
1593
+ },
1594
+ success: function() {
1595
+ ok( true, "Check for local timeout" );
1596
+ start();
1597
+ }
1598
+ });
1599
+ });
1600
+
1601
+ //----------- jQuery.domManip()
1602
+
1603
+ test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", 1, function() {
1604
+ jQuery.ajaxSetup({
1605
+ type: "POST"
1606
+ });
1607
+
1608
+ jQuery( document ).bind( "ajaxStart ajaxStop", function() {
1609
+ ok( false, "Global event triggered" );
1610
+ });
1611
+
1612
+ jQuery("#qunit-fixture").append("<script src='data/evalScript.php'></script>");
1613
+
1614
+ jQuery( document ).unbind("ajaxStart ajaxStop");
1615
+ });
1616
+
1617
+ asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
1618
+ jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
1619
+ });
1620
+
1621
+ //----------- jQuery.get()
1622
+
1623
+ asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() {
1624
+ jQuery.get( url("data/dashboard.xml"), function( xml ) {
1625
+ var content = [];
1626
+ jQuery( "tab", xml ).each(function() {
1627
+ content.push( jQuery( this ).text() );
1628
+ });
1629
+ strictEqual( content[ 0 ], "blabla", "Check first tab" );
1630
+ strictEqual( content[ 1 ], "blublu", "Check second tab" );
1631
+ start();
1632
+ });
1633
+ });
1634
+
1635
+ asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() {
1636
+ jQuery.ajaxSetup({
1637
+ data: "helloworld"
1638
+ });
1639
+ jQuery.get( url("data/echoQuery.php"), function( data ) {
1640
+ ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
1641
+ start();
1642
+ });
1643
+ });
1644
+
1645
+ //----------- jQuery.getJSON()
1646
+
1647
+ asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() {
1648
+ jQuery.getJSON(
1649
+ url("data/json.php"),
1650
+ {
1651
+ "json": "array"
1652
+ },
1653
+ function( json ) {
1654
+ ok( json.length >= 2, "Check length" );
1655
+ strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
1656
+ strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
1657
+ strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
1658
+ strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
1659
+ start();
1660
+ }
1661
+ );
1662
+ });
1663
+
1664
+ asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() {
1665
+ jQuery.getJSON( url("data/json.php"), function( json ) {
1666
+ if ( json && json["data"] ) {
1667
+ strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
1668
+ strictEqual( json["data"].length, 25, "Check JSON: length" );
1669
+ start();
1670
+ }
1671
+ });
1672
+ });
1673
+
1674
+ asyncTest( "jQuery.getJSON() - Using Native JSON", 2, function() {
1675
+ var restore = "JSON" in window,
1676
+ old = window.JSON;
1677
+ if ( !restore ) {
1678
+ Globals.register("JSON");
1679
+ }
1680
+ window.JSON = {
1681
+ parse: function( str ) {
1682
+ ok( true, "Verifying that parse method was run" );
1683
+ window.JSON = old;
1684
+ return true;
1685
+ }
1686
+ };
1687
+ jQuery.getJSON( url("data/json.php"), function( json ) {
1688
+ strictEqual( json, true, "Verifying return value" );
1689
+ start();
1690
+ });
1691
+ });
1692
+
1693
+ asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() {
1694
+ jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
1695
+ strictEqual( json.data.lang, "en", "Check JSON: lang" );
1696
+ strictEqual( json.data.length, 25, "Check JSON: length" );
1697
+ start();
1698
+ });
1699
+ });
1700
+
1701
+ //----------- jQuery.getScript()
1702
+
1703
+ asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
1704
+ Globals.register("testBar");
1705
+ jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) {
1706
+ strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
1707
+ start();
1708
+ });
1709
+ });
1710
+
1711
+ asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
1712
+ Globals.register("testBar");
1713
+ jQuery.getScript( url("data/test.js") ).done( start );
1714
+ });
1715
+
1716
+ asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() {
1717
+ Globals.register("testBar");
1718
+ jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) {
1719
+ strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
1720
+ start();
1721
+ });
1722
+ });
1723
+
1724
+ //----------- jQuery.fn.load()
1725
+
1726
+ // check if load can be called with only url
1727
+ asyncTest( "jQuery.fn.load( String )", 2, function() {
1728
+ jQuery.ajaxSetup({
1729
+ beforeSend: function() {
1730
+ strictEqual( this.type, "GET", "no data means GET request" );
1731
+ }
1732
+ });
1733
+ jQuery("#first").load( "data/name.html", start );
1734
+ });
1735
+
1736
+ asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() {
1737
+ addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")();
1738
+ jQuery( document ).ajaxStop( start );
1739
+ jQuery("<div/>").load( "data/404.html", function() {
1740
+ ok( true, "complete" );
1741
+ });
1742
+ });
1743
+
1744
+ // check if load can be called with url and null data
1745
+ asyncTest( "jQuery.fn.load( String, null )", 2, function() {
1746
+ jQuery.ajaxSetup({
1747
+ beforeSend: function() {
1748
+ strictEqual( this.type, "GET", "no data means GET request" );
1749
+ }
1750
+ });
1751
+ jQuery("#first").load( "data/name.html", null, start );
1752
+ });
1753
+
1754
+ // check if load can be called with url and undefined data
1755
+ asyncTest( "jQuery.fn.load( String, undefined )", 2, function() {
1756
+ jQuery.ajaxSetup({
1757
+ beforeSend: function() {
1758
+ strictEqual( this.type, "GET", "no data means GET request" );
1759
+ }
1760
+ });
1761
+ jQuery("#first").load( "data/name.html", undefined, start );
1762
+ });
1763
+
1764
+ // check if load can be called with only url
1765
+ asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() {
1766
+ jQuery("#first").load( "data/test3.html div.user", function() {
1767
+ strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
1768
+ start();
1769
+ });
1770
+ });
1771
+
1772
+ asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
1773
+ jQuery("#first").load( url("data/name.html"), function() {
1774
+ ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
1775
+ start();
1776
+ });
1777
+ });
1778
+
1779
+ asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() {
1780
+ var verifyEvaluation = function() {
1781
+ strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
1782
+ strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
1783
+ start();
1784
+ };
1785
+
1786
+ Globals.register("testFoo");
1787
+ Globals.register("testBar");
1788
+
1789
+ jQuery("#first").load( url("data/test.html"), function() {
1790
+ ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
1791
+ strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
1792
+ strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1793
+ setTimeout( verifyEvaluation, 600 );
1794
+ });
1795
+ });
1796
+
1797
+ asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() {
1798
+ Globals.register("testFoo");
1799
+
1800
+ jQuery("#first").load( url("data/test2.html"), function() {
1801
+ strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
1802
+ strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1803
+ start();
1804
+ });
1805
+ });
1806
+
1807
+ asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() {
1808
+ jQuery.ajaxSetup({
1809
+ dataFilter: function() {
1810
+ return "Hello World";
1811
+ }
1812
+ });
1813
+ jQuery("<div/>").load( url("data/name.html"), function( responseText ) {
1814
+ strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
1815
+ strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
1816
+ start();
1817
+ });
1818
+ });
1819
+
1820
+ asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() {
1821
+ jQuery("<div />").load( url("data/params_html.php"), {
1822
+ "foo": 3,
1823
+ "bar": "ok"
1824
+ }, function() {
1825
+ var $post = jQuery( this ).find("#post");
1826
+ strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
1827
+ strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
1828
+ start();
1829
+ });
1830
+ });
1831
+
1832
+ asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() {
1833
+ jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
1834
+ var $get = jQuery( this ).find("#get");
1835
+ strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
1836
+ strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" );
1837
+ start();
1838
+ });
1839
+ });
1840
+
1841
+ asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
1842
+ var slice = [].slice,
1843
+ completeArgs = {};
1844
+
1845
+ jQuery.ajaxSetup({
1846
+ success: function( _, status, jqXHR ) {
1847
+ completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1848
+ },
1849
+ error: function( jqXHR, status ) {
1850
+ completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1851
+ }
1852
+ });
1853
+
1854
+ jQuery.when.apply(
1855
+ jQuery,
1856
+ jQuery.map([
1857
+ {
1858
+ type: "success",
1859
+ url: "data/echoQuery.php?arg=pop"
1860
+ },
1861
+ {
1862
+ type: "error",
1863
+ url: "data/404.php"
1864
+ }
1865
+ ],
1866
+ function( options ) {
1867
+ return jQuery.Deferred(function( defer ) {
1868
+ jQuery("#foo").load( options.url, function() {
1869
+ var args = arguments;
1870
+ strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
1871
+ jQuery.each( completeArgs[ options.url ], function( i, value ) {
1872
+ strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
1873
+ });
1874
+ defer.resolve();
1875
+ });
1876
+ });
1877
+ })
1878
+ ).always( start );
1879
+ });
1880
+
1881
+ asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() {
1882
+ jQuery.ajaxSetup({
1883
+ dataType: "json"
1884
+ });
1885
+ jQuery( document ).ajaxComplete(function( e, xml, s ) {
1886
+ strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
1887
+ jQuery( document ).unbind("ajaxComplete");
1888
+ start();
1889
+ });
1890
+ jQuery("#first").load("data/test3.html");
1891
+ });
1892
+
1893
+ asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() {
1894
+ var data = {
1895
+ "baz": 1
1896
+ };
1897
+ jQuery.ajaxSetup({
1898
+ data: {
1899
+ "foo": "bar"
1900
+ }
1901
+ });
1902
+ jQuery("#foo").load( "data/echoQuery.php", data );
1903
+ jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
1904
+ ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
1905
+ start();
1906
+ });
1907
+ });
1908
+
1909
+ //----------- jQuery.post()
1910
+
1911
+ asyncTest( "jQuery.post() - data", 3, function() {
1912
+ jQuery.when(
1913
+ jQuery.post(
1914
+ url("data/name.php"),
1915
+ {
1916
+ xml: "5-2",
1917
+ length: 3
1918
+ },
1919
+ function( xml ) {
1920
+ jQuery( "math", xml ).each(function() {
1921
+ strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
1922
+ strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
1923
+ });
1924
+ }
1925
+ ),
1926
+ jQuery.ajax({
1927
+ url: url("data/echoData.php"),
1928
+ type: "POST",
1929
+ data: {
1930
+ "test": {
1931
+ "length": 7,
1932
+ "foo": "bar"
1933
+ }
1934
+ },
1935
+ success: function( data ) {
1936
+ strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
1937
+ }
1938
+ })
1939
+ ).always( start );
1940
+ });
1941
+
1942
+ asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() {
1943
+ jQuery.when(
1944
+ jQuery.post(
1945
+ url("data/name.php"),
1946
+ {
1947
+ "xml": "5-2"
1948
+ },
1949
+ function( xml ) {
1950
+ jQuery( "math", xml ).each(function() {
1951
+ strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
1952
+ strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
1953
+ });
1954
+ }
1955
+ ),
1956
+ jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
1957
+ jQuery( "math", xml ).each(function() {
1958
+ strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
1959
+ strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
1960
+ });
1961
+ })
1962
+ ).always( start );
1963
+ });
1964
+
1965
+ //----------- jQuery.active
1966
+
1967
+ test( "jQuery.active", 1, function() {
1968
+ ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
1969
+ });
1970
+
1971
+ })();