Example usage for android.app Instrumentation invokeContextMenuAction

List of usage examples for android.app Instrumentation invokeContextMenuAction

Introduction

In this page you can find the example usage for android.app Instrumentation invokeContextMenuAction.

Prototype

public boolean invokeContextMenuAction(Activity targetActivity, int id, int flag) 

Source Link

Document

Show the context menu for the currently focused view and executes a particular context menu item.

Usage

From source file:org.barbon.mangaget.MainTest.java

public void testRemoveManga() {
    Instrumentation instr = getInstrumentation();

    UiUtils.selectListAndMoveToTop(mangaList.getListView());
    UiUtils.moveDown();/*from  www  .  ja v  a 2s .  com*/
    UiUtils.selectCurrent();

    // sanity check
    assertEquals(2, mangaList.getListView().getCount());

    assertTrue(instr.invokeContextMenuAction(activity, R.id.delete, 0));

    // click on confirmation dialog
    for (;;) {
        if (UiUtils.clickAlertDialog(DeleteConfirmationDialog.find(mangaList), DialogInterface.BUTTON_POSITIVE))
            break;

        UiUtils.sleep(500);
    }

    DB db = DB.getInstance(null);

    // wait until refresh completes
    for (;;) {
        Cursor cursor = db.getSubscribedMangaList();
        int count = cursor.getCount();

        cursor.close();

        if (count == 1)
            break;

        UiUtils.sleep(500);
    }

    UiUtils.waitForIdle(2000);

    // check chapter list has been refreshed
    assertEquals(1, mangaList.getListView().getCount());
}

From source file:org.barbon.mangaget.SearchTest.java

public void testMangaAdd() {
    Instrumentation instr = getInstrumentation();

    setActivityIntent(searchIntent(""));
    setActivity(UiUtils.forceHorizontal(getActivity()));
    refreshMembers();/*from w  w  w  .  ja  v  a2 s . c  om*/
    ListView resultList = results.getListView();

    while (resultList.getCount() == 0)
        UiUtils.sleep(500);

    assertEquals(49, resultList.getCount());

    UiUtils.selectListAndMoveToTop(resultList);
    UiUtils.moveDown();
    UiUtils.selectCurrent();

    int prev_count = mangaCount();

    instr.invokeContextMenuAction(activity, R.id.add_manga, 0);

    while (mangaCount() == prev_count)
        UiUtils.sleep(500);

    assertEquals(prev_count + 1, mangaCount());
}