@SmallTest public void testOnDown() { KeyEventButtonTouchListener keyEventButtonTouchListener = new KeyEventButtonTouchListener(1, 10); KeyEventHandler keyEventHandler = createKeyEventHandlerMock(); keyEventButtonTouchListener.setKeyEventHandler(keyEventHandler); Context context = getInstrumentation().getContext(); ViewGroup parent = new FrameLayout(context); parent.layout(0, 0, 100, 100); View view = new View(context); parent.addView(view); view.layout(0, 0, 50, 50); Key key = KeyEventButtonTouchListener.createKey(view, 1, 10); KeyEventContext keyEventContext = new KeyEventContext(key, 0, 0, 0, 0, 100, 100, Collections.<MetaState>emptySet()); keyEventButtonTouchListener.keyEventContext = keyEventContext; // For onDown, first, cancelDelayedKeyEvent should be invoked to cancel old // event, then maybeStartDelayedKeyEvent and sendPress should follow. keyEventHandler.cancelDelayedKeyEvent(keyEventContext); keyEventHandler.maybeStartDelayedKeyEvent(isA(KeyEventContext.class)); keyEventHandler.sendPress(10); replayAll(); keyEventButtonTouchListener.onDown(view, 0, 0); verifyAll(); assertNotSame(keyEventContext, keyEventButtonTouchListener.keyEventContext); assertTrue(view.isPressed()); }
@SmallTest public void testOnUp() { KeyEventButtonTouchListener keyEventButtonTouchListener = new KeyEventButtonTouchListener(1, 10); KeyEventHandler keyEventHandler = createKeyEventHandlerMock(); keyEventButtonTouchListener.setKeyEventHandler(keyEventHandler); View view = new View(getInstrumentation().getTargetContext()); view.layout(0, 0, 50, 50); Key key = KeyEventButtonTouchListener.createKey(view, 1, 10); KeyEventContext keyEventContext = new KeyEventContext(key, 0, 0, 0, 0, 100, 100, Collections.<MetaState>emptySet()); keyEventButtonTouchListener.keyEventContext = keyEventContext; keyEventHandler.cancelDelayedKeyEvent(keyEventContext); keyEventHandler.sendKey(eq(10), EasyMock.<List<TouchEvent>>notNull()); keyEventHandler.sendRelease(10); replayAll(); view.setPressed(true); keyEventButtonTouchListener.onUp(view, 25, 25, 100); verifyAll(); assertNull(keyEventButtonTouchListener.keyEventContext); assertFalse(view.isPressed()); }
@SmallTest public void testOnMove() { KeyEventButtonTouchListener keyEventButtonTouchListener = new KeyEventButtonTouchListener(1, 10); KeyEventHandler keyEventHandler = createKeyEventHandlerMock(); keyEventButtonTouchListener.setKeyEventHandler(keyEventHandler); KeyEventContext keyEventContext = createKeyEventContextMock(); keyEventButtonTouchListener.keyEventContext = keyEventContext; expect(keyEventContext.update(10, 20, TouchAction.TOUCH_MOVE, 100)).andReturn(true); keyEventHandler.cancelDelayedKeyEvent(keyEventContext); replayAll(); keyEventButtonTouchListener.onMove(10, 20, 100); verifyAll(); assertNull(keyEventButtonTouchListener.keyEventContext); }
@SmallTest public void testReset() { KeyEventButtonTouchListener keyEventButtonTouchListener = new KeyEventButtonTouchListener(1, 10); KeyEventHandler keyEventHandler = createKeyEventHandlerMock(); keyEventButtonTouchListener.setKeyEventHandler(keyEventHandler); View view = new View(getInstrumentation().getTargetContext()); view.layout(0, 0, 50, 50); Key key = KeyEventButtonTouchListener.createKey(view, 1, 10); KeyEventContext keyEventContext = new KeyEventContext(key, 0, 0, 0, 0, 100, 100, Collections.<MetaState>emptySet()); keyEventHandler.cancelDelayedKeyEvent(keyEventContext); replayAll(); keyEventButtonTouchListener.keyEventContext = keyEventContext; keyEventButtonTouchListener.reset(); verifyAll(); assertNull(keyEventButtonTouchListener.keyEventContext); }