1 /* 2 * Copyright (C) 2015 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.assist.cts; 18 19 import android.assist.common.AutoResetLatch; 20 import android.assist.common.Utils; 21 import android.os.Bundle; 22 import android.os.SystemClock; 23 import android.util.Log; 24 25 import org.junit.Test; 26 27 /** 28 * Test that the AssistStructure returned is properly formatted. 29 */ 30 public class TextViewTest extends AssistTestBase { 31 private static final String TAG = "TextViewTest"; 32 private static final String TEST_CASE_TYPE = Utils.TEXTVIEW; 33 34 @Override customSetup()35 protected void customSetup() throws Exception { 36 startTestActivity(TEST_CASE_TYPE); 37 } 38 39 @Test testTextView()40 public void testTextView() throws Exception { 41 if (mActivityManager.isLowRamDevice()) { 42 Log.d(TAG, "Not running assist tests on low-RAM device."); 43 return; 44 } 45 46 start3pApp(TEST_CASE_TYPE); 47 scrollTestApp(0, 0, true, false); 48 SystemClock.sleep(500); 49 50 // Verify that the text view contains the right text 51 startTest(TEST_CASE_TYPE); 52 waitForAssistantToBeReady(); 53 final AutoResetLatch latch1 = startSession(); 54 waitForContext(latch1); 55 verifyAssistDataNullness(false, false, false, false); 56 57 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), 58 false /*FLAG_SECURE set*/); 59 60 // Verify that the scroll position of the text view is accurate after scrolling. 61 scrollTestApp(10, 50, true /* scrollTextView */, false /* scrollScrollView */); 62 // TODO: Check if we can get TextView's position to expected position instead of waiting 63 SystemClock.sleep(500); 64 65 final AutoResetLatch latch2 = startSession(); 66 waitForContext(latch2); 67 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), false); 68 69 scrollTestApp(-1, -1, true, false); 70 // TODO: Check if we can get TextView's position to expected position instead of waiting 71 SystemClock.sleep(500); 72 73 final AutoResetLatch latch3 = startSession(); 74 waitForContext(latch3); 75 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), false); 76 77 scrollTestApp(0, 0, true, true); 78 // TODO: Check if we can get TextView's position to expected position instead of waiting 79 SystemClock.sleep(500); 80 81 final AutoResetLatch latch4 = startSession(); 82 waitForContext(latch4); 83 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), false); 84 85 scrollTestApp(10, 50, false, true); 86 // TODO: Check if we can get TextView's position to expected position instead of waiting 87 SystemClock.sleep(500); 88 89 final AutoResetLatch latch5 = startSession(); 90 waitForContext(latch5); 91 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), false); 92 } 93 94 @Override scrollTestApp(int scrollX, int scrollY, boolean scrollTextView, boolean scrollScrollView)95 protected void scrollTestApp(int scrollX, int scrollY, boolean scrollTextView, 96 boolean scrollScrollView) { 97 super.scrollTestApp(scrollX, scrollY, scrollTextView, scrollScrollView); 98 Bundle bundle = new Bundle(); 99 if (scrollTextView) { 100 bundle.putString(Utils.EXTRA_REMOTE_CALLBACK_ACTION, Utils.SCROLL_TEXTVIEW_ACTION); 101 } else if (scrollScrollView) { 102 bundle.putString(Utils.EXTRA_REMOTE_CALLBACK_ACTION, Utils.SCROLL_SCROLLVIEW_ACTION); 103 } 104 bundle.putInt(Utils.SCROLL_X_POSITION, scrollX); 105 bundle.putInt(Utils.SCROLL_Y_POSITION, scrollY); 106 m3pActivityCallback.sendResult(bundle); 107 } 108 } 109