1 /* 2 * Copyright (C) 2017 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 com.android.cts.ephemeralapp1; 18 19 import android.content.pm.PackageManager; 20 import android.test.ActivityInstrumentationTestCase2; 21 import android.test.UiThreadTest; 22 23 import android.webkit.WebView; 24 import android.webkit.cts.WebViewOnUiThread; 25 26 public class WebViewTest extends ActivityInstrumentationTestCase2<WebViewTestActivity> { 27 28 private WebView mWebView; 29 private WebViewOnUiThread mOnUiThread; 30 31 public WebViewTest() { 32 super("com.android.cts.ephemeralapp1", WebViewTestActivity.class); 33 } 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 if (!hasWebViewFeature()) { 39 return; 40 } 41 final WebViewTestActivity activity = getActivity(); 42 mWebView = activity.getWebView(); 43 mOnUiThread = new WebViewOnUiThread(this, mWebView); 44 } 45 46 @Override 47 protected void tearDown() throws Exception { 48 if (mOnUiThread != null) { 49 mOnUiThread.cleanUp(); 50 } 51 super.tearDown(); 52 } 53 54 @UiThreadTest 55 public void testWebViewLoads() throws Exception { 56 // Webview is not supported on Watches 57 if (!hasWebViewFeature()) { 58 return; 59 } 60 mOnUiThread.loadUrlAndWaitForCompletion("about:blank"); 61 } 62 63 private boolean hasWebViewFeature() { 64 return getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WEBVIEW); 65 } 66 } 67