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.Utils; 20 21 import android.content.BroadcastReceiver; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.IntentFilter; 25 import android.provider.Settings; 26 import android.util.Log; 27 28 import java.util.concurrent.CountDownLatch; 29 import java.util.concurrent.TimeUnit; 30 31 /** 32 * Test that the AssistStructure returned is properly formatted. 33 */ 34 35 public class LargeViewHierarchyTest extends AssistTestBase { 36 private static final String TAG = "LargeViewHierarchyTest"; 37 private static final String TEST_CASE_TYPE = Utils.LARGE_VIEW_HIERARCHY; 38 39 private BroadcastReceiver mReceiver; 40 private CountDownLatch mHasResumedLatch = new CountDownLatch(1); 41 private CountDownLatch mReadyLatch = new CountDownLatch(1); 42 LargeViewHierarchyTest()43 public LargeViewHierarchyTest() { 44 super(); 45 } 46 47 @Override setUp()48 protected void setUp() throws Exception { 49 super.setUp(); 50 setUpAndRegisterReceiver(); 51 startTestActivity(TEST_CASE_TYPE); 52 } 53 54 @Override tearDown()55 public void tearDown() throws Exception { 56 super.tearDown(); 57 if (mReceiver != null) { 58 mContext.unregisterReceiver(mReceiver); 59 mReceiver = null; 60 } 61 } 62 setUpAndRegisterReceiver()63 private void setUpAndRegisterReceiver() { 64 if (mReceiver != null) { 65 mContext.unregisterReceiver(mReceiver); 66 } 67 mReceiver = new LargeViewTestBroadcastReceiver(); 68 IntentFilter filter = new IntentFilter(); 69 filter.addAction(Utils.APP_3P_HASRESUMED); 70 filter.addAction(Utils.ASSIST_RECEIVER_REGISTERED); 71 mContext.registerReceiver(mReceiver, filter); 72 } 73 waitForOnResume()74 private void waitForOnResume() throws Exception { 75 Log.i(TAG, "waiting for onResume() before continuing"); 76 if (!mHasResumedLatch.await(Utils.ACTIVITY_ONRESUME_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { 77 fail("Activity failed to resume in " + Utils.ACTIVITY_ONRESUME_TIMEOUT_MS + "msec"); 78 } 79 } 80 testTextView()81 public void testTextView() throws Exception { 82 if (mActivityManager.isLowRamDevice()) { 83 Log.d(TAG, "Not running assist tests on low-RAM device."); 84 return; 85 } 86 mTestActivity.start3pApp(TEST_CASE_TYPE); 87 mTestActivity.startTest(TEST_CASE_TYPE); 88 waitForAssistantToBeReady(mReadyLatch); 89 waitForOnResume(); 90 startSession(); 91 waitForContext(); 92 verifyAssistDataNullness(false, false, false, false); 93 94 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), 95 false /*FLAG_SECURE set*/); 96 } 97 98 private class LargeViewTestBroadcastReceiver extends BroadcastReceiver { 99 @Override onReceive(Context context, Intent intent)100 public void onReceive(Context context, Intent intent) { 101 String action = intent.getAction(); 102 if (action.equals(Utils.APP_3P_HASRESUMED) && mHasResumedLatch != null) { 103 mHasResumedLatch.countDown(); 104 } else if (action.equals(Utils.ASSIST_RECEIVER_REGISTERED) && mReadyLatch != null) { 105 mReadyLatch.countDown(); 106 } 107 } 108 } 109 } 110