From 4e8440972891bd1f010472fe51d1893e0ecf08e8 Mon Sep 17 00:00:00 2001 From: Kenneth Ford Date: Fri, 29 Oct 2021 18:08:21 +0000 Subject: [PATCH] Adds tests for device state flags in DeviceStateProvider Tests that you can add the FLAG_CANCEL_STICKY_REQUESTS flag to a device state as well as an invalid flag being discarded. Bug: 204573679 Test: DeviceStateProviderImplTest Change-Id: I8142ed36069c213bac4e7aaefc389c60d26d8cca --- .../policy/DeviceStateProviderImplTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/services/tests/servicestests/src/com/android/server/policy/DeviceStateProviderImplTest.java b/services/tests/servicestests/src/com/android/server/policy/DeviceStateProviderImplTest.java index 8e2c1f051279d..761cea79df28d 100644 --- a/services/tests/servicestests/src/com/android/server/policy/DeviceStateProviderImplTest.java +++ b/services/tests/servicestests/src/com/android/server/policy/DeviceStateProviderImplTest.java @@ -159,6 +159,64 @@ public final class DeviceStateProviderImplTest { assertEquals(1, mIntegerCaptor.getValue().intValue()); } + @Test + public void create_stateWithCancelStickyRequestFlag() { + String configString = "\n" + + " \n" + + " 1\n" + + " \n" + + " FLAG_CANCEL_STICKY_REQUESTS\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 2\n" + + " \n" + + " \n" + + "\n"; + DeviceStateProviderImpl.ReadableConfig config = new TestReadableConfig(configString); + DeviceStateProviderImpl provider = DeviceStateProviderImpl.createFromConfig(mContext, + config); + + DeviceStateProvider.Listener listener = mock(DeviceStateProvider.Listener.class); + provider.setListener(listener); + + verify(listener).onSupportedDeviceStatesChanged(mDeviceStateArrayCaptor.capture()); + final DeviceState[] expectedStates = new DeviceState[]{ + new DeviceState(1, "", DeviceState.FLAG_CANCEL_STICKY_REQUESTS), + new DeviceState(2, "", 0 /* flags */) }; + assertArrayEquals(expectedStates, mDeviceStateArrayCaptor.getValue()); + } + + @Test + public void create_stateWithInvalidFlag() { + String configString = "\n" + + " \n" + + " 1\n" + + " \n" + + " INVALID_FLAG\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 2\n" + + " \n" + + " \n" + + "\n"; + DeviceStateProviderImpl.ReadableConfig config = new TestReadableConfig(configString); + DeviceStateProviderImpl provider = DeviceStateProviderImpl.createFromConfig(mContext, + config); + + DeviceStateProvider.Listener listener = mock(DeviceStateProvider.Listener.class); + provider.setListener(listener); + + verify(listener).onSupportedDeviceStatesChanged(mDeviceStateArrayCaptor.capture()); + final DeviceState[] expectedStates = new DeviceState[]{ + new DeviceState(1, "", 0 /* flags */), + new DeviceState(2, "", 0 /* flags */) }; + assertArrayEquals(expectedStates, mDeviceStateArrayCaptor.getValue()); + } + @Test public void create_lidSwitch() { String configString = "\n"