FileDocCategorySizeDatePackage
MockAccessibilityService.javaAPI DocAndroid 5.1 API9122Thu Mar 12 22:22:42 GMT 2015com.android.server

MockAccessibilityService

public abstract class MockAccessibilityService extends android.accessibilityservice.AccessibilityService
This is the base class for mock {@link AccessibilityService}s.

Fields Summary
private final Queue
mExpectedEvents
The event this service expects to receive.
private boolean
mExpectedInterrupt
Interruption call this service expects to receive.
private boolean
mReplaying
Flag if the mock is currently replaying.
private boolean
mIsSystemBoundAsClient
Flag if the system is bound as a client to this service.
Constructors Summary
Methods Summary
private voidassertEqualsAccessiblityEvent(android.view.accessibility.AccessibilityEvent expectedEvent, android.view.accessibility.AccessibilityEvent receivedEvent)
Compares all properties of the expectedEvent and the receviedEvent to verify that the received event is the one that is expected.

        TestCase.assertEquals("addedCount has incorrect value", expectedEvent.getAddedCount(),
                receivedEvent.getAddedCount());
        TestCase.assertEquals("beforeText has incorrect value", expectedEvent.getBeforeText(),
                receivedEvent.getBeforeText());
        TestCase.assertEquals("checked has incorrect value", expectedEvent.isChecked(),
                receivedEvent.isChecked());
        TestCase.assertEquals("className has incorrect value", expectedEvent.getClassName(),
                receivedEvent.getClassName());
        TestCase.assertEquals("contentDescription has incorrect value", expectedEvent
                .getContentDescription(), receivedEvent.getContentDescription());
        TestCase.assertEquals("currentItemIndex has incorrect value", expectedEvent
                .getCurrentItemIndex(), receivedEvent.getCurrentItemIndex());
        TestCase.assertEquals("enabled has incorrect value", expectedEvent.isEnabled(),
                receivedEvent.isEnabled());
        TestCase.assertEquals("eventType has incorrect value", expectedEvent.getEventType(),
                receivedEvent.getEventType());
        TestCase.assertEquals("fromIndex has incorrect value", expectedEvent.getFromIndex(),
                receivedEvent.getFromIndex());
        TestCase.assertEquals("fullScreen has incorrect value", expectedEvent.isFullScreen(),
                receivedEvent.isFullScreen());
        TestCase.assertEquals("itemCount has incorrect value", expectedEvent.getItemCount(),
                receivedEvent.getItemCount());
        assertEqualsNotificationAsParcelableData(expectedEvent, receivedEvent);
        TestCase.assertEquals("password has incorrect value", expectedEvent.isPassword(),
                receivedEvent.isPassword());
        TestCase.assertEquals("removedCount has incorrect value", expectedEvent.getRemovedCount(),
                receivedEvent.getRemovedCount());
        assertEqualsText(expectedEvent, receivedEvent);
    
private voidassertEqualsNotificationAsParcelableData(android.view.accessibility.AccessibilityEvent expectedEvent, android.view.accessibility.AccessibilityEvent receivedEvent)
Compares the {@link android.os.Parcelable} data of the expectedEvent and receivedEvent to verify that the received event is the one that is expected.

        String message = "parcelableData has incorrect value";
        Message expectedMessage = (Message) expectedEvent.getParcelableData();
        Message receivedMessage = (Message) receivedEvent.getParcelableData();

        if (expectedMessage == null) {
            if (receivedMessage == null) {
                return;
            }
        }

        TestCase.assertNotNull(message, receivedMessage);

        // we do a very simple sanity check since we do not test Message
        TestCase.assertEquals(message, expectedMessage.what, receivedMessage.what);
    
private voidassertEqualsText(android.view.accessibility.AccessibilityEvent expectedEvent, android.view.accessibility.AccessibilityEvent receivedEvent)
Compares the text of the expectedEvent and receivedEvent by comparing the string representation of the corresponding {@link CharSequence}s.

        String message = "text has incorrect value";
        List<CharSequence> expectedText = expectedEvent.getText();
        List<CharSequence> receivedText = receivedEvent.getText();

        TestCase.assertEquals(message, expectedText.size(), receivedText.size());

        Iterator<CharSequence> expectedTextIterator = expectedText.iterator();
        Iterator<CharSequence> receivedTextIterator = receivedText.iterator();

        for (int i = 0; i < expectedText.size(); i++) {
            // compare the string representation
            TestCase.assertEquals(message, expectedTextIterator.next().toString(),
                    receivedTextIterator.next().toString());
        }
    
public static android.accessibilityservice.AccessibilityServiceInfocreateDefaultInfo()
Creates an {@link AccessibilityServiceInfo} populated with default values.

return
The default info.


                     
        
        AccessibilityServiceInfo defaultInfo = new AccessibilityServiceInfo();
        defaultInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED;
        defaultInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
        defaultInfo.flags = 0;
        defaultInfo.notificationTimeout = 0;
        defaultInfo.packageNames = new String[] {
            "foo.bar.baz"
        };

        return defaultInfo;
    
public voidexpectEvent(android.view.accessibility.AccessibilityEvent expectedEvent)
Sets an expected call to {@link #onAccessibilityEvent(AccessibilityEvent)} with given event as argument.

param
expectedEvent The expected event argument.

        mExpectedEvents.add(expectedEvent);
    
public voidexpectInterrupt()
Sets an expected call of {@link #onInterrupt()}.

        mExpectedInterrupt = true;
    
public booleanisSystemBoundAsClient()
Returns if the system is bound as client to this service.

return
True if the system is bound, false otherwise.

        return mIsSystemBoundAsClient;
    
public voidonAccessibilityEvent(android.view.accessibility.AccessibilityEvent receivedEvent)

        if (!mReplaying) {
            return;
        }

        if (mExpectedEvents.isEmpty()) {
            throw new IllegalStateException("Unexpected event: " + receivedEvent);
        }

        AccessibilityEvent expectedEvent = mExpectedEvents.poll();
        assertEqualsAccessiblityEvent(expectedEvent, receivedEvent);
    
public voidonInterrupt()

        if (!mReplaying) {
            return;
        }

        if (!mExpectedInterrupt) {
            throw new IllegalStateException("Unexpected call to onInterrupt()");
        }

        mExpectedInterrupt = false;
    
protected voidonServiceConnected()

        mIsSystemBoundAsClient = true;
    
public booleanonUnbind(android.content.Intent intent)

        mIsSystemBoundAsClient = false;
        return false;
    
public voidreplay()
Starts replaying the mock.

        mReplaying = true;
    
public voidreset()
Resets this instance so it can be reused.

        mExpectedEvents.clear();
        mExpectedInterrupt = false;
        mReplaying = false;
    
public voidverify()
Verifies if all expected service methods have been called.

        if (!mReplaying) {
            throw new IllegalStateException("Did you forget to call replay()");
        }

        if (mExpectedInterrupt) {
            throw new IllegalStateException("Expected call to #interrupt() not received");
        }
        if (!mExpectedEvents.isEmpty()) {
            throw new IllegalStateException("Expected a call to onAccessibilityEvent() for "
                    + "events \"" + mExpectedEvents + "\" not received");
        }