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 org.junit.Assert.fail;
20 
21 import android.assist.common.AutoResetLatch;
22 import android.assist.common.Utils;
23 import android.content.pm.PackageManager;
24 import android.util.Log;
25 
26 import org.junit.Test;
27 
28 import java.util.concurrent.TimeUnit;
29 
30 /**
31  *  Test that the AssistStructure returned is properly formatted.
32  */
33 public class WebViewTest extends AssistTestBase {
34     private static final String TAG = "WebViewTest";
35     private static final String TEST_CASE_TYPE = Utils.WEBVIEW;
36 
37     private final AutoResetLatch mTestWebViewLatch = new AutoResetLatch();
38 
39     @Override
customSetup()40     protected void customSetup() throws Exception {
41         mActionLatchReceiver = new ActionLatchReceiver(Utils.TEST_ACTIVITY_WEBVIEW_LOADED, mTestWebViewLatch);
42         startTestActivity(TEST_CASE_TYPE);
43     }
44 
waitForTestActivity()45     private void waitForTestActivity() throws Exception {
46         Log.i(TAG, "waiting for webview in test activity to load");
47         if (!mTestWebViewLatch.await(Utils.ACTIVITY_ONRESUME_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
48             fail("failed to receive load web view in " + Utils.TIMEOUT_MS + "msec");
49         }
50     }
51 
52     @Test
testWebView()53     public void testWebView() throws Throwable {
54         if (mActivityManager.isLowRamDevice()) {
55             Log.d(TAG, "Not running assist tests on low-RAM device.");
56             return;
57         }
58         if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WEBVIEW)) {
59             return;
60         }
61         start3pApp(TEST_CASE_TYPE);
62         startTest(TEST_CASE_TYPE);
63         waitForAssistantToBeReady();
64         waitForTestActivity();
65 
66         eventuallyWithSessionClose(() -> {
67             waitForContext(startSession());
68             verifyAssistDataNullness(false, false, false, false);
69             verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE),
70                     false /*FLAG_SECURE set*/);
71             verifyAssistStructureHasWebDomain(Utils.WEBVIEW_HTML_DOMAIN);
72             verifyAssistStructureHasLocaleList(Utils.WEBVIEW_LOCALE_LIST);
73         });
74     }
75 }
76