public void testRemoveOnGlobalFocusChangeListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    final ListView lv1 = (ListView) mActivity.findViewById(R.id.listview1);
    final ListView lv2 = (ListView) mActivity.findViewById(R.id.listview2);

    mViewTreeObserver = layout.getViewTreeObserver();
    MockOnGlobalFocusChangeListener listener = new MockOnGlobalFocusChangeListener();
    mViewTreeObserver.addOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertTrue(listener.hasCalledOnGlobalFocusChanged());

    listener.reset();
    mViewTreeObserver.removeOnGlobalFocusChangeListener(listener);
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            layout.requestChildFocus(lv1, lv2);
          }
        });
    mInstrumentation.waitForIdleSync();
    assertFalse(listener.hasCalledOnGlobalFocusChanged());
  }
  public void testRemoveOnTouchModeChangeListener() {
    final Button b = (Button) mActivity.findViewById(R.id.button1);
    // let the button be touch mode.
    TouchUtils.tapView(this, b);

    mViewTreeObserver = b.getViewTreeObserver();

    MockOnTouchModeChangeListener listener = new MockOnTouchModeChangeListener();
    mViewTreeObserver.addOnTouchModeChangeListener(listener);
    assertFalse(listener.hasCalledOnTouchModeChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            b.requestFocusFromTouch();
          }
        });
    mInstrumentation.waitForIdleSync();

    assertTrue(listener.hasCalledOnTouchModeChanged());

    listener = new MockOnTouchModeChangeListener();
    assertFalse(listener.hasCalledOnTouchModeChanged());
    mInstrumentation.runOnMainSync(
        new Runnable() {
          @Override
          public void run() {
            b.requestFocusFromTouch();
          }
        });
    mInstrumentation.waitForIdleSync();

    assertFalse(listener.hasCalledOnTouchModeChanged());
  }
  public void testDowngrade() {

    for (final View caseView : mCaseListIndexView) {
      if (((TextView) caseView).getText().toString().equals("TC_Downgrade")) {
        Log.e(TAG, "TC_Downgrade find");

        final TextView inputView = (TextView) caseView;
        mInstrumentation.runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                inputView.requestFocus();
                inputView.performClick();
              }
            });

        sleep(2000);

        setActivity(WXPageActivity.wxPageActivityInstance);
        Activity activity2 = getActivity();

        ViewGroup myGroup = (ViewGroup) (activity2.findViewById(R.id.container));
        ArrayList<View> inputListView = new ArrayList<View>();
        myGroup.findViewsWithText(
            inputListView, "TC_Downgrade_osV_True", View.FIND_VIEWS_WITH_TEXT);

        Log.e(TAG, "TC_Downgrade_osV_True== " + inputListView.size());

        if (inputListView.size() != 0) {
          final TextView inputTypeView = (TextView) inputListView.get(0);

          mInstrumentation.runOnMainSync(
              new Runnable() {
                @Override
                public void run() {
                  inputTypeView.requestFocus();
                  inputTypeView.performClick();
                  Log.e(TAG, "TC_Downgrade_osV_True clcik!");
                }
              });

          sleep(2000);
          Log.e(TAG, "TC_Downgrade_osV_True snap!");
          //                   screenShot("TC_Downgrade_appV_True");
          ScreenShot.takeScreenShotIncludeDialog(getActivity(), "TC_Downgrade_osV_True");

          sleep(2000);
        }
      }
    }
  }
Esempio n. 4
0
  /**
   * Types text in an {@code EditText}
   *
   * @param index the index of the {@code EditText}
   * @param text the text that should be typed
   */
  public void typeText(final EditText editText, final String text) {
    if (editText != null) {
      inst.runOnMainSync(
          new Runnable() {
            public void run() {
              editText.setInputType(InputType.TYPE_NULL);
            }
          });
      clicker.clickOnScreen(editText, false, 0);
      activityUtils.hideSoftKeyboard(editText, true, true);

      boolean successfull = false;
      int retry = 0;

      while (!successfull && retry < 10) {

        try {
          inst.sendStringSync(text);
          successfull = true;
        } catch (SecurityException e) {
          activityUtils.hideSoftKeyboard(editText, true, true);
          retry++;
        }
      }
      if (!successfull) {
        Assert.assertTrue("Text can not be typed!", false);
      }
    }
  }
