Merge "Make chart time slot not clickable when accessibility servie is enabled" into sc-dev
This commit is contained in:
@@ -130,6 +130,7 @@ public final class BatteryChartViewTest {
|
||||
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
assertThat(mBatteryChartView.isClickable()).isFalse();
|
||||
assertThat(mBatteryChartView.mTrapezoidCurvePaint).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,6 +142,7 @@ public final class BatteryChartViewTest {
|
||||
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
assertThat(mBatteryChartView.isClickable()).isTrue();
|
||||
assertThat(mBatteryChartView.mTrapezoidCurvePaint).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,6 +157,7 @@ public final class BatteryChartViewTest {
|
||||
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
assertThat(mBatteryChartView.isClickable()).isTrue();
|
||||
assertThat(mBatteryChartView.mTrapezoidCurvePaint).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,5 +169,62 @@ public final class BatteryChartViewTest {
|
||||
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
assertThat(mBatteryChartView.isClickable()).isFalse();
|
||||
assertThat(mBatteryChartView.mTrapezoidCurvePaint).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickable_restoreFromNonClickableState() {
|
||||
final int[] levels = new int[13];
|
||||
for (int index = 0; index < levels.length; index++) {
|
||||
levels[index] = index + 1;
|
||||
}
|
||||
mBatteryChartView.setTrapezoidCount(12);
|
||||
mBatteryChartView.setLevels(levels);
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
.thenReturn(true);
|
||||
doReturn(true).when(mockAccessibilityManager).isEnabled();
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
// Ensures the testing environment is correct.
|
||||
assertThat(mBatteryChartView.isClickable()).isFalse();
|
||||
// Turns off accessibility service.
|
||||
doReturn(false).when(mockAccessibilityManager).isEnabled();
|
||||
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
|
||||
assertThat(mBatteryChartView.isClickable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAttachedToWindow_addAccessibilityStateChangeListener() {
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
verify(mockAccessibilityManager)
|
||||
.addAccessibilityStateChangeListener(mBatteryChartView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDetachedFromWindow_removeAccessibilityStateChangeListener() {
|
||||
mBatteryChartView.onAttachedToWindow();
|
||||
mBatteryChartView.mHandler.postDelayed(
|
||||
mBatteryChartView.mUpdateClickableStateRun, 1000);
|
||||
|
||||
mBatteryChartView.onDetachedFromWindow();
|
||||
|
||||
verify(mockAccessibilityManager)
|
||||
.removeAccessibilityStateChangeListener(mBatteryChartView);
|
||||
assertThat(mBatteryChartView.mHandler.hasCallbacks(
|
||||
mBatteryChartView.mUpdateClickableStateRun))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnAccessibilityStateChanged_postUpdateStateRunnable() {
|
||||
mBatteryChartView.mHandler = spy(mBatteryChartView.mHandler);
|
||||
mBatteryChartView.onAccessibilityStateChanged(/*enabled=*/ true);
|
||||
|
||||
verify(mBatteryChartView.mHandler)
|
||||
.removeCallbacks(mBatteryChartView.mUpdateClickableStateRun);
|
||||
verify(mBatteryChartView.mHandler)
|
||||
.postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user