Events.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Plupload: Test Uploader Events</title>
  6. <script src="../loader.js"></script>
  7. <script type="text/javascript">
  8. QUnit.config.reorder = false;
  9. QUnit.config.testTimeout = 10000;
  10. o.Env.swf_url = "../../js/flash/Moxie.swf";
  11. o.Env.xap_url = "../../js/silverlight/Moxie.xap";
  12. module("plupload.Uploader", {
  13. setup: function() {
  14. var options, up;
  15. $('#qunit-fixture').html('<div id="uploader" />');
  16. options = this.options = {
  17. browse_button: 'uploader',
  18. container: 'qunit-fixture',
  19. url: "Plupload/upload.php"
  20. };
  21. up = this.up = new plupload.Uploader(options);
  22. up.bind('PostInit', function() {
  23. QUnit.start();
  24. });
  25. QUnit.stop();
  26. up.init();
  27. },
  28. teardown: function() {
  29. this.up.destroy();
  30. }
  31. });
  32. test("trigger()", function(assert) {
  33. var up = this.up, arg1 = 1, arg2 = { two: 2 };
  34. up.bind('SomeEvent', function(up, one, two) {
  35. ok(up instanceof plupload.Uploader, "First argument is always plupload.Uploader instance.");
  36. deepEqual(one, arg1, "Second argument (number) successfully passed.");
  37. deepEqual(two, arg2, "Thir argument (object) successfully passed.");
  38. });
  39. up.trigger('SomeEvent', arg1, arg2);
  40. });
  41. test("bind() - basic functionality, priority, scope.", function() {
  42. var up = this.up, seq = [];
  43. var someScope = {
  44. prop1: 1,
  45. prop2: 2
  46. };
  47. up.bind('SomeEvent', function() {
  48. seq.push(1);
  49. deepEqual(this, someScope, "Scope successfully altered.");
  50. }, someScope, 5);
  51. up.bind('SomeEvent', function() {
  52. ok(!seq.length, "Handler with higher priority runs first.")
  53. seq.push(2);
  54. }, up, 10);
  55. up.bind('SomeEvent', function() {
  56. ok(this instanceof plupload.Uploader, "By default the scope is set to the object firing the event.");
  57. seq.push(3);
  58. return false;
  59. });
  60. up.bind('SomeEvent', function() {
  61. // this should never run
  62. ok(false, "Consequent event handlers cancelled by returning false.");
  63. seq.push(4);
  64. });
  65. up.bind('TestComplete', function() {
  66. deepEqual(seq, [2,1,3], "All expected event handlers have run and in order specified by priority.");
  67. });
  68. up.trigger('SomeEvent');
  69. up.trigger('TestComplete');
  70. });
  71. test("unbind()", function(assert) {
  72. var up = this.up, seq = [];
  73. function handler1() {
  74. seq.push(1);
  75. }
  76. function handler2() {
  77. seq.push(2);
  78. }
  79. up.bind('SomeEvent', handler1);
  80. up.bind('SomeEvent', handler2);
  81. up.trigger('SomeEvent'); // will populate seq with [1,2]
  82. up.unbind('SomeEvent', handler2);
  83. up.trigger('SomeEvent'); // seq should become [1,2,1]
  84. assert.deepEqual(seq, [1,2,1], "unbind successfull.");
  85. });
  86. test("unbindAll()", function(assert) {
  87. var up = this.up, seq = [];
  88. function handler1() {
  89. seq.push(1);
  90. }
  91. function handler2() {
  92. seq.push(2);
  93. }
  94. up.bind('SomeEvent', handler1);
  95. up.bind('SomeEvent', handler2);
  96. up.trigger('SomeEvent'); // will populate seq with [1,2]
  97. up.unbindAll('SomeEvent');
  98. up.trigger('SomeEvent'); // seq should become [1,2,1]
  99. assert.deepEqual(seq, [1,2], "unbind successfull.");
  100. });
  101. // test upload
  102. </script>
  103. </head>
  104. <body>
  105. <div id="qunit"></div>
  106. <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
  107. </body>
  108. </html>