From: <rb...@us...> - 2013-10-23 20:48:21
|
Revision: 8678 http://sourceforge.net/p/htmlunit/code/8678 Author: rbri Date: 2013-10-23 20:48:17 +0000 (Wed, 23 Oct 2013) Log Message: ----------- setting frame.location does not send Referer Header Issue 1551 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-23 19:18:33 UTC (rev 8677) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-23 20:48:17 UTC (rev 8678) @@ -8,6 +8,9 @@ <body> <release version="2.14" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1551"> + JavaScript: send the correct Referer header when changing the location property. + </action> <action type="fix" dev="asashour"> SSL: use default algorithm for fetching the KeyManagerFactory. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2013-10-23 19:18:33 UTC (rev 8677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2013-10-23 20:48:17 UTC (rev 8678) @@ -222,8 +222,11 @@ } } + final WebRequest request = new WebRequest(url); + request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); + final WebWindow webWindow = getWindow().getWebWindow(); - webWindow.getWebClient().download(webWindow, "", new WebRequest(url), + webWindow.getWebClient().download(webWindow, "", request, newLocation.endsWith("#"), "JS set location"); } catch (final MalformedURLException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2013-10-23 19:18:33 UTC (rev 8677) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2013-10-23 20:48:17 UTC (rev 8678) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE10; import java.net.URL; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,6 +29,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -576,4 +578,48 @@ shutDownAll(); } } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("§§URL§§menu.html") + public void missingRefererHeaderWhenSettingFrameLocation() throws Exception { + final String html = "<html><head><title>Frameset</title></head>\n" + + "<frameset rows='20%,80%'>\n" + + " <frame src='menu.html' name='menu'>\n" + + " <frame src='' name='content'>\n" + + "</frameset></html>"; + + final String menu = "<html><head><title>Menu</title></head>\n" + + "<body>\n" + + " <a id='link' href='content.html' target='content'>Link</a>" + + " <a id='jsLink' href='#' onclick=\"javascript:top.content.location='content.html';\">jsLink</a>\n" + + "</body></html>"; + + final String content = "<html><head><title>Content</title></head><body><p>content</p></body></html>"; + + final MockWebConnection conn = getMockWebConnection(); + conn.setResponse(new URL(getDefaultUrl(), "menu.html"), menu); + conn.setResponse(new URL(getDefaultUrl(), "content.html"), content); + conn.setResponse(new URL(getDefaultUrl(), "content.html"), content); + + expandExpectedAlertsVariables(getDefaultUrl()); + final WebDriver driver = loadPage2(html); + + assertEquals(2, conn.getRequestCount()); + + // click an anchor with href and target + driver.switchTo().frame(0); + driver.findElement(By.id("link")).click(); + assertEquals(3, conn.getRequestCount()); + Map<String, String> lastAdditionalHeaders = conn.getLastAdditionalHeaders(); + assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get("Referer")); + + // click an anchor with onclick which sets frame.location + driver.findElement(By.id("jsLink")).click(); + assertEquals(4, conn.getRequestCount()); + lastAdditionalHeaders = conn.getLastAdditionalHeaders(); + assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get("Referer")); + } } |