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 testcase04_DownloadingCancel() {

    mPreference.edit().putInt(OTA_PRE_STATUS, STATE_DOWNLOADING).commit();
    mPreference.edit().putInt(OTA_PRE_DELTA_ID, PKG_ID_TEST).commit();

    mActivity = getActivity();

    ProgressBar dlRatioProgressBar = (ProgressBar) mActivity.findViewById(R.id.downloaingProBar);

    assertTrue(dlRatioProgressBar != null);
    assertTrue(dlRatioProgressBar.isShown());

    if (Util.isSdcardAvailable(mActivity) && Util.isNetWorkAvailable(mActivity, "WIFI")) {
      if (mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD) {
        return;
      }
      mInst.invokeMenuActionSync(mActivity, MENU_ID_CANCEL, 0);
      mInst.waitForIdleSync();

      assertTrue(mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD);
      sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
      sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);

      sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

      mInst.waitForIdleSync();
      assertTrue(mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_QUERYNEWVERSION);
    }
  }
  public void longPress(Coordinates where) {
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    Point point = where.getLocationOnScreen();
    // List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
    //
    // motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, point));
    // motionEvents.add(getMotionEvent(downTime, (downTime + 3000), MotionEvent.ACTION_UP, point));
    // sendMotionEvents(motionEvents);
    Instrumentation inst = instrumentation;

    MotionEvent event = null;
    boolean successfull = false;
    int retry = 0;
    while (!successfull && retry < 10) {
      try {
        if (event == null) {
          event =
              MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, point.x, point.y, 0);
        }
        System.out.println("trying to send pointer");
        inst.sendPointerSync(event);
        successfull = true;
      } catch (SecurityException e) {
        System.out.println("failed: " + retry);
        // activityUtils.hideSoftKeyboard(null, false, true);
        retry++;
      }
    }
    if (!successfull) {
      throw new SelendroidException("Click can not be completed!");
    }
    inst.sendPointerSync(event);
    inst.waitForIdleSync();

    eventTime = SystemClock.uptimeMillis();
    final int touchSlop = ViewConfiguration.get(inst.getTargetContext()).getScaledTouchSlop();
    event =
        MotionEvent.obtain(
            downTime,
            eventTime,
            MotionEvent.ACTION_MOVE,
            point.x + touchSlop / 2,
            point.y + touchSlop / 2,
            0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();

    try {
      Thread.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f));
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    eventTime = SystemClock.uptimeMillis();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, point.x, point.y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    mActivity = getActivity();
    mInstrumentation = getInstrumentation();

    mButton = new Button(mActivity);
    mActivity.runOnUiThread(
        new Runnable() {
          public void run() {
            try {
              mActivity.addContentView(
                  mButton, new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
            } catch (Exception e) {
              mException = e;
            }
          }
        });
    mInstrumentation.waitForIdleSync();

    if (mException != null) {
      throw mException;
    }

    int right = mButton.getRight();
    int bottom = mButton.getBottom();
    mXInside = (mButton.getLeft() + right) / 3;
    mYInside = (mButton.getTop() + bottom) / 3;

    mRect = new Rect();
    mButton.getHitRect(mRect);
  }
Example #6
0
  /** Tests that pressing the next button and clicking ok on the dialog closes the activity */
  @LargeTest
  public void testActivityClosesOnFinish() {
    loadUpImageAndGoToShareActivity();

    createNewspaperActivity.runOnUiThread(
        new Runnable() {
          public void run() {
            Button finishButton = (Button) createNewspaperActivity.findViewById(R.id.finishBtn);

            // Ensure that the button is not null before we attempt to click it
            assertNotNull(finishButton);
            finishButton.performClick();

            // Ensure that the error dialog is not null
            assertNotNull(createNewspaperActivity.getErrorDialog());

            // Click on the positive button (OK) to close the dialog
            createNewspaperActivity
                .getErrorDialog()
                .getDialog()
                .getButton(DialogInterface.BUTTON_POSITIVE)
                .performClick();
          }
        });
    instrumentation.waitForIdleSync();

    // Ensure that the activity is closing off now we have clicked finish and ok on the dialog
    assertTrue(createNewspaperActivity.isFinishing());
  }
 private void layout(final int layoutId) {
   mInstrumentation.runOnMainSync(
       new Runnable() {
         @Override
         public void run() {
           mActivity.setContentView(layoutId);
         }
       });
   mInstrumentation.waitForIdleSync();
 }
  private void sendRestriction(final Bundle restrictions) {
    // Deliver restriction on UI thread
    mActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            ManagedProfileManager.getInstance().setMdmRestrictions(restrictions);
          }
        });

    // Wait to ensure restriction is set
    mInstrumentation.waitForIdleSync();
  }
