Добавить доступный интерфейс этапа 3
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
package com.projectsacrifice.game;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.core.app.ActivityScenario;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public final class AccessibilityPersistenceTest {
|
||||
@Test
|
||||
public void accessibilityAndControlChoicesSurviveActivityRecreationTogether() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
view.resetControlSettingsForAutomation();
|
||||
view.resetAccessibilitySettingsForAutomation();
|
||||
view.selectNextControlSizeForAutomation();
|
||||
view.selectNextTextSizeForAutomation();
|
||||
view.toggleHighContrastForAutomation();
|
||||
});
|
||||
|
||||
activity.recreate();
|
||||
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
assertEquals("Large", view.controlSettingsForAutomation().controlSizeLabel());
|
||||
assertEquals("Large", view.accessibilitySettingsForAutomation().textSizeLabel());
|
||||
assertTrue(view.accessibilitySettingsForAutomation().highContrastEnabled());
|
||||
view.resetControlSettingsForAutomation();
|
||||
view.resetAccessibilitySettingsForAutomation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptionsFollowScreensWhileBackAlwaysHasOneDeterministicResult() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
activity.onActivity(current -> assertContains(
|
||||
current.gameViewForAutomation(), "Level select"));
|
||||
|
||||
activity.onActivity(current -> current.gameViewForAutomation()
|
||||
.openSettingsForAutomation());
|
||||
activity.onActivity(current -> {
|
||||
assertContains(current.gameViewForAutomation(), "Settings");
|
||||
assertContains(current.gameViewForAutomation(), "Text size");
|
||||
current.onBackPressed();
|
||||
assertContains(current.gameViewForAutomation(), "Level select");
|
||||
});
|
||||
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
view.startLevelForAutomation(1);
|
||||
assertContains(view, "Playing level 1");
|
||||
view.pauseForAutomation();
|
||||
assertContains(view, "Paused on level 1");
|
||||
current.onBackPressed();
|
||||
assertContains(view, "Playing level 1");
|
||||
assertFalse(view.automationSnapshot().visiblyPaused());
|
||||
view.showCompleteForAutomation();
|
||||
assertContains(view, "Level complete");
|
||||
current.onBackPressed();
|
||||
assertContains(view, "Level select");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textAndContrastPresetsDoNotMoveContentOutsideTheSafeViewport() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
float[] before = view.safeViewportForAutomation();
|
||||
view.selectNextTextSizeForAutomation();
|
||||
view.toggleHighContrastForAutomation();
|
||||
float[] after = view.safeViewportForAutomation();
|
||||
|
||||
assertTrue(before[0] >= 0f);
|
||||
assertTrue(before[1] >= 0f);
|
||||
assertTrue(before[2] <= view.getWidth());
|
||||
assertTrue(before[3] <= view.getHeight());
|
||||
assertEquals(before[0], after[0], 0f);
|
||||
assertEquals(before[1], after[1], 0f);
|
||||
assertEquals(before[2], after[2], 0f);
|
||||
assertEquals(before[3], after[3], 0f);
|
||||
view.resetAccessibilitySettingsForAutomation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessibilityRowsChangeThePersistedSettingsThroughRealTouchInput() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
view.resetAccessibilitySettingsForAutomation();
|
||||
view.openSettingsForAutomation();
|
||||
});
|
||||
|
||||
tap(activity, 220f, 345f);
|
||||
tap(activity, 220f, 515f);
|
||||
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
assertEquals(1.25f, view.textScaleForAutomation(), 0f);
|
||||
assertTrue(view.highContrastForAutomation());
|
||||
assertTrue(view.screenDescriptionForAutomation().contains("Text size Large"));
|
||||
assertTrue(view.screenDescriptionForAutomation().contains("High contrast On"));
|
||||
view.resetAccessibilitySettingsForAutomation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void criticalSignalAndDoorStateRemainsTextualWhenVibrationIsOff() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
view.resetControlSettingsForAutomation();
|
||||
view.toggleHapticsForAutomation();
|
||||
view.startLevelForAutomation(3);
|
||||
|
||||
assertEquals("Signals 0/1 · Doors 0/1 · Volunteer active",
|
||||
view.criticalVisibleStatusForAutomation());
|
||||
assertTrue(view.screenDescriptionForAutomation().contains(
|
||||
view.criticalVisibleStatusForAutomation()));
|
||||
view.resetControlSettingsForAutomation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void tap(ActivityScenario<MainActivity> activity, float canvasX, float canvasY) {
|
||||
touch(activity, MotionEvent.ACTION_DOWN, canvasX, canvasY);
|
||||
touch(activity, MotionEvent.ACTION_UP, canvasX, canvasY);
|
||||
}
|
||||
|
||||
private static void touch(ActivityScenario<MainActivity> activity, int action,
|
||||
float canvasX, float canvasY) {
|
||||
activity.onActivity(current -> {
|
||||
GameView view = current.gameViewForAutomation();
|
||||
float scale = Math.min(view.getWidth() / 1_920f, view.getHeight() / 1_080f);
|
||||
float x = (view.getWidth() - 1_920f * scale) * 0.5f + canvasX * scale;
|
||||
float y = (view.getHeight() - 1_080f * scale) * 0.5f + canvasY * scale;
|
||||
long now = SystemClock.uptimeMillis();
|
||||
MotionEvent event = MotionEvent.obtain(now, now, action, x, y, 0);
|
||||
view.dispatchTouchEvent(event);
|
||||
event.recycle();
|
||||
});
|
||||
}
|
||||
|
||||
private static void assertContains(GameView view, String expected) {
|
||||
String description = String.valueOf(view.getContentDescription());
|
||||
assertTrue("Expected '" + expected + "' in '" + description + "'",
|
||||
description.contains(expected));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user