| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>Plupload: Test Uploader Initialization</title>
- <script src="../loader.js"></script>
- <script type="text/javascript">
- QUnit.config.reorder = false;
- QUnit.config.autostart = false;
- QUnit.config.testTimeout = 10000;
- FileHash.init({
- files: ['files/01.min.js', 'files/02.min.js'],
- onready: function() {
- QUnit.start();
- }
- });
- o.Env.swf_url = "../../js/Moxie.swf";
- o.Env.xap_url = "../../js/Moxie.xap";
- module("plupload.Uploader", {
- setup: function() {
- $('#qunit-fixture').html('<div id="uploader" />');
- this.options = {
- browse_button: 'uploader',
- drop_element: 'uploader',
- container: 'qunit-fixture',
- url: "Plupload/upload.php"
- };
- this.up = null;
- },
- teardown: function() {
- if (this.up) {
- this.up.destroy();
- }
- }
- });
- // test required options
- test("'url' is not a required option anymore so uploader shouldn't trigger plupload.INIT_ERROR", function() {
- expect(1);
- delete this.options['url'];
- this.up = new plupload.Uploader(this.options);
- this.up.bind("Init", function() {
- start();
- ok(true, "'url' option is not required.");
- });
- this.up.bind("Error", function(up, err) {
- start();
- ok(false, "'url' option is not required.");
- });
- stop();
- this.up.init();
- });
- test("If both 'browse_button' and 'drop_element' are missing, uploader should trigger plupload.INIT_ERROR", function() {
- expect(1);
- delete this.options['browse_button'];
- delete this.options['drop_element'];
- this.up = new plupload.Uploader(this.options);
- this.up.bind("Init", function() {
- start();
- ok(false,
- "One must specify either 'browse_button' or 'drop_element'.");
- });
- this.up.bind("Error", function(up, err) {
- start();
- equal(err.code, plupload.INIT_ERROR,
- "One must specify either 'browse_button' or 'drop_element'.");
- });
- stop();
- this.up.init();
- });
- // test normalized options after instantiation
- test("Normalize required_features when passed as comma-delimited string", function() {
- expect(1);
- this.up = new plupload.Uploader(o.extend(this.options, {
- required_features: 'chunks,jpgresize, progress,dragdrop,multi_selection,triggerDialog,display_media'
- }));
- deepEqual(this.up.settings.required_features, {
- slice_blob: true,
- send_binary_string: true,
- report_upload_progress: true,
- select_multiple: true,
- summon_file_dialog: true,
- drag_and_drop: true,
- display_media: true
- }, "required_features properly normalized and translated to caps.");
- });
- test("Normalize required_features when passed as object", function() {
- expect(1);
- this.up = new plupload.Uploader(o.extend(this.options, {
- required_features: {
- chunks: true,
- jpgresize: true,
- progress: true,
- dragdrop: true,
- multi_selection: true,
- triggerDialog: true,
- display_media: true
- }
- }));
- deepEqual(this.up.settings.required_features, {
- slice_blob: true,
- send_binary_string: true,
- report_upload_progress: true,
- select_multiple: true,
- summon_file_dialog: true,
- drag_and_drop: true,
- display_media: true
- }, "required_features properly normalized and translated to caps.");
- });
- test("Consider special settings as required_features when required_features is boolean true", function() {
- this.up = new plupload.Uploader(o.extend(this.options, {
- multi_selection: true,
- drop_element: 'uploader',
- multipart: false,
- chunk_size: '1mb',
- max_file_size: '1gb',
- resize: {
- width: 100,
- height: 60
- },
- headers: {
- 'X-Test': 1
- },
- required_features: true
- }));
- deepEqual(this.up.settings.required_features, {
- select_multiple: true,
- drag_and_drop: true,
- slice_blob: true,
- send_binary_string: true,
- send_custom_headers: true,
- use_http_method: "POST"
- }, "required_features properly normalized and translated to caps.");
- });
- test("When required_features is undefined, consider special settings as optional", function() {
- this.up = new plupload.Uploader(o.extend(this.options, {
- multi_selection: true,
- drop_element: 'uploader',
- max_file_size: '1gb',
- resize: {
- width: 100,
- height: 60
- },
- headers: {
- 'X-Test': 1
- }
- }));
- deepEqual(this.up.settings.required_features, {}, "required_features must be empty.");
- });
- test("Size identifiers in string format (e.g. 1mb) converted to numerical format", function() {
- this.up = new plupload.Uploader(o.extend(this.options, {
- chunk_size: '1mb',
- max_file_size: '1gb'
- }));
- equal(this.up.settings.chunk_size, 1024 * 1024, "'1mb' converted to numerical bytes");
- });
- test("Test how default values are assigned to missing options", function() {
- this.up = new plupload.Uploader(this.options);
- deepEqual(this.up.settings, {
- browse_button: plupload.getAll('uploader'),
- drop_element: plupload.getAll('uploader'),
- container: plupload.get('qunit-fixture'),
- url: "Plupload/upload.php",
- runtimes: o.Runtime.order,
- http_method: "POST",
- max_retries: 0,
- multipart : true,
- send_file_name : true,
- multi_selection : true,
- file_data_name : 'file',
- flash_swf_url : 'js/Moxie.swf',
- silverlight_xap_url : 'js/Moxie.xap',
- filters : {
- prevent_duplicates: false,
- prevent_empty: true,
- max_file_size: 0,
- mime_types: []
- },
- resize: false,
- chunk_size: 0,
- required_features: {},
- send_chunk_number: true
- }, "Proper defaults set.");
- });
- test("Test how defaults are set for resize object", function() {
- this.up = new plupload.Uploader(o.extend(this.options, {
- resize: {
- width: 100,
- height: 60
- }
- }));
- deepEqual(this.up.settings.resize, {
- width: 100,
- height: 60,
- crop: false,
- preserve_headers: true
- }, "Proper defaults set for resize property.");
- });
- // test init event with restored runtime specifier
- test("Test runtime property", function() {
- expect(2);
- this.up = new plupload.Uploader(o.extend(this.options, {
- runtimes: 'html4,test',
- required_features: 'multi_selection'
- }));
- this.up.bind('Init', function(up, info) {
- equal(info.runtime, 'test', "Test second argument for Init handler.");
- equal(up.runtime, 'test', "Test uploader's 'runtime' property.");
- });
- this.up.bind('PostInit', function() {
- start();
- });
- stop();
- this.up.init();
- });
- // test preinit and init
- test("Test preinit and init callbacks", function() {
- var eventOrder = [];
- this.up = new plupload.Uploader(o.extend(this.options, {
- preinit: function() {
- eventOrder.push(1);
- },
- init: function() {
- start();
- eventOrder.push(2);
- }
- }));
- this.up.bind('Init', function() {
- eventOrder.push(3);
- deepEqual(eventOrder, [1, 2, 3], "preinit callback runs first, then init callback and finally Init handler.");
- });
- stop();
- this.up.init();
- });
- test("Test preinit and init set of event handlers", function() {
- var eventOrder = [];
- this.up = new plupload.Uploader(o.extend(this.options, {
- preinit: {
- PostInit: function() {
- eventOrder.push(1);
- }
- },
- init: {
- PostInit: function() {
- eventOrder.push(2);
- start();
- deepEqual(eventOrder, [1, 2], "preinit handlers run first and and then init handlers.");
- }
- }
- }));
- stop();
- this.up.init();
- });
- module("up.features must be set for backward compatibility", {
- setup: function() {
- $('#qunit-fixture').html('<div id="uploader" />');
- this.options = {
- runtimes: 'test',
- browse_button: 'uploader',
- drop_element: 'uploader',
- container: 'qunit-fixture',
- url: "Plupload/upload.php",
- init: {
- Error: function(up) {
- start();
- ok(false, "Runtime failed to initialise.");
- }
- }
- };
- this.up = null;
- },
- teardown: function() {
- if (this.up) {
- this.up.destroy();
- }
- }
- });
- test("with 'drop_element' only", function() {
- delete this.options.browse_button;
- var up = new plupload.Uploader(this.options);
- up.bind('PostInit', function(up) {
- start();
- deepEqual(up.features, {
- dragdrop: true,
- chunks: true,
- multipart: true
- },
- "up.features properly set for backward compatibility."
- );
- });
- stop();
- up.init();
- });
- test("with 'browse_button' only", function() {
- delete this.options.drop_element;
- var up = new plupload.Uploader(this.options);
- up.bind('PostInit', function(up) {
- start();
- deepEqual(up.features, {
- multi_selection: true,
- chunks: true,
- multipart: true
- },
- "up.features properly set for backward compatibility."
- );
- });
- stop();
- up.init();
- });
- test("with both", function() {
- var up = new plupload.Uploader(this.options);
- up.bind('PostInit', function(up) {
- start();
- deepEqual(up.features, {
- dragdrop: true,
- chunks: true,
- multipart: true,
- multi_selection: true
- },
- "up.features properly set for backward compatibility."
- );
- });
- stop();
- up.init();
- });
- </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>
|