Merge "Fixes to interstitial activity transitions" into main
This commit is contained in:
@@ -115,18 +115,21 @@ public class SetupInterstitialActivity extends FragmentActivity {
|
||||
if (intent == null) {
|
||||
Log.w(TAG, "no intent found for modes interstitial");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
String modeId = intent.getStringExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID);
|
||||
if (modeId == null) {
|
||||
Log.w(TAG, "no mode id included in intent: " + intent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
ZenMode mode = mBackend.getMode(modeId);
|
||||
if (mode == null) {
|
||||
Log.w(TAG, "mode not found for mode id: " + modeId);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
setTitle(mode.getName());
|
||||
|
||||
@@ -237,11 +240,11 @@ public class SetupInterstitialActivity extends FragmentActivity {
|
||||
// Don't come back to this activity after sending the user to the modes page, if
|
||||
// they happen to go back. Forward the activity result in case we got here (indirectly)
|
||||
// from some app that is waiting for the result.
|
||||
finish();
|
||||
if (updated) {
|
||||
ZenSubSettingLauncher.forMode(this, modeId)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).launch();
|
||||
}
|
||||
finish();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,41 @@ public class SetupInterstitialActivityTest {
|
||||
when(mImage.getLayoutParams()).thenReturn(new ViewGroup.LayoutParams(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidIntent_doesNotQueryBackend() {
|
||||
// Mode is set up sensibly
|
||||
ZenMode mode = new TestModeBuilder().setId(MODE_ID).setEnabled(false).build();
|
||||
when(mBackend.getMode(MODE_ID)).thenReturn(mode);
|
||||
|
||||
// but the intent is lacking the zen mode extra
|
||||
ActivityScenario<SetupInterstitialActivity> scenario =
|
||||
ActivityScenario.launch(new Intent(Intent.ACTION_MAIN)
|
||||
.setClass(RuntimeEnvironment.getApplication(),
|
||||
SetupInterstitialActivity.class));
|
||||
// creating the scenario takes it through onResume(), which would query the backend if
|
||||
// it had mode data.
|
||||
scenario.onActivity(activity -> {
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
verify(mBackend, never()).getMode(any());
|
||||
});
|
||||
scenario.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidModeId_doesNotCrash() {
|
||||
when(mBackend.getMode(MODE_ID)).thenReturn(null);
|
||||
ActivityScenario<SetupInterstitialActivity> scenario =
|
||||
ActivityScenario.launch(new Intent(Intent.ACTION_MAIN)
|
||||
.setClass(RuntimeEnvironment.getApplication(),
|
||||
SetupInterstitialActivity.class)
|
||||
.putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, MODE_ID));
|
||||
// do nothing, but it would crash if attempting to work with a null mode at any point
|
||||
scenario.onActivity(activity -> {
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
});
|
||||
scenario.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableButton_enablesModeAndRedirectsToModePage() {
|
||||
ZenMode mode = new TestModeBuilder().setId(MODE_ID).setEnabled(false).build();
|
||||
|
||||
Reference in New Issue
Block a user