Example usage for android.webkit WebBackForwardList getSize

List of usage examples for android.webkit WebBackForwardList getSize

Introduction

In this page you can find the example usage for android.webkit WebBackForwardList getSize.

Prototype

public abstract int getSize();

Source Link

Document

Get the total size of the back/forward list.

Usage

From source file:org.apache.cordova.AndroidWebView.java

public void printBackForwardList() {
    WebBackForwardList currentList = this.copyBackForwardList();
    int currentSize = currentList.getSize();
    for (int i = 0; i < currentSize; ++i) {
        WebHistoryItem item = currentList.getItemAtIndex(i);
        String url = item.getUrl();
        LOG.d(TAG, "The URL at index: " + Integer.toString(i) + " is " + url);
    }//from  ww  w.j  a  va  2  s .  co m
}

From source file:android.webkit.cts.WebViewTest.java

private boolean checkWebBackForwardList(WebBackForwardList list, String currUrl, int currIndex, int size) {
    return (list != null) && (list.getSize() == size) && (list.getCurrentIndex() == currIndex)
            && list.getItemAtIndex(currIndex).getUrl().equals(currUrl);
}

From source file:android.webkit.cts.WebViewTest.java

@UiThreadTest
public void testSaveAndRestoreState() throws Throwable {
    if (!NullWebViewUtils.isWebViewAvailable()) {
        return;/* w  w  w . ja  v a  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());
}