< prev index next >

modules/javafx.web/src/test/java/test/javafx/scene/web/HistoryTest.java

Print this page

        

*** 23,37 **** --- 23,41 ---- * questions. */ package test.javafx.scene.web; + import static javafx.concurrent.Worker.State.SUCCEEDED; + import java.util.concurrent.atomic.AtomicBoolean; + import java.util.concurrent.CountDownLatch; import java.util.List; import java.io.File; import java.net.MalformedURLException; import javafx.beans.value.ObservableValue; + import javafx.scene.web.WebEngine; import javafx.scene.web.WebHistory; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; import java.util.Date;
*** 39,48 **** --- 43,53 ---- import java.util.concurrent.Callable; import javafx.scene.web.WebHistory; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; + import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class HistoryTest extends TestBase { WebHistory history = getEngine().getHistory();
*** 256,265 **** --- 261,338 ---- fail("maxSizeProperty: IllegalArgumentException is not thrown"); } catch (IllegalArgumentException ex) {} }); } + /** + * @test + * @bug 8157686 + * Summary : Html history.pushState, history.back and history.replace + * Ref : https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate + */ + @Test(timeout = 30000) public void historyOnPopStateTest() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + final String page0 = "archive-root0.html"; + final String page1 = "archive-root1.html"; + final String page2 = "archive-root2.html"; + final String page3 = "longselectorlist.html"; + + submit(() -> { + WebEngine webEngine = new WebEngine(); + ClassLoader loader = LoadTest.class.getClassLoader(); + + webEngine.locationProperty().addListener((observable, oldValue, newValue) -> { + if (oldValue == null) { + return; + } + + if (oldValue.substring(oldValue.lastIndexOf('?') + 1).equalsIgnoreCase(page3) && + newValue.substring(newValue.lastIndexOf('?') + 1).equalsIgnoreCase(page1)) { + webEngine.executeScript("history.back();"); + } else if (oldValue.substring(oldValue.lastIndexOf('?') + 1).equalsIgnoreCase(page1) && + newValue.substring(newValue.lastIndexOf('/') + 1).equalsIgnoreCase(page0)) { + assertNull("history.state should be null ", webEngine.executeScript("history.state")); + webEngine.executeScript("history.go(2);"); + } else if(oldValue.substring(oldValue.lastIndexOf('/') + 1).equalsIgnoreCase(page0) && + newValue.substring(newValue.lastIndexOf('?') + 1).equalsIgnoreCase(page3)) { + latch.countDown(); + } + }); + + webEngine.getLoadWorker().stateProperty().addListener(((observable, oldValue, newValue) -> { + if (newValue == SUCCEEDED) { + webEngine.executeScript("history.pushState({page: 1}, 'title 1', '?" + page1 + "');"); + assertEquals("history.pushState Failed", + page1, + webEngine.getLocation().substring(webEngine.getLocation().lastIndexOf('?') + 1) + ); + + webEngine.executeScript("history.pushState({page: 2}, 'title 2', '?" + page2 + "');"); + assertEquals("history.pushState Failed", + page2, + webEngine.getLocation().substring(webEngine.getLocation().lastIndexOf('?') + 1) + ); + + webEngine.executeScript("history.replaceState({page: 3}, 'title 3', '?" + page3 + "');"); + assertEquals("history.pushState Failed", + page3, + webEngine.getLocation().substring(webEngine.getLocation().lastIndexOf('?') + 1) + ); + + webEngine.executeScript("history.back();"); + } + })); + + webEngine.load(loader.getResource("test/html/archive-root0.html").toExternalForm()); + }); + try { + latch.await(); + } catch (InterruptedException ex) { + throw new AssertionError(ex); + } + } + void checkLoad(File file, int size, int index, String title) { load(file); check(file, size, index, title); }
< prev index next >