Esempio n. 5
0
  /**
   * Scrolls a ScrollView.
   *
   * @param direction the direction to be scrolled
   * @return {@code true} if scrolling occurred, false if it did not
   */
  boolean scrollView(final View view, int direction) {
    if (view == null) {
      return false;
    }

    int height = view.getHeight();
    height--;
    int scrollTo = -1;

    if (direction == DOWN) {
      scrollTo = height;
    } else if (direction == UP) {
      scrollTo = -height;
    }

    int originalY = view.getScrollY();
    final int scrollAmount = scrollTo;
    inst.runOnMainSync(
        new Runnable() {
          public void run() {
            view.scrollBy(0, scrollAmount);
          }
        });

    if (originalY == view.getScrollY()) {
      return false;
    } else {
      return true;
    }
  }
 private void layout(final int layoutId) {
   mInstrumentation.runOnMainSync(
       new Runnable() {
         @Override
         public void run() {
           mActivity.setContentView(layoutId);
         }
       });
   mInstrumentation.waitForIdleSync();
 }
Esempio n. 7
0
  @Override
  protected void setUp() throws Exception {
    Instrumentation instrumentation = getInstrumentation();
    mockSupport = new MozcMockSupport(instrumentation);

    activity =
        Preconditions.checkNotNull(
            launchActivity("org.mozc.android.inputmethod.japanese", Activity.class, null));
    instrumentation.runOnMainSync(new OnCreateRunner());
    context = instrumentation.getTargetContext();
  }
Esempio n. 8
0
  /**
   * Scrolls a WebView.
   *
   * @param webView the WebView to scroll
   * @param direction the direction to scroll
   * @param allTheWay {@code true} to scroll the view all the way up or down, {@code false} to
   *     scroll one page up or down or down.
   * @return {@code true} if more scrolling can be done
   */
  public boolean scrollWebView(final WebView webView, int direction, final boolean allTheWay) {

    if (direction == DOWN) {
      inst.runOnMainSync(
          new Runnable() {
            public void run() {
              canScroll = webView.pageDown(allTheWay);
            }
          });
    }
    if (direction == UP) {
      inst.runOnMainSync(
          new Runnable() {
            public void run() {
              canScroll = webView.pageUp(allTheWay);
            }
          });
    }
    return canScroll;
  }
 private void longClickAtPosition(final String methodExt, final int position)
     throws InterruptedException {
   final View view = getListView().getChildAt(position);
   assertTrue("View at list position " + position + " exists", view != null);
   mInstrumentation.runOnMainSync(
       new Runnable() {
         @Override
         public void run() {
           MyLog.v(methodExt, "performLongClick on " + view + " at position " + position);
           view.performLongClick();
         }
       });
   TestSuite.waitForIdleSync(mInstrumentation);
 }
 /**
  * Enables JavaScript in the given {@code WebViews} objects.
  *
  * @param webViews the {@code WebView} objects to enable JavaScript in
  */
 public void enableJavascriptAndSetRobotiumWebClient(
     List<WebView> webViews, WebChromeClient originalWebChromeClient) {
   this.originalWebChromeClient = originalWebChromeClient;
   for (final WebView webView : webViews) {
     if (webView != null) {
       inst.runOnMainSync(
           new Runnable() {
             public void run() {
               webView.getSettings().setJavaScriptEnabled(true);
               webView.setWebChromeClient(robotiumWebClient);
             }
           });
     }
   }
 }
  public void clickView(final String methodExt, final View view) throws InterruptedException {
    assertTrue(view != null);

    Runnable clicker =
        new Runnable() {
          @Override
          public void run() {
            MyLog.v(methodExt, "Before click view");
            view.performClick();
          }
        };

    mInstrumentation.runOnMainSync(clicker);
    MyLog.v(methodExt, "After click view");
    TestSuite.waitForIdleSync(mInstrumentation);
  }
