Methods Summary |
---|
private static android.view.accessibility.IAccessibilityManagerClient | anyIAccessibilityManagerClient()Determines if an {@link IAccessibilityManagerClient} passed as a method argument
matches expectations which in this case are that any instance is accepted.
reportMatcher(new AnyIAccessibilityManagerClientMather());
return null;
|
private static android.view.accessibility.AccessibilityEvent | eqAccessibilityEvent(android.view.accessibility.AccessibilityEvent matched)Determines if an {@link AccessibilityEvent} passed as a method argument
matches expectations.
reportMatcher(new AccessibilityEventMather(matched));
return null;
|
public void | setUp()
reset(mMockServiceInterface);
|
public void | testGetAccessibilityServiceList()
// create a list of installed accessibility services the mock service returns
List<AccessibilityServiceInfo> expectedServices = new ArrayList<AccessibilityServiceInfo>();
AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
expectedServices.add(accessibilityServiceInfo);
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(),
UserHandle.USER_OWNER)).andReturn(
AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
expect(mockServiceInterface.getInstalledAccessibilityServiceList(UserHandle.USER_OWNER))
.andReturn(expectedServices);
replay(mockServiceInterface);
// invoke the method under test
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface,
UserHandle.USER_OWNER);
List<AccessibilityServiceInfo> receivedServices =
manager.getInstalledAccessibilityServiceList();
// check expected result (list equals() compares it contents as well)
assertEquals("All expected services must be returned", receivedServices, expectedServices);
// verify the mock service was properly called
verify(mockServiceInterface);
|
public void | testInterrupt()
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(),
UserHandle.USER_OWNER)).andReturn(
AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
mockServiceInterface.interrupt(UserHandle.USER_OWNER);
replay(mockServiceInterface);
// invoke the method under test
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface,
UserHandle.USER_OWNER);
manager.interrupt();
// verify the mock service was properly called
verify(mockServiceInterface);
|
public void | testIsEnabled()
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(),
UserHandle.USER_OWNER)).andReturn(
AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
replay(mockServiceInterface);
// invoke the method under test
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface,
UserHandle.USER_OWNER);
boolean isEnabledServiceEnabled = manager.isEnabled();
// check expected result
assertTrue("Must be enabled since the mock service is enabled", isEnabledServiceEnabled);
// disable accessibility
manager.getClient().setState(0);
// wait for the asynchronous IBinder call to complete
Thread.sleep(TIMEOUT_BINDER_CALL);
// invoke the method under test
boolean isEnabledServcieDisabled = manager.isEnabled();
// check expected result
assertFalse("Must be disabled since the mock service is disabled",
isEnabledServcieDisabled);
// verify the mock service was properly called
verify(mockServiceInterface);
|
public void | testSendAccessibilityEvent_AccessibilityDisabled()
// create an event to be dispatched
AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(),
UserHandle.USER_OWNER)).andReturn(0);
replay(mockServiceInterface);
// invoke the method under test (accessibility disabled)
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface,
UserHandle.USER_OWNER);
try {
manager.sendAccessibilityEvent(sentEvent);
fail("No accessibility events are sent if accessibility is disabled");
} catch (IllegalStateException ise) {
// check expected result
assertEquals("Accessibility off. Did you forget to check that?", ise.getMessage());
}
// verify the mock service was properly called
verify(mockServiceInterface);
|
public void | testSendAccessibilityEvent_AccessibilityEnabled()
// create an event to be dispatched
AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(),
UserHandle.USER_OWNER)).andReturn(
AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent),
UserHandle.USER_OWNER)).andReturn(true);
expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent),
UserHandle.USER_OWNER)).andReturn(false);
replay(mockServiceInterface);
// invoke the method under test (manager and service in different processes)
AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface,
UserHandle.USER_OWNER);
manager.sendAccessibilityEvent(sentEvent);
// check expected result
AccessibilityEvent nextEventDifferentProcesses = AccessibilityEvent.obtain();
assertSame("The manager and the service are in different processes, so the event must be " +
"recycled", sentEvent, nextEventDifferentProcesses);
// invoke the method under test (manager and service in the same process)
manager.sendAccessibilityEvent(sentEvent);
// check expected result
AccessibilityEvent nextEventSameProcess = AccessibilityEvent.obtain();
assertNotSame("The manager and the service are in the same process, so the event must not" +
"be recycled", sentEvent, nextEventSameProcess);
// verify the mock service was properly called
verify(mockServiceInterface);
|