Example #9
0
 @Override
 protected int executeInner(String parameters) {
   log("executeInner");
   final Instrumentation instrumentation = AutotestEngine.getInstance().getInstrumentation();
   if (!mIsRecording) {
     PhoneRecorderHandler.getInstance()
         .startVoiceRecord(Constants.PHONE_RECORDING_VOICE_CALL_CUSTOM_VALUE);
   } else {
     PhoneRecorderHandler.getInstance().stopRecording();
   }
   Utils.sleep(2000);
   instrumentation.waitForIdleSync();
   return ICommand.RESULT_OK;
 }
  public void testcase02_NewVersionDl() {

    mPreference.edit().putInt(OTA_PRE_STATUS, STATE_NEWVERSION_READY).commit();
    mPreference.edit().putInt(OTA_PRE_DELTA_ID, PKG_ID_TEST).commit();
    mActivity = getActivity();

    mInst.invokeMenuActionSync(mActivity, MENU_ID_DOWNLOAD, 0);
    mInst.waitForIdleSync();

    Xlog.i(TAG, "OTA_PRE_STATUS = " + mPreference.getInt(OTA_PRE_STATUS, -1));
    if (Util.isSdcardAvailable(mActivity) && Util.isNetWorkAvailable(mActivity, "WIFI")) {
      assertTrue(
          mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_DOWNLOADING
              || mPreference.getInt(OTA_PRE_STATUS, -1) == STATE_PAUSEDOWNLOAD);
    }
  }
Example #11
0
  public void testItemClick() throws Exception {
    ds.writeNote("Note 1", "test");
    start();
    Instrumentation.ActivityMonitor monitor =
        instrumentation.addMonitor(Editor.class.getName(), null, false);

    notes.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            listView.performItemClick(listView, 0, 0);
          }
        });

    instrumentation.waitForIdleSync();
    Activity editor = instrumentation.waitForMonitorWithTimeout(monitor, 3 * 1000);
    notes.finishActivity(1);
    assertNotNull("Editor not started in 3 sec.", editor);
  }
Example #12
0
  /**
   * Tests that pressing the next button opens a dialog asking the user to confirm that they are
   * going back to the home screen
   */
  @LargeTest
  public void testDialogAppearsOnFinishClick() {
    loadUpImageAndGoToShareActivity();

    createNewspaperActivity.runOnUiThread(
        new Runnable() {
          public void run() {
            Button finishButton = (Button) createNewspaperActivity.findViewById(R.id.finishBtn);

            // Ensure that the button is not null before we attempt to click it
            assertNotNull(finishButton);
            finishButton.performClick();
          }
        });
    instrumentation.waitForIdleSync();

    // Ensure that the error dialog is displaying after clicking the finish button
    assertTrue(createNewspaperActivity.getErrorDialog().isShowing());
  }
Example #13
0
  /**
   * Utility method to launch the share fragment with a dummy image such that we can test all that
   * relates to the share fragment
   */
  public void loadUpImageAndGoToShareActivity() {
    createNewspaperActivity.runOnUiThread(
        new Runnable() {
          public void run() {
            // Set up all of the properties of the imageFragment so it can hold an image
            createNewspaperActivity.getImageFragment().updateImage(bitmap);
            createNewspaperActivity.getImageFragment().setOriginalImage();
            createNewspaperActivity.setOldBitmaps(bitmap, 0);

            // Ensure that the properties of the imageView are set up (not null)
            assertNotNull(createNewspaperActivity.getImageFragment().getImageView());
            assertNotNull(createNewspaperActivity.getImageFragment().getBitmap());
            assertNotNull(createNewspaperActivity.getImageFragment().getImageBytes());

            // Open the createNewspaperActivity's share fragment with this dummy image we loaded in
            // from our assets
            createNewspaperActivity.saveToGallery();
            createNewspaperActivity.openShareFragment();
          }
        });
    instrumentation.waitForIdleSync();
  }
  public void testAccessOnScrollChangedListener() throws Throwable {
    layout(R.layout.scrollview_layout);
    final ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.scroll_view);

    mViewTreeObserver = scrollView.getViewTreeObserver();

    final MockOnScrollChangedListener listener = new MockOnScrollChangedListener();
    assertFalse(listener.hasCalledOnScrollChanged());
    mViewTreeObserver.addOnScrollChangedListener(listener);

    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_DOWN);
          }
        });
    mInstrumentation.waitForIdleSync();
    new PollingCheck() {
      @Override
      protected boolean check() {
        return listener.hasCalledOnScrollChanged();
      }
    }.run();

    listener.reset();
    assertFalse(listener.hasCalledOnScrollChanged());

    mViewTreeObserver.removeOnScrollChangedListener(listener);
    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_UP);
          }
        });
    assertFalse(listener.hasCalledOnScrollChanged());
  }