From: <rb...@us...> - 2018-05-14 14:27:47
|
Revision: 15261 http://sourceforge.net/p/htmlunit/code/15261 Author: rbri Date: 2018-05-14 14:27:42 +0000 (Mon, 14 May 2018) Log Message: ----------- document.fonts added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSetTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-05-14 13:40:24 UTC (rev 15260) +++ trunk/htmlunit/src/changes/changes.xml 2018-05-14 14:27:42 UTC (rev 15261) @@ -8,6 +8,9 @@ <body> <release version="2.31" date="xx, 2018" description="Bugfixes, FIREFOX_45 is deprecated, special GAE handlings removed"> + <action type="add" dev="rbri"> + document.fonts added. + </action> <action type="update" dev="rbri"> BrowserVersion: deprecate FIREFOX_45. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSet.java 2018-05-14 13:40:24 UTC (rev 15260) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSet.java 2018-05-14 14:27:42 UTC (rev 15261) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -24,7 +25,9 @@ * A JavaScript object for {@code FontFaceSet}. * * @author Ahmed Ashour + * @author Ronald Brill */ +@JsxClass(isJSObject = false, value = CHROME) @JsxClass(FF) public class FontFaceSet extends EventTarget { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-05-14 13:40:24 UTC (rev 15260) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-05-14 14:27:42 UTC (rev 15261) @@ -104,6 +104,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.host.Element; +import com.gargoylesoftware.htmlunit.javascript.host.FontFaceSet; import com.gargoylesoftware.htmlunit.javascript.host.Location; import com.gargoylesoftware.htmlunit.javascript.host.NativeFunctionPrefixResolver; import com.gargoylesoftware.htmlunit.javascript.host.Window; @@ -230,6 +231,7 @@ private String domain_; private String lastModified_; private ScriptableObject currentScript_; + private transient FontFaceSet fonts_; private transient StyleSheetList styleSheetList_; static { @@ -4291,4 +4293,18 @@ public void setCurrentScript(final ScriptableObject script) { currentScript_ = script; } + + /** + * @return the {@code FontFaceSet} + */ + @JsxGetter({CHROME, FF}) + public ScriptableObject getFonts() { + if (fonts_ == null) { + final FontFaceSet fonts = new FontFaceSet(); + fonts.setParentScope(getWindow()); + fonts.setPrototype(getPrototype(fonts.getClass())); + fonts_ = fonts; + } + return fonts_; + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSetTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSetTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSetTest.java 2018-05-14 14:27:42 UTC (rev 15261) @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link FontFaceSet}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class FontFaceSetTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "undefined", + FF = "function FontFaceSet() {\n [native code]\n}") + public void window() throws Exception { + final String html + = "<html>\n" + + "<body>\n" + + "<script>\n" + + " alert(window.FontFaceSet);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object FontFaceSet]", + IE = "undefined") + public void documentFonts() throws Exception { + final String html + = "<html>\n" + + "<body>\n" + + "<script>\n" + + " alert(document.fonts);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceSetTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceTest.java 2018-05-14 14:27:42 UTC (rev 15261) @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link FontFace}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class FontFaceTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "function FontFace() {\n [native code]\n}", + CHROME = "function FontFace() { [native code] }", + IE = "undefined") + public void window() throws Exception { + final String html + = "<html>\n" + + "<body>\n" + + "<script>\n" + + " alert(window.FontFace);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/FontFaceTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |