blob: bc2ab808ea16a4ee4b1ce572dd398aca21847aa4 [file] [log] [blame]
Alice Leee4839c32015-09-04 15:11:35 -07001/*
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
17package android.assist.cts;
18
19import android.assist.common.Utils;
20
21import android.content.BroadcastReceiver;
22import android.content.Context;
23import android.content.Intent;
24import android.content.IntentFilter;
25import android.provider.Settings;
26import android.util.Log;
27
28import java.util.concurrent.CountDownLatch;
29import java.util.concurrent.TimeUnit;
30
31/**
32 * Test that the AssistStructure returned is properly formatted.
33 */
34
35public 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
43 public LargeViewHierarchyTest() {
44 super();
45 }
46
47 @Override
48 protected void setUp() throws Exception {
49 super.setUp();
50 setUpAndRegisterReceiver();
51 startTestActivity(TEST_CASE_TYPE);
52 }
53
54 @Override
55 public void tearDown() throws Exception {
56 super.tearDown();
57 if (mReceiver != null) {
58 mContext.unregisterReceiver(mReceiver);
59 mReceiver = null;
60 }
61 }
62
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
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
81 public void testTextView() throws Exception {
82 mTestActivity.start3pApp(TEST_CASE_TYPE);
83 mTestActivity.startTest(TEST_CASE_TYPE);
84 waitForAssistantToBeReady(mReadyLatch);
85 waitForOnResume();
86 startSession();
87 waitForContext();
88 verifyAssistDataNullness(false, false, false, false);
89
90 verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE),
91 false /*FLAG_SECURE set*/);
92 }
93
94 private class LargeViewTestBroadcastReceiver extends BroadcastReceiver {
95 @Override
96 public void onReceive(Context context, Intent intent) {
97 String action = intent.getAction();
98 if (action.equals(Utils.APP_3P_HASRESUMED) && mHasResumedLatch != null) {
99 mHasResumedLatch.countDown();
100 } else if (action.equals(Utils.ASSIST_RECEIVER_REGISTERED) && mReadyLatch != null) {
101 mReadyLatch.countDown();
102 }
103 }
104 }
105}