filelist_selected_file-manual.html (2527B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset='utf-8'> 5 <title>FileAPI Test: filelist_selected_file</title> 6 <link rel='author' title='Intel' href='http://www.intel.com'> 7 <link rel='help' href='http://dev.w3.org/2006/webapi/FileAPI/#filelist-section'> 8 <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-length"> 9 <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-item"> 10 <script src='/resources/testharness.js'></script> 11 <script src='/resources/testharnessreport.js'></script> 12 </head> 13 14 <body> 15 <form name='uploadData'> 16 <input type='file' id='fileChooser'> 17 </form> 18 <div> 19 <p>Test steps:</p> 20 <ol> 21 <li>Download <a href='support/upload.txt'>upload.txt</a> to local.</li> 22 <li>Select the local upload.txt file to run the test.</li> 23 </ol> 24 </div> 25 26 <div id='log'></div> 27 28 <script> 29 var fileInput = document.querySelector('#fileChooser'); 30 var fileList; 31 32 setup({explicit_done: true, explicit_timeout: true}); 33 34 on_event(fileInput, 'change', function(evt) { 35 test(function() { 36 fileList = document.querySelector('#fileChooser').files; 37 assert_equals(fileList.length, 1, 'fileList length is 1'); 38 }, 'Check if the fileList length is 1 when selected one file'); 39 40 test(function() { 41 fileList = document.querySelector('#fileChooser').files; 42 assert_true(fileList.item(0) instanceof File, 'item method is instanceof File'); 43 }, 'Check if the item method returns the File interface when selected one file'); 44 45 test(function() { 46 fileList = document.querySelector('#fileChooser').files; 47 assert_not_equals(fileList.item(0), null, 'item(0) is not null'); 48 }, 'Check if item(0) is not null when selected one file. Index must be treated by user agents as value for the position of a File object in the FileList, with 0 representing the first file.'); 49 50 test(function() { 51 fileList = document.querySelector('#fileChooser').files; 52 assert_equals(fileList.item(1), null, 'item(1) is null'); 53 }, 'Check if item(1) is null when selected one file only'); 54 55 test(function() { 56 fileList = document.querySelector('#fileChooser').files; 57 assert_equals(fileList.item(0).name, 'upload.txt', 'file name string is "upload.txt"'); 58 }, 'Check if the file name string is the selected "upload.txt"'); 59 60 done(); 61 }); 62 </script> 63 </body> 64 </html>