From: <rb...@us...> - 2017-09-09 18:31:28
|
Revision: 14819 http://sourceforge.net/p/htmlunit/code/14819 Author: rbri Date: 2017-09-09 18:31:25 +0000 (Sat, 09 Sep 2017) Log Message: ----------- NetworkInformation added Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformation.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/package-info.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2017-09-09 14:52:38 UTC (rev 14818) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -381,6 +381,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.media.rtc.mozRTCSessionDescription; import com.gargoylesoftware.htmlunit.javascript.host.media.rtc.webkitRTCPeerConnection; import com.gargoylesoftware.htmlunit.javascript.host.moz.MozPowerManager; +import com.gargoylesoftware.htmlunit.javascript.host.network.NetworkInformation; import com.gargoylesoftware.htmlunit.javascript.host.payment.PaymentAddress; import com.gargoylesoftware.htmlunit.javascript.host.payment.PaymentRequest; import com.gargoylesoftware.htmlunit.javascript.host.payment.PaymentResponse; @@ -526,7 +527,8 @@ mozRTCPeerConnection.class, mozRTCSessionDescription.class, MozSettingsEvent.class, MSGestureEvent.class, MutationEvent.class, MutationObserver.class, MutationRecord.class, NamedNodeMap.class, Namespace.class, - NamespaceCollection.class, Navigator.class, Node.class, NodeFilter.class, NodeIterator.class, + NamespaceCollection.class, + Navigator.class, NetworkInformation.class, Node.class, NodeFilter.class, NodeIterator.class, NodeList.class, Notification.class, OES_element_index_uint.class, OES_standard_derivatives.class, OES_texture_float.class, OES_texture_float_linear.class, OfflineAudioCompletionEvent.class, OfflineAudioContext.class, Option.class, OscillatorNode.class, PageTransitionEvent.class, PannerNode.class, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java 2017-09-09 14:52:38 UTC (rev 14818) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -26,6 +26,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.host.geo.Geolocation; +import com.gargoylesoftware.htmlunit.javascript.host.network.NetworkInformation; /** * A JavaScript object for {@code Navigator}. @@ -315,4 +316,16 @@ public String getOscpu() { return "Windows NT 6.1"; } + + /** + * Returns the {@code connection} property. + * @return the {@code connection} property + */ + @JsxGetter(CHROME) + public NetworkInformation getConnection() { + final NetworkInformation networkInformation = new NetworkInformation(); + networkInformation.setPrototype(getPrototype(networkInformation.getClass())); + networkInformation.setParentScope(getParentScope()); + return networkInformation; + } } Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformation.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformation.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformation.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2002-2017 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.network; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; + +/** + * A JavaScript object for {@code NetworkInformation}. + * + * @author Ronald Brill + */ +@JsxClass(CHROME) +public class NetworkInformation extends SimpleScriptable { + + /** + * Creates an instance. + */ + @JsxConstructor + public NetworkInformation() { + } + + /** + * @return the {@code downlink} property + */ + @JsxGetter + public double getDownlink() { + return 1.95d; + } + + /** + * @return the {@code effectiveType} property + */ + @JsxGetter + public String getEffectiveType() { + return "4g"; + } + + /** + * @return the {@code rtt} property + */ + @JsxGetter + public int getRtt() { + return 125; + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformation.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/package-info.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/package-info.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/package-info.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2002-2017 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. + */ + +/** + * Implementations of the NetworkInformation JavaScript host objects - users of HtmlUnit shouldn't + * need anything in this package. + */ +package com.gargoylesoftware.htmlunit.javascript.host.network; Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/network/package-info.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-09-09 14:52:38 UTC (rev 14818) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -23,6 +23,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; import com.gargoylesoftware.htmlunit.PluginConfiguration; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -437,4 +438,26 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"undefined", "undefined", "undefined"}, + CHROME = {"[object NetworkInformation]", "undefined", "undefined"}) + public void connection() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(navigator.connection);\n" + + " alert(navigator.mozConnection);\n" + + " alert(navigator.webkitConnection);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformationTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformationTest.java 2017-09-09 18:31:25 UTC (rev 14819) @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2002-2017 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.network; + +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; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link NetworkInformation}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class NetworkInformationTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"undefined", "undefined", "undefined"}, + CHROME = {"[object NetworkInformation]", "undefined", "undefined"}) + public void navigatorConnection() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(navigator.connection);\n" + + " alert(navigator.mozConnection);\n" + + " alert(navigator.webkitConnection);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "no connection", + CHROME = "undefined") + public void type() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;\n" + + " if (connection) {" + + " alert(connection.type);\n" + + " } else {\n" + + " alert('no connection');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "no connection", + CHROME = "undefined") + public void downlinkMax() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;\n" + + " if (connection) {" + + " alert(connection.downlinkMax);\n" + + " } else {\n" + + " alert('no connection');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "no connection", + CHROME = "4g") + public void effectiveType() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;\n" + + " if (connection) {" + + " alert(connection.effectiveType);\n" + + " } else {\n" + + " alert('no connection');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "no connection", + CHROME = "1.95") + public void downlink() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;\n" + + " if (connection) {" + + " alert(connection.downlink);\n" + + " } else {\n" + + " alert('no connection');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "no connection", + CHROME = "125") + public void rtt() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;\n" + + " if (connection) {" + + " alert(connection.rtt);\n" + + " } else {\n" + + " alert('no connection');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/network/NetworkInformationTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |