aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Fischer <ntfschr@google.com>2019-04-25 17:45:11 -0700
committerNate Fischer <ntfschr@google.com>2019-04-25 21:46:31 -0700
commitd58611ec8a40c6137ea2319e404fc9914279c927 (patch)
treeeba4de33d9b272d9bf0afc496556c0ec82a333a5
parentd3e18a289993600c311a52484c467c09b63c3335 (diff)
downloadsupport-d58611ec8a40c6137ea2319e404fc9914279c927.tar.gz
AndroidX Webkit: add loud interstitials in testapp
No change to production, just testapp. This implements support for Loud (big, red) interstitials in our demo app, by pointing the WebView at the main page of the test site. This is mostly a copy of the standalone Safe Browsing test app. Bug: 124773936 Test: Manual - working as intended Change-Id: I4825f3a57581a9af01b32ea3c5c6f8073cb6c8ab
-rw-r--r--webkit/integration-tests/testapp/src/main/AndroidManifest.xml4
-rw-r--r--webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/LoudInterstitialActivity.java65
-rw-r--r--webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java3
-rw-r--r--webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingHelpers.java7
-rw-r--r--webkit/integration-tests/testapp/src/main/res/layout/activity_loud_interstitial.xml33
-rw-r--r--webkit/integration-tests/testapp/src/main/res/values/strings.xml1
6 files changed, 111 insertions, 2 deletions
diff --git a/webkit/integration-tests/testapp/src/main/AndroidManifest.xml b/webkit/integration-tests/testapp/src/main/AndroidManifest.xml
index aa226ac29bd..bba51641244 100644
--- a/webkit/integration-tests/testapp/src/main/AndroidManifest.xml
+++ b/webkit/integration-tests/testapp/src/main/AndroidManifest.xml
@@ -29,7 +29,6 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">
-
<!-- Top-level Activity -->
<activity android:name=".MainActivity">
<intent-filter>
@@ -49,6 +48,9 @@
android:name=".MediumInterstitialActivity"
android:exported="true" />
<activity
+ android:name=".LoudInterstitialActivity"
+ android:exported="true" />
+ <activity
android:name=".ProxyOverrideActivity"
android:exported="true" />
<activity
diff --git a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/LoudInterstitialActivity.java b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/LoudInterstitialActivity.java
new file mode 100644
index 00000000000..911efe84c51
--- /dev/null
+++ b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/LoudInterstitialActivity.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.androidx.webkit;
+
+import android.os.Bundle;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.webkit.WebSettingsCompat;
+import androidx.webkit.WebViewFeature;
+
+/**
+ * An {@link android.app.Activity} to demonstrate "Loud" interstitials. WebView displays a
+ * red (or grey) error page with considerable description when it's "full" sized (takes up almost
+ * the entire available device screen), and we believe it's likely the predominant part of the UI.
+ * <p>
+ * This {@link android.app.Activity} points to a safe page, but that page itself has links to
+ * (fake) malicious resources of various threat types, to allow testing each threat type. Within the
+ * interstitial, the user can click any of several links which provide more information about Safe
+ * Browsing overall, including "proceed" and "back to safety" buttons for navigation.
+ */
+public class LoudInterstitialActivity extends AppCompatActivity {
+
+ private WebView mWebView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_loud_interstitial);
+ setTitle(R.string.loud_interstitial_activity_title);
+ WebkitHelpers.appendWebViewVersionToTitle(this);
+
+ mWebView = findViewById(R.id.loud_webview);
+ mWebView.getSettings().setJavaScriptEnabled(true); // in case site needs JS to render
+ mWebView.setWebViewClient(new WebViewClient()); // allow mWebView to handle navigations
+ if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)) {
+ WebSettingsCompat.setSafeBrowsingEnabled(mWebView.getSettings(), true);
+ }
+ mWebView.loadUrl(SafeBrowsingHelpers.TEST_SAFE_BROWSING_SITE);
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (mWebView.canGoBack()) {
+ mWebView.goBack();
+ } else {
+ super.onBackPressed();
+ }
+ }
+}
diff --git a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
index 6d7d8b4a568..929f0a976e7 100644
--- a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
+++ b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
@@ -75,6 +75,9 @@ public class SafeBrowsingActivity extends AppCompatActivity {
getResources().getString(R.string.medium_tall_interstitial_activity_title),
new Intent(activityContext, MediumInterstitialActivity.class)
.putExtra(MediumInterstitialActivity.LAYOUT_HORIZONTAL, true)),
+ new MenuListView.MenuItem(
+ getResources().getString(R.string.loud_interstitial_activity_title),
+ new Intent(activityContext, LoudInterstitialActivity.class)),
};
listView.setItems(menuItems);
}
diff --git a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingHelpers.java b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingHelpers.java
index fc11af41175..ca4671c4300 100644
--- a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingHelpers.java
+++ b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingHelpers.java
@@ -23,7 +23,6 @@ import android.net.Uri;
*/
public final class SafeBrowsingHelpers {
public static final String TEST_SAFE_BROWSING_DOMAIN = "testsafebrowsing.appspot.com";
- // TODO(ntfschr): add URLs for each threat type.
public static final String MALWARE_URL = new Uri.Builder()
.scheme("http")
.authority(TEST_SAFE_BROWSING_DOMAIN)
@@ -48,6 +47,12 @@ public final class SafeBrowsingHelpers {
.path("/s/trick_to_bill.html")
.build()
.toString();
+ public static final String TEST_SAFE_BROWSING_SITE = new Uri.Builder()
+ .scheme("http")
+ .authority(TEST_SAFE_BROWSING_DOMAIN)
+ .path("/")
+ .build()
+ .toString();
// Do not instantiate this class.
private SafeBrowsingHelpers() {}
diff --git a/webkit/integration-tests/testapp/src/main/res/layout/activity_loud_interstitial.xml b/webkit/integration-tests/testapp/src/main/res/layout/activity_loud_interstitial.xml
new file mode 100644
index 00000000000..e44ce4d1ed5
--- /dev/null
+++ b/webkit/integration-tests/testapp/src/main/res/layout/activity_loud_interstitial.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/activity_loud_interstitial"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/colorBackground">
+
+ <WebView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/loud_webview"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/webkit/integration-tests/testapp/src/main/res/values/strings.xml b/webkit/integration-tests/testapp/src/main/res/values/strings.xml
index dd2d8e1ab92..f4c683e8cbb 100644
--- a/webkit/integration-tests/testapp/src/main/res/values/strings.xml
+++ b/webkit/integration-tests/testapp/src/main/res/values/strings.xml
@@ -27,5 +27,6 @@
<string name="small_interstitial_activity_title">Small Interstitial</string>
<string name="medium_tall_interstitial_activity_title">Medium (Tall) Interstitials</string>
<string name="medium_wide_interstitial_activity_title">Medium (Wide) Interstitials</string>
+ <string name="loud_interstitial_activity_title">Loud (Red) Interstitials</string>
<string name="cannot_start_safe_browsing">Unable to start Safe Browsing, this is unexpected.</string>
</resources>