11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset=utf-8> 31cb0ef41Sopenharmony_ci<title>Process Events for FileReader</title> 41cb0ef41Sopenharmony_ci<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#event-handler-attributes-section"> 51cb0ef41Sopenharmony_ci<link rel=author title="Jinks Zhao" href="mailto:jinks@maxthon.com"> 61cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 71cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 81cb0ef41Sopenharmony_ciPlease choose one file through this input below.<br> 91cb0ef41Sopenharmony_ci<input type="file" id="filer"> 101cb0ef41Sopenharmony_ci<div id="log"></div> 111cb0ef41Sopenharmony_ci<script> 121cb0ef41Sopenharmony_civar input, reader, progressEventCounter, progressEventTimeList, 131cb0ef41Sopenharmony_ci lastProgressEventTime; 141cb0ef41Sopenharmony_cisetup(function() { 151cb0ef41Sopenharmony_ci input = document.getElementById('filer'); 161cb0ef41Sopenharmony_ci reader = new FileReader(); 171cb0ef41Sopenharmony_ci progressEventCounter = 0; 181cb0ef41Sopenharmony_ci progressEventTimeList = []; 191cb0ef41Sopenharmony_ci lastProgressEventTime; 201cb0ef41Sopenharmony_ci}, { explicit_timeout: true }); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_civar t = async_test("FileReader progress events.") 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_cireader.onprogress = t.step_func(function () { 251cb0ef41Sopenharmony_ci var newTime = new Date; 261cb0ef41Sopenharmony_ci var timeout = newTime - lastProgressEventTime; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci progressEventTimeList.push(timeout); 291cb0ef41Sopenharmony_ci lastProgressEventTime = newTime; 301cb0ef41Sopenharmony_ci progressEventCounter++; 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci assert_less_than_equal(timeout, 50, "The progress event should be fired every 50ms."); 331cb0ef41Sopenharmony_ci}); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cireader.onload = t.step_func_done(function () { 361cb0ef41Sopenharmony_ci assert_greater_than_equal(progressEventCounter, 1, 371cb0ef41Sopenharmony_ci "When read completely, the progress event must be fired at least once.") 381cb0ef41Sopenharmony_ci}); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciinput.onchange = t.step_func(function () { 411cb0ef41Sopenharmony_ci var files = input.files; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci assert_greater_than(files.length, 0); 441cb0ef41Sopenharmony_ci var file = files[0]; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci lastProgressEventTime = new Date; 471cb0ef41Sopenharmony_ci reader.readAsArrayBuffer(file); 481cb0ef41Sopenharmony_ci}); 491cb0ef41Sopenharmony_ci</script> 50