Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.autofillservice.cts;
     18 
     19 import com.android.compatibility.common.util.Timeout;
     20 
     21 /**
     22  * Timeouts for common tasks.
     23  */
     24 public final class Timeouts {
     25 
     26     private static final long ONE_TIMEOUT_TO_RULE_THEN_ALL_MS = 20_000;
     27     private static final long ONE_NAPTIME_TO_RULE_THEN_ALL_MS = 2_000;
     28 
     29     static final long MOCK_IME_TIMEOUT_MS = 5_000;
     30 
     31     /**
     32      * Timeout until framework binds / unbinds from service.
     33      */
     34     public static final Timeout CONNECTION_TIMEOUT = new Timeout("CONNECTION_TIMEOUT",
     35             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     36 
     37     /**
     38      * Timeout for {@link MyAutofillCallback#assertNotCalled()} - test will sleep for that amount of
     39      * time as there is no callback that be received to assert it's not shown.
     40      */
     41     static final long CALLBACK_NOT_CALLED_TIMEOUT_MS = ONE_NAPTIME_TO_RULE_THEN_ALL_MS;
     42 
     43     /**
     44      * Timeout until framework unbinds from a service.
     45      */
     46     // TODO: must be higher than RemoteFillService.TIMEOUT_IDLE_BIND_MILLIS, so we should use a
     47     // @hidden @Testing constants instead...
     48     static final Timeout IDLE_UNBIND_TIMEOUT = new Timeout("IDLE_UNBIND_TIMEOUT",
     49             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     50 
     51     /**
     52      * Timeout to get the expected number of fill events.
     53      */
     54     static final Timeout FILL_EVENTS_TIMEOUT = new Timeout("FILL_EVENTS_TIMEOUT",
     55             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     56 
     57     /**
     58      * Timeout for expected autofill requests.
     59      */
     60     static final Timeout FILL_TIMEOUT = new Timeout("FILL_TIMEOUT", ONE_TIMEOUT_TO_RULE_THEN_ALL_MS,
     61             2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     62 
     63     /**
     64      * Timeout for expected save requests.
     65      */
     66     static final Timeout SAVE_TIMEOUT = new Timeout("SAVE_TIMEOUT", ONE_TIMEOUT_TO_RULE_THEN_ALL_MS,
     67             2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     68 
     69     /**
     70      * Timeout used when save is not expected to be shown - test will sleep for that amount of time
     71      * as there is no callback that be received to assert it's not shown.
     72      */
     73     static final long SAVE_NOT_SHOWN_NAPTIME_MS = ONE_NAPTIME_TO_RULE_THEN_ALL_MS;
     74 
     75     /**
     76      * Timeout for UI operations. Typically used by {@link UiBot}.
     77      */
     78     static final Timeout UI_TIMEOUT = new Timeout("UI_TIMEOUT", ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F,
     79             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
     80 
     81     /**
     82      * Timeout for a11y window change events.
     83      */
     84     static final long WINDOW_CHANGE_TIMEOUT_MS = ONE_TIMEOUT_TO_RULE_THEN_ALL_MS;
     85 
     86     /**
     87      * Timeout used when an a11y window change events is not expected to be generated - test will
     88      * sleep for that amount of time as there is no callback that be received to assert it's not
     89      * shown.
     90      */
     91     static final long WINDOW_CHANGE_NOT_GENERATED_NAPTIME_MS = ONE_NAPTIME_TO_RULE_THEN_ALL_MS;
     92 
     93     /**
     94      * Timeout for webview operations. Typically used by {@link UiBot}.
     95      */
     96     // TODO(b/80317628): switch back to ONE_TIMEOUT_TO_RULE_THEN_ALL_MS once fixed...
     97     static final Timeout WEBVIEW_TIMEOUT = new Timeout("WEBVIEW_TIMEOUT", 3_000, 2F, 5_000);
     98 
     99     /**
    100      * Timeout for showing the autofill dataset picker UI.
    101      *
    102      * <p>The value is usually higher than {@link #UI_TIMEOUT} because the performance of the
    103      * dataset picker UI can be affect by external factors in some low-level devices.
    104      *
    105      * <p>Typically used by {@link UiBot}.
    106      */
    107     static final Timeout UI_DATASET_PICKER_TIMEOUT = new Timeout("UI_DATASET_PICKER_TIMEOUT",
    108             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
    109 
    110     /**
    111      * Timeout used when the dataset picker is not expected to be shown - test will sleep for that
    112      * amount of time as there is no callback that be received to assert it's not shown.
    113      */
    114     static final long DATASET_PICKER_NOT_SHOWN_NAPTIME_MS = ONE_NAPTIME_TO_RULE_THEN_ALL_MS;
    115 
    116     /**
    117      * Timeout (in milliseconds) for an activity to be brought out to top.
    118      */
    119     static final Timeout ACTIVITY_RESURRECTION = new Timeout("ACTIVITY_RESURRECTION",
    120             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F, ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
    121 
    122     /**
    123      * Timeout for changing the screen orientation.
    124      */
    125     static final Timeout UI_SCREEN_ORIENTATION_TIMEOUT = new Timeout(
    126             "UI_SCREEN_ORIENTATION_TIMEOUT", ONE_TIMEOUT_TO_RULE_THEN_ALL_MS, 2F,
    127             ONE_TIMEOUT_TO_RULE_THEN_ALL_MS);
    128 
    129     private Timeouts() {
    130         throw new UnsupportedOperationException("contain static methods only");
    131     }
    132 }
    133