Esempio n. 12
0
  /**
   * Scroll the list to a given line
   *
   * @param view the {@link AbsListView} to scroll
   * @param line the line to scroll to
   */
  public <T extends AbsListView> void scrollListToLine(final T view, final int line) {
    if (view == null) Assert.fail("AbsListView is null!");

    final int lineToMoveTo;
    if (view instanceof GridView) {
      lineToMoveTo = line + 1;
    } else {
      lineToMoveTo = line;
    }

    inst.runOnMainSync(
        new Runnable() {
          public void run() {
            view.setSelection(lineToMoveTo);
          }
        });
  }
Esempio n. 13
0
  /**
   * Sets an {@code EditText} text
   *
   * @param index the index of the {@code EditText}
   * @param text the text that should be set
   */
  public void setEditText(final EditText editText, final String text) {
    if (editText != null) {
      final String previousText = editText.getText().toString();

      inst.runOnMainSync(
          new Runnable() {
            public void run() {
              editText.setInputType(InputType.TYPE_NULL);
              editText.performClick();
              activityUtils.hideSoftKeyboard(editText, false, false);
              if (text.equals("")) editText.setText(text);
              else {
                editText.setText(previousText + text);
                editText.setCursorVisible(false);
              }
            }
          });
    }
  }
 public void clickListAtPosition(final String methodExt, final int position)
     throws InterruptedException {
   final String method = "clickListAtPosition";
   mInstrumentation.runOnMainSync(
       new Runnable() {
         // See
         // http://stackoverflow.com/questions/8094268/android-listview-performitemclick
         @Override
         public void run() {
           long listItemId = mActivity.getListAdapter().getItemId(position);
           MyLog.v(methodExt, method + "; on performClick, listItemId=" + listItemId);
           getListView()
               .performItemClick(
                   getListView().getAdapter().getView(position, null, null), position, listItemId);
         }
       });
   MyLog.v(methodExt, method + " ended");
   TestSuite.waitForIdleSync(mInstrumentation);
 }
 /**
  * InstrumentationTestCase.getInstrumentation().invokeContextMenuAction doesn't work properly
  *
  * @return success
  *     <p>Note: This method cannot be invoked on the main thread. See
  *     https://github.com/google/google-authenticator-android/blob/master/tests/src/com/google/android/apps/authenticator/TestUtilities.java
  */
 private boolean invokeContextMenuAction(
     final String methodExt, final MyListActivity activity, int position, final int menuItemId)
     throws InterruptedException {
   final String method = "invokeContextMenuAction";
   MyLog.v(
       methodExt, method + " started on menuItemId=" + menuItemId + " at position=" + position);
   boolean success = false;
   int position1 = position;
   for (long attempt = 1; attempt < 4; attempt++) {
     longClickAtPosition(methodExt, position1);
     if (mActivity.getPositionOfContextMenu() == position) {
       success = true;
       break;
     }
     MyLog.i(
         methodExt,
         method
             + "; Context menu created for position "
             + mActivity.getPositionOfContextMenu()
             + " instead of "
             + position
             + "; was set to "
             + position1
             + "; attempt "
             + attempt);
     position1 = position + (position1 - mActivity.getPositionOfContextMenu());
   }
   if (success) {
     mInstrumentation.runOnMainSync(
         new Runnable() {
           @Override
           public void run() {
             MyLog.v(methodExt, method + "; before performContextMenuIdentifierAction");
             activity.getWindow().performContextMenuIdentifierAction(menuItemId, 0);
           }
         });
     TestSuite.waitForIdleSync(mInstrumentation);
   }
   MyLog.v(methodExt, method + " ended " + success);
   return success;
 }
 public void selectListPosition(final String methodExt, final int positionIn)
     throws InterruptedException {
   final String method = "selectListPosition";
   MyLog.v(methodExt, method + " started; position=" + positionIn);
   mInstrumentation.runOnMainSync(
       new Runnable() {
         @Override
         public void run() {
           int position = positionIn;
           ListAdapter la = getListView().getAdapter();
           if (la.getCount() <= position) {
             position = la.getCount() - 1;
           }
           MyLog.v(
               methodExt, method + " on setSelection " + position + " of " + (la.getCount() - 1));
           getListView().setSelectionFromTop(position, 0);
         }
       });
   TestSuite.waitForIdleSync(mInstrumentation);
   MyLog.v(methodExt, method + " ended");
 }