--- old/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java 2018-06-27 16:32:40.741397208 +0530 +++ new/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java 2018-06-27 16:32:40.519413003 +0530 @@ -1361,7 +1361,8 @@ break; case PAGE_REPLACED: message.set("Replaced " + url); - updateLocation(url); + // Update only the location, don't change title or document. + WebEngine.this.location.set(url); break; case PAGE_FINISHED: message.set("Loading complete"); --- old/modules/javafx.web/src/test/java/test/javafx/scene/web/HistoryStateTest.java 2018-06-27 16:32:41.224026725 +0530 +++ new/modules/javafx.web/src/test/java/test/javafx/scene/web/HistoryStateTest.java 2018-06-27 16:32:40.993498189 +0530 @@ -31,6 +31,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import javafx.collections.ObservableList; +import javafx.scene.web.WebHistory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -161,5 +163,37 @@ assertEquals("history navigation using javascript failed", 2, historyListenerIndex.get()); } } + + // JDK-8204856 + @Test + public void testDocumentExistenceAfterPushState() { + final ObservableList history = getEngine().getHistory().getEntries(); + final int initialHistorySize = history.size(); + + load(HistoryStateTest.class.getClassLoader().getResource( + resourcePath + initialLoadUrl).toExternalForm()); + assertNotNull(getEngine().getDocument()); + + executeScript("history.pushState('push', 'title', 'pushState.html')"); + assertNotNull("Document shouldn't be null after history.pushState", getEngine().getDocument()); + assertTrue("location must end with pushState.html", getEngine().getLocation().endsWith("pushState.html")); + assertEquals("history count should be incremented", initialHistorySize + 1, history.size()); + } + + // JDK-8204856 + @Test + public void testDocumentExistenceAfterReplaceState() { + final ObservableList history = getEngine().getHistory().getEntries(); + final int initialHistorySize = history.size(); + + load(HistoryStateTest.class.getClassLoader().getResource( + resourcePath + initialLoadUrl).toExternalForm()); + assertNotNull(getEngine().getDocument()); + + executeScript("history.replaceState('push', 'title', 'replaceState.html')"); + assertNotNull("Document shouldn't be null after history.replaceState", getEngine().getDocument()); + assertTrue("location must end with replaceState.html", getEngine().getLocation().endsWith("replaceState.html")); + assertEquals("history count shouldn't be incremented", initialHistorySize, history.size()); + } }