uploading.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Plupload: Uploading</title>
  6. <script src="../loader.js"></script>
  7. <script type="text/javascript">
  8. QUnit.config.reorder = false;
  9. QUnit.config.autostart = false;
  10. QUnit.config.testTimeout = 10000;
  11. FileHash.init({
  12. files: ['files/01.min.js', 'files/02.min.js'],
  13. onready: function() {
  14. QUnit.start();
  15. }
  16. });
  17. o.Env.swf_url = "../../js/flash/Moxie.swf";
  18. o.Env.xap_url = "../../js/silverlight/Moxie.xap";
  19. module("Test uploading");
  20. test("multipart=false", function() {
  21. var up = new plupload.Uploader({
  22. runtimes: 'test',
  23. browse_button: 'qunit-fixture',
  24. url: "Plupload/upload.php",
  25. required_features: true,
  26. multipart: false,
  27. headers: {
  28. "Content-Type": "image/jpeg"
  29. }
  30. });
  31. up.bind('PostInit', function() {
  32. var files = FileHash.getRuntimeFiles();
  33. up.addFile(files[0]);
  34. });
  35. up.bind('Error', function() {
  36. start();
  37. ok(false, "Plupload cannot be initialized.");
  38. up.destroy();
  39. });
  40. stop();
  41. up.init();
  42. up.bind('FilesAdded', function() {
  43. up.start();
  44. });
  45. up.bind('FileUploaded', function(up, file, result) {
  46. var response = JSON.parse(result.response);
  47. start();
  48. equal(response.headers["content-type"], "image/jpeg",
  49. "not forcing content-type=application/octet-stream when multipart=false.");
  50. up.destroy();
  51. });
  52. });
  53. test("http_method='PUT'", function() {
  54. expect(3);
  55. var uploader = new plupload.Uploader({
  56. browse_button: 'qunit-fixture',
  57. runtimes: 'test',
  58. url: '../upload.php',
  59. http_method: 'GRAB', // arbitrary bullshit method
  60. preinit: {
  61. Init: function(up, info) {
  62. var files = FileHash.getRuntimeFiles();
  63. up.addFile(files[0]);
  64. },
  65. Error: function(up, err) {
  66. start();
  67. ok(false, "Plupload failed to initialize.");
  68. }
  69. },
  70. init: {
  71. FilesAdded: function(up) {
  72. equal(up.getOption('http_method'), 'POST',
  73. "http_method should be either PUT or POST.");
  74. up.setOption('http_method', 'put');
  75. equal(up.getOption('http_method'), 'PUT',
  76. "http_method set to PUT and upper-cased.");
  77. up.start();
  78. },
  79. FileUploaded: function(up, file, result) {
  80. start();
  81. var meta = (function(headers) {
  82. var meta = {};
  83. o.each(headers, function(header) {
  84. if (/^meta\-/.test(header)) {
  85. var parts = header.split(/:/);
  86. meta[parts[0].replace(/^meta\-/, '')] = parts[1];
  87. }
  88. });
  89. return meta;
  90. }(result.responseHeaders.split(/\r\n/)));
  91. equal(up.getOption('http_method'), 'PUT',
  92. "PUT was used as HTTP method.");
  93. }
  94. }
  95. });
  96. stop();
  97. uploader.init();
  98. });
  99. </script>
  100. </head>
  101. <body>
  102. <div id="qunit"></div>
  103. <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
  104. </body>
  105. </html>