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