1 /* 2 * Copyright (C) 2024 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.resources.registerresourcepaths1; 18 19 import static org.junit.Assume.assumeTrue; 20 21 import android.webkit.WebView; 22 23 import androidx.test.annotation.UiThreadTest; 24 import androidx.test.ext.junit.rules.ActivityScenarioRule; 25 26 import com.android.compatibility.common.util.NullWebViewUtils; 27 import com.android.cts.webkit.WebViewStartupCtsActivity; 28 29 import org.junit.Assert; 30 import org.junit.Before; 31 import org.junit.Rule; 32 import org.junit.Test; 33 34 public class RegisterResourcePathsTest { 35 @Rule 36 public ActivityScenarioRule<WebViewStartupCtsActivity> mActivityRule = 37 new ActivityScenarioRule<>(WebViewStartupCtsActivity.class); 38 39 private WebViewStartupCtsActivity mActivity; 40 41 @Before setUp()42 public void setUp() { 43 mActivityRule.getScenario().onActivity(activity -> { 44 mActivity = activity; 45 }); 46 } 47 48 @Test 49 @UiThreadTest testWebViewInitialization()50 public void testWebViewInitialization() { 51 if (!NullWebViewUtils.isWebViewAvailable()) { 52 assumeTrue("WebView is not available on the device.", false); 53 } 54 mActivity.createAndAttachWebView(); 55 WebView webView = mActivity.getWebView(); 56 57 webView.clearHistory(); 58 Assert.assertNull(webView.getUrl()); 59 webView.loadUrl("http://fake.url/", null); 60 Assert.assertEquals("http://fake.url/", webView.getUrl()); 61 } 62 } 63