From: <rb...@us...> - 2018-04-02 13:42:24
|
Revision: 15222 http://sourceforge.net/p/htmlunit/code/15222 Author: rbri Date: 2018-04-02 13:42:22 +0000 (Mon, 02 Apr 2018) Log Message: ----------- fix doNotTrack Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -1076,6 +1076,10 @@ @BrowserFeature(IE) JS_MENU_TYPE_EMPTY, + /** Navigator.doNotTrack returns unspecified if not set. */ + @BrowserFeature(FF) + JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED, + /** Indicates if the String representation of a native function is without newline. */ @BrowserFeature({CHROME, EDGE}) JS_NATIVE_FUNCTION_TOSTRING_COMPACT, 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 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; @@ -20,6 +21,7 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE; import com.gargoylesoftware.htmlunit.PluginConfiguration; +import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -300,12 +302,16 @@ * Returns the {@code doNotTrack} property. * @return the {@code doNotTrack} property */ - @JsxGetter(FF) - public String getDoNotTrack() { - if (getWindow().getWebWindow().getWebClient().getOptions().isDoNotTrackEnabled()) { - return "yes"; + @JsxGetter({CHROME, FF}) + public Object getDoNotTrack() { + final WebClient client = getWindow().getWebWindow().getWebClient(); + if (client.getOptions().isDoNotTrackEnabled()) { + return 1; } - return "unspecified"; + if (client.getBrowserVersion().hasFeature(JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED)) { + return "unspecified"; + } + return null; } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -4483,6 +4483,18 @@ setEventHandler("selectstart", selectstart); } + /** + * Returns the {@code doNotTrack} property. + * @return the {@code doNotTrack} property + */ + @JsxGetter(IE) + public Object getDoNotTrack() { + final WebClient client = getWindow().getWebWindow().getWebClient(); + if (client.getOptions().isDoNotTrackEnabled()) { + return 1; + } + return null; + } } class HTMLCollectionFrames extends HTMLCollection { @@ -4545,5 +4557,4 @@ } } } - } 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 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -466,4 +466,27 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"unspecified", "undefined", "undefined"}, + CHROME = {"null", "undefined", "undefined"}, + IE = {"undefined", "undefined", "null"}) + public void doNotTrack() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(navigator.doNotTrack);\n" + + " alert(navigator.msDoNotTrack);\n" + + " alert(window.doNotTrack);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |