From: <rb...@us...> - 2017-08-10 19:01:01
|
Revision: 14781 http://sourceforge.net/p/htmlunit/code/14781 Author: rbri Date: 2017-08-10 19:00:58 +0000 (Thu, 10 Aug 2017) Log Message: ----------- minor start of file reader impl Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-10 18:16:25 UTC (rev 14780) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-10 19:00:58 UTC (rev 14781) @@ -17,12 +17,18 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; +import net.sourceforge.htmlunit.corejs.javascript.Function; + /** * A JavaScript object for {@code FileReader}. * * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass public class FileReader extends EventTarget { @@ -39,11 +45,66 @@ @JsxConstant public static final short DONE = 2; + private int readyState_; + /** * Creates an instance. */ @JsxConstructor public FileReader() { + readyState_ = EMPTY; } + /** + * Returns the {@code onload} event handler for this element. + * @return the {@code onload} event handler for this element + */ + @JsxGetter + public int getReadyState() { + return readyState_; + } + + /** + * Returns the {@code onload} event handler for this element. + * @return the {@code onload} event handler for this element + */ + @JsxGetter + public Function getOnload() { + return getEventHandler("load"); + } + + /** + * Sets the {@code onload} event handler for this element. + * @param onload the {@code onload} event handler for this element + */ + @JsxSetter + public void setOnload(final Object onload) { + setEventHandler("load", onload); + } + + /** + * Returns the {@code onerror} event handler for this element. + * @return the {@code onerror} event handler for this element + */ + @JsxGetter + public Function getOnerror() { + return getEventHandler("error"); + } + + /** + * Sets the {@code onerror} event handler for this element. + * @param onerror the {@code onerror} event handler for this element + */ + @JsxSetter + public void setOnerror(final Object onerror) { + setEventHandler("error", onerror); + } + + /** + * Function readAsDataURL. + * @param file the file + */ + @JsxFunction + public void readAsDataURL(final File file) { + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-10 18:16:25 UTC (rev 14780) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-10 19:00:58 UTC (rev 14781) @@ -24,9 +24,9 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; /** @@ -41,8 +41,34 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "data:;base64,SHRtbFVuaXQ=", - FF = "data:application/octet-stream;base64,SHRtbFVuaXQ=") + @Alerts("0") + public void ctorReadyState() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var reader = new FileReader();\n" + + " alert(reader.readyState);\n" + + " }\n" + + " </script>\n" + + "<head>\n" + + "<body>\n" + + " <button id='testBtn' onclick='test()'>Tester</button>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("testBtn")).click(); + verifyAlerts(driver, getExpectedAlerts()); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("data:text/plain;base64,SHRtbFVuaXQ=") @NotYetImplemented public void readAsDataURL() throws Exception { final String html @@ -51,12 +77,12 @@ + "<head>\n" + " <script>\n" + " function test() {\n" + + " var files = document.testForm.fileupload.files;\n" + " var reader = new FileReader();\n" + " reader.onload = function() {\n" + " var dataURL = reader.result;\n" + " alert(dataURL);\n" + " };\n" - + " var files = document.testForm.fileupload.files;\n" + " reader.readAsDataURL(files[0]);\n" + " }\n" + " </script>\n" |