| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>Plupload: Test Uploader Events</title>
- <script src="../loader.js"></script>
- <script type="text/javascript">
- QUnit.config.reorder = false;
- QUnit.config.testTimeout = 10000;
- o.Env.swf_url = "../../js/flash/Moxie.swf";
- o.Env.xap_url = "../../js/silverlight/Moxie.xap";
- module("plupload.Uploader", {
- setup: function() {
- var options, up;
- $('#qunit-fixture').html('<div id="uploader" />');
- options = this.options = {
- browse_button: 'uploader',
- container: 'qunit-fixture',
- url: "Plupload/upload.php"
- };
- up = this.up = new plupload.Uploader(options);
- up.bind('PostInit', function() {
- QUnit.start();
- });
- QUnit.stop();
- up.init();
- },
- teardown: function() {
- this.up.destroy();
- }
- });
- test("trigger()", function(assert) {
- var up = this.up, arg1 = 1, arg2 = { two: 2 };
- up.bind('SomeEvent', function(up, one, two) {
- ok(up instanceof plupload.Uploader, "First argument is always plupload.Uploader instance.");
- deepEqual(one, arg1, "Second argument (number) successfully passed.");
- deepEqual(two, arg2, "Thir argument (object) successfully passed.");
- });
- up.trigger('SomeEvent', arg1, arg2);
- });
- test("bind() - basic functionality, priority, scope.", function() {
- var up = this.up, seq = [];
- var someScope = {
- prop1: 1,
- prop2: 2
- };
- up.bind('SomeEvent', function() {
- seq.push(1);
- deepEqual(this, someScope, "Scope successfully altered.");
- }, someScope, 5);
- up.bind('SomeEvent', function() {
- ok(!seq.length, "Handler with higher priority runs first.")
- seq.push(2);
- }, up, 10);
- up.bind('SomeEvent', function() {
- ok(this instanceof plupload.Uploader, "By default the scope is set to the object firing the event.");
- seq.push(3);
- return false;
- });
- up.bind('SomeEvent', function() {
- // this should never run
- ok(false, "Consequent event handlers cancelled by returning false.");
- seq.push(4);
- });
- up.bind('TestComplete', function() {
- deepEqual(seq, [2,1,3], "All expected event handlers have run and in order specified by priority.");
- });
- up.trigger('SomeEvent');
- up.trigger('TestComplete');
- });
- test("unbind()", function(assert) {
- var up = this.up, seq = [];
- function handler1() {
- seq.push(1);
- }
- function handler2() {
- seq.push(2);
- }
- up.bind('SomeEvent', handler1);
- up.bind('SomeEvent', handler2);
- up.trigger('SomeEvent'); // will populate seq with [1,2]
- up.unbind('SomeEvent', handler2);
- up.trigger('SomeEvent'); // seq should become [1,2,1]
- assert.deepEqual(seq, [1,2,1], "unbind successfull.");
- });
- test("unbindAll()", function(assert) {
- var up = this.up, seq = [];
- function handler1() {
- seq.push(1);
- }
- function handler2() {
- seq.push(2);
- }
- up.bind('SomeEvent', handler1);
- up.bind('SomeEvent', handler2);
- up.trigger('SomeEvent'); // will populate seq with [1,2]
- up.unbindAll('SomeEvent');
- up.trigger('SomeEvent'); // seq should become [1,2,1]
- assert.deepEqual(seq, [1,2], "unbind successfull.");
- });
- // test upload
- </script>
- </head>
- <body>
- <div id="qunit"></div>
- <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
- </body>
- </html>
|