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 static com.google.common.truth.Truth.assertThat;
20 
21 import static org.junit.Assert.fail;
22 
23 import android.assist.common.AutoResetLatch;
24 import android.assist.common.Utils;
25 import android.graphics.Point;
26 import android.os.Bundle;
27 import android.util.Log;
28 
29 import org.junit.Test;
30 import org.junit.Ignore;
31 
32 import java.util.concurrent.TimeUnit;
33 
34 /** Test verifying the Content View of the Assistant */
35 public class AssistantContentViewTest extends AssistTestBase {
36     private static final String TAG = "ContentViewTest";
37     private AutoResetLatch mContentViewLatch = new AutoResetLatch(1);
38     private Bundle mBundle;
39 
40     @Override
customSetup()41     protected void customSetup() throws Exception {
42         mActionLatchReceiver = new AssistantReceiver();
43         startTestActivity(Utils.VERIFY_CONTENT_VIEW);
44     }
45 
46     @Override
customTearDown()47     protected void customTearDown() throws Exception {
48         mBundle = null;
49     }
50 
waitForContentView()51     private void waitForContentView() throws Exception {
52         Log.i(TAG, "waiting for the Assistant's Content View  before continuing");
53         if (!mContentViewLatch.await(Utils.TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
54             fail("failed to receive content view in " + Utils.TIMEOUT_MS + "msec");
55         }
56     }
57 
58     @Test
59     @Ignore("b/349497368")
testAssistantContentViewDimens()60     public void testAssistantContentViewDimens() throws Exception {
61         if (mActivityManager.isLowRamDevice()) {
62           Log.d(TAG, "Not running assist tests on low-RAM device.");
63           return;
64         }
65         startTest(Utils.VERIFY_CONTENT_VIEW);
66         waitForAssistantToBeReady();
67         startSession();
68         waitForContentView();
69         int height = mBundle.getInt(Utils.EXTRA_CONTENT_VIEW_HEIGHT, 0);
70         int width = mBundle.getInt(Utils.EXTRA_CONTENT_VIEW_WIDTH, 0);
71         Point displayPoint = mBundle.getParcelable(Utils.EXTRA_DISPLAY_POINT);
72         assertThat(height).isEqualTo(displayPoint.y);
73         assertThat(width).isEqualTo(displayPoint.x);
74     }
75 
76     private class AssistantReceiver extends ActionLatchReceiver {
77 
AssistantReceiver()78         AssistantReceiver() {
79             super(Utils.BROADCAST_CONTENT_VIEW_HEIGHT, mContentViewLatch);
80         }
81 
82         @Override
onAction(Bundle bundle, String action)83         protected void onAction(Bundle bundle, String action) {
84             mBundle = bundle;
85             super.onAction(bundle, action);
86         }
87     }
88 }
89