List of usage examples for android.webkit WebView copyBackForwardList
public WebBackForwardList copyBackForwardList()
From source file:android.webkit.cts.WebViewTest.java
@UiThreadTest public void testSaveAndRestoreState() throws Throwable { if (!NullWebViewUtils.isWebViewAvailable()) { return;/*from w ww .java 2 s. c o m*/ } // nothing to save assertNull(mWebView.saveState(new Bundle())); startWebServer(false); String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1); String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2); String url3 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL3); // make a history list mOnUiThread.loadUrlAndWaitForCompletion(url1); pollingCheckWebBackForwardList(url1, 0, 1); mOnUiThread.loadUrlAndWaitForCompletion(url2); pollingCheckWebBackForwardList(url2, 1, 2); mOnUiThread.loadUrlAndWaitForCompletion(url3); pollingCheckWebBackForwardList(url3, 2, 3); // save the list Bundle bundle = new Bundle(); WebBackForwardList saveList = mWebView.saveState(bundle); assertNotNull(saveList); assertEquals(3, saveList.getSize()); assertEquals(2, saveList.getCurrentIndex()); assertEquals(url1, saveList.getItemAtIndex(0).getUrl()); assertEquals(url2, saveList.getItemAtIndex(1).getUrl()); assertEquals(url3, saveList.getItemAtIndex(2).getUrl()); // change the content to a new "blank" web view without history final WebView newWebView = new WebView(getActivity()); WebBackForwardList copyListBeforeRestore = newWebView.copyBackForwardList(); assertNotNull(copyListBeforeRestore); assertEquals(0, copyListBeforeRestore.getSize()); // restore the list final WebBackForwardList restoreList = newWebView.restoreState(bundle); assertNotNull(restoreList); assertEquals(3, restoreList.getSize()); assertEquals(2, saveList.getCurrentIndex()); // wait for the list items to get inflated new PollingCheck(TEST_TIMEOUT) { @Override protected boolean check() { return restoreList.getItemAtIndex(0).getUrl() != null && restoreList.getItemAtIndex(1).getUrl() != null && restoreList.getItemAtIndex(2).getUrl() != null; } }.run(); assertEquals(url1, restoreList.getItemAtIndex(0).getUrl()); assertEquals(url2, restoreList.getItemAtIndex(1).getUrl()); assertEquals(url3, restoreList.getItemAtIndex(2).getUrl()); WebBackForwardList copyListAfterRestore = newWebView.copyBackForwardList(); assertNotNull(copyListAfterRestore); assertEquals(3, copyListAfterRestore.getSize()); assertEquals(2, copyListAfterRestore.getCurrentIndex()); assertEquals(url1, copyListAfterRestore.getItemAtIndex(0).getUrl()); assertEquals(url2, copyListAfterRestore.getItemAtIndex(1).getUrl()); assertEquals(url3, copyListAfterRestore.getItemAtIndex(2).getUrl()); }