Commit f1c22acf authored by Hazem Ashmawy's avatar Hazem Ashmawy Committed by Commit Bot

[AW][Dev-UI] Add some espresso tests for flag UI

Add tests for toggling flags and the persistent notification. Also
remove test batching for flags fragment tests to so the flags service
is killed when the process is killed leaving a clean state.

Fixed: 1130599
Test: run_webview_instrumentation_test_apk -f "*FlagsFragmentTest*"
Change-Id: I0cb416471d3b79e98ed9ef8ad5e760b4bfaa1083
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438534
Commit-Queue: Hazem Ashmawy <hazems@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814362}
parent 70f8f965
...@@ -57,7 +57,8 @@ import org.chromium.base.test.util.Feature; ...@@ -57,7 +57,8 @@ import org.chromium.base.test.util.Feature;
public class DeveloperUiTest { public class DeveloperUiTest {
// The package name of the test shell. This is acting both as the client app and the WebView // The package name of the test shell. This is acting both as the client app and the WebView
// provider. // provider.
private static final String TEST_WEBVIEW_PACKAGE_NAME = "org.chromium.android_webview.shell"; public static final String TEST_WEBVIEW_PACKAGE_NAME = "org.chromium.android_webview.shell";
public static final String TEST_WEBVIEW_APPLICATION_LABEL = "AwShellApplication";
@Rule @Rule
public IntentsTestRule mRule = new IntentsTestRule<MainActivity>(MainActivity.class); public IntentsTestRule mRule = new IntentsTestRule<MainActivity>(MainActivity.class);
......
...@@ -54,6 +54,8 @@ ...@@ -54,6 +54,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Don't actually try to launch with this alias: it only exists so we can query its enabled state. --> <!-- Don't actually try to launch with this alias: it only exists so we can query its enabled state. -->
<!-- If you change this component make sure to update the corresponding copy in
test/shell/AndroidManifest.xml -->
<activity-alias android:name="org.chromium.android_webview.devui.DeveloperModeState" <activity-alias android:name="org.chromium.android_webview.devui.DeveloperModeState"
android:targetActivity="org.chromium.android_webview.devui.MainActivity" android:targetActivity="org.chromium.android_webview.devui.MainActivity"
android:visibleToInstantApps="true" android:visibleToInstantApps="true"
...@@ -78,6 +80,8 @@ ...@@ -78,6 +80,8 @@
android:grantUriPermissions="true" android:grantUriPermissions="true"
android:process=":webview_apk" /> {# Explicit process required for monochrome compatibility. #} android:process=":webview_apk" /> {# Explicit process required for monochrome compatibility. #}
<!-- Disabled by default, enabled at runtime by Developer UI. --> <!-- Disabled by default, enabled at runtime by Developer UI. -->
<!-- If you change this component make sure to update the corresponding copy in
test/shell/AndroidManifest.xml-->
<provider android:name="org.chromium.android_webview.services.DeveloperModeContentProvider" <provider android:name="org.chromium.android_webview.services.DeveloperModeContentProvider"
android:visibleToInstantApps="true" android:visibleToInstantApps="true"
android:exported="true" android:exported="true"
......
...@@ -433,10 +433,11 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -433,10 +433,11 @@ public class FlagsFragment extends DevUiBaseFragment {
TextView flagName = toggleableFlag.findViewById(R.id.flag_name); TextView flagName = toggleableFlag.findViewById(R.id.flag_name);
if (state == /* STATE_DEFAULT */ 0) { if (state == /* STATE_DEFAULT */ 0) {
// Unset the compound drawable. // Unset the compound drawable.
flagName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); flagName.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
} else { // STATE_ENABLED or STATE_DISABLED } else { // STATE_ENABLED or STATE_DISABLED
// Draws a blue circle to the left of the text. // Draws a blue circle to the left of the text.
flagName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.blue_circle, 0, 0, 0); flagName.setCompoundDrawablesRelativeWithIntrinsicBounds(
R.drawable.blue_circle, 0, 0, 0);
} }
} }
......
...@@ -21,6 +21,8 @@ import android.os.IBinder; ...@@ -21,6 +21,8 @@ import android.os.IBinder;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import androidx.annotation.VisibleForTesting;
import org.chromium.android_webview.common.DeveloperModeUtils; import org.chromium.android_webview.common.DeveloperModeUtils;
import org.chromium.android_webview.common.Flag; import org.chromium.android_webview.common.Flag;
import org.chromium.android_webview.common.FlagOverrideHelper; import org.chromium.android_webview.common.FlagOverrideHelper;
...@@ -51,6 +53,11 @@ public final class DeveloperUiService extends Service { ...@@ -51,6 +53,11 @@ public final class DeveloperUiService extends Service {
private static final int FRAGMENT_ID_CRASHES = 1; private static final int FRAGMENT_ID_CRASHES = 1;
private static final int FRAGMENT_ID_FLAGS = 2; private static final int FRAGMENT_ID_FLAGS = 2;
public static final String NOTIFICATION_TITLE =
"WARNING: experimental WebView features enabled";
public static final String NOTIFICATION_CONTENT = "Tap to see experimental features.";
public static final String NOTIFICATION_TICKER = "Experimental WebView features enabled";
private static final Object sLock = new Object(); private static final Object sLock = new Object();
@GuardedBy("sLock") @GuardedBy("sLock")
private static Map<String, Boolean> sOverriddenFlags = new HashMap<>(); private static Map<String, Boolean> sOverriddenFlags = new HashMap<>();
...@@ -221,15 +228,14 @@ public final class DeveloperUiService extends Service { ...@@ -221,15 +228,14 @@ public final class DeveloperUiService extends Service {
notificationIntent.putExtra(FRAGMENT_ID_INTENT_EXTRA, FRAGMENT_ID_FLAGS); notificationIntent.putExtra(FRAGMENT_ID_INTENT_EXTRA, FRAGMENT_ID_FLAGS);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification.Builder builder = Notification.Builder builder = createNotificationBuilder()
createNotificationBuilder() .setContentTitle(NOTIFICATION_TITLE)
.setContentTitle("WARNING: experimental WebView features enabled") .setContentText(NOTIFICATION_CONTENT)
.setContentText("Tap to see experimental features.") .setSmallIcon(android.R.drawable.stat_notify_error)
.setSmallIcon(android.R.drawable.stat_notify_error) .setContentIntent(pendingIntent)
.setContentIntent(pendingIntent) .setOngoing(true)
.setOngoing(true) .setVisibility(Notification.VISIBILITY_PUBLIC)
.setVisibility(Notification.VISIBILITY_PUBLIC) .setTicker(NOTIFICATION_TICKER);
.setTicker("Experimental WebView features enabled");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
builder = builder builder = builder
...@@ -310,4 +316,14 @@ public final class DeveloperUiService extends Service { ...@@ -310,4 +316,14 @@ public final class DeveloperUiService extends Service {
FlagOverrideHelper helper = new FlagOverrideHelper(ProductionSupportedFlagList.sFlagList); FlagOverrideHelper helper = new FlagOverrideHelper(ProductionSupportedFlagList.sFlagList);
helper.applyFlagOverrides(newFlags); helper.applyFlagOverrides(newFlags);
} }
@VisibleForTesting
public static void clearSharedPrefsForTesting(Context context) {
synchronized (sLock) {
context.getSharedPreferences(DeveloperUiService.SHARED_PREFS_FILE, Context.MODE_PRIVATE)
.edit()
.clear()
.apply();
}
}
} }
...@@ -203,6 +203,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -203,6 +203,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"//third_party/android_deps:androidx_core_core_java", "//third_party/android_deps:androidx_core_core_java",
"//third_party/android_deps:androidx_fragment_fragment_java", "//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_test_runner_java", "//third_party/android_deps:androidx_test_runner_java",
"//third_party/android_deps:androidx_test_uiautomator_uiautomator_java",
"//third_party/android_deps:com_google_code_findbugs_jsr305_java", "//third_party/android_deps:com_google_code_findbugs_jsr305_java",
"//third_party/android_deps:com_google_guava_failureaccess_java", "//third_party/android_deps:com_google_guava_failureaccess_java",
"//third_party/android_deps:espresso_java", "//third_party/android_deps:espresso_java",
......
...@@ -84,5 +84,15 @@ ...@@ -84,5 +84,15 @@
android:exported="true" /> android:exported="true" />
<service android:name="org.chromium.android_webview.test.services.MockVariationsSeedServer" <service android:name="org.chromium.android_webview.test.services.MockVariationsSeedServer"
android:exported="true" /> android:exported="true" />
<!-- Components for DevTools Flags UI, make sure that any changes in these components reflect
the corresponding original components in nonembedded/java/AndroidManifest.xml -->
<provider android:name="org.chromium.android_webview.services.DeveloperModeContentProvider"
android:exported="true"
android:authorities="org.chromium.android_webview.shell.DeveloperModeContentProvider"/>
<service android:name="org.chromium.android_webview.services.DeveloperUiService"
android:exported="false" />
<activity-alias android:name="org.chromium.android_webview.devui.DeveloperModeState"
android:targetActivity="org.chromium.android_webview.shell.AwShellActivity"
android:enabled="false" />
</application> </application>
</manifest> </manifest>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment