1 /* 2 * Copyright (C) 2023 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 package com.android.launcher3.tapl; 17 18 import androidx.test.uiautomator.UiObject2; 19 20 import com.android.launcher3.testing.shared.TestProtocol; 21 22 /** 23 * Container that can be used to input a search query and retrieve a {@link SearchResultFromQsb} 24 * instance. 25 */ 26 interface SearchInputSource { 27 String INPUT_RES = "input"; 28 29 /** Set the already focused search input edit text and update search results. */ searchForInput(String input)30 default SearchResultFromQsb searchForInput(String input) { 31 LauncherInstrumentation launcher = getLauncher(); 32 try (LauncherInstrumentation.Closable c = launcher.addContextLayer( 33 "want to search for result with an input"); 34 LauncherInstrumentation.Closable e = launcher.eventsCheck()) { 35 launcher.executeAndWaitForLauncherEvent( 36 () -> { 37 UiObject2 editText = launcher.waitForLauncherObject(INPUT_RES); 38 launcher.waitForObjectFocused(editText, "search input"); 39 editText.setText(input); 40 }, 41 event -> TestProtocol.SEARCH_RESULT_COMPLETE.equals(event.getClassName()), 42 () -> "Didn't receive a search result completed message", "searching"); 43 return getSearchResultForInput(); 44 } 45 } 46 47 /** This method requires public access, however should not be called in tests. */ getLauncher()48 LauncherInstrumentation getLauncher(); 49 50 /** This method requires public access, however should not be called in tests. */ getSearchResultForInput()51 SearchResultFromQsb getSearchResultForInput(); 52 } 53