1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.base.test.transit; 6 7 import android.widget.Toast; 8 9 import androidx.test.platform.app.InstrumentationRegistry; 10 11 import org.chromium.base.Log; 12 import org.chromium.base.ResettersForTesting; 13 import org.chromium.base.ThreadUtils; 14 15 /** Configuration for PublicTransit tests. */ 16 public class PublicTransitConfig { 17 private static final String TAG = "Transit"; 18 private static long sTransitionPause; 19 20 /** 21 * Set a pause for all transitions for debugging. 22 * 23 * @param millis how long to pause for (1000 to 4000 ms is typical). 24 */ setTransitionPauseForDebugging(long millis)25 public static void setTransitionPauseForDebugging(long millis) { 26 sTransitionPause = millis; 27 ResettersForTesting.register(() -> sTransitionPause = 0); 28 } 29 maybePauseAfterTransition(ConditionalState state)30 static void maybePauseAfterTransition(ConditionalState state) { 31 long pauseMs = sTransitionPause; 32 if (pauseMs > 0) { 33 ThreadUtils.runOnUiThread( 34 () -> { 35 Toast.makeText( 36 InstrumentationRegistry.getInstrumentation() 37 .getTargetContext(), 38 state.toString(), 39 Toast.LENGTH_SHORT) 40 .show(); 41 }); 42 try { 43 Log.e(TAG, "Pause for sightseeing %s for %dms", state, pauseMs); 44 Thread.sleep(pauseMs); 45 } catch (InterruptedException e) { 46 Log.e(TAG, "Interrupted pause", e); 47 } 48 } 49 } 50 } 51