Adds new test for notification.
1. Add notification test. 2. Add shareUserId into manifest file. Test: atest com.android.settings.notification.AppNotificationComponentTest Bug: 184814161 Change-Id: I38b7a854e8c8e0777fb7be3a518b7ed9d0f0a7a6
This commit is contained in:
@@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
|
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
|
||||||
package="com.android.settings.tests.component">
|
package="com.android.settings.tests.component"
|
||||||
|
android:sharedUserId="android.uid.systemui">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
|
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.android.settings.notification;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.app.Instrumentation;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import androidx.test.filters.SmallTest;
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import androidx.test.runner.lifecycle.Stage;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.UiUtils;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@SmallTest
|
||||||
|
public class AppNotificationComponentTest {
|
||||||
|
private static final String TAG =
|
||||||
|
AppNotificationComponentTest.class.getSimpleName();
|
||||||
|
private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||||
|
private final String mNoSlientAppName = "com.google.android.dialer";
|
||||||
|
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ActivityScenarioRule<com.android.settings.Settings.AppNotificationSettingsActivity>
|
||||||
|
rule = new ActivityScenarioRule<>(
|
||||||
|
new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||||
|
.putExtra(Settings.EXTRA_APP_PACKAGE, mNoSlientAppName)
|
||||||
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_special_app_could_not_disable_notification() {
|
||||||
|
ActivityScenario ac = rule.getScenario();
|
||||||
|
ac.onActivity(
|
||||||
|
activity -> {
|
||||||
|
View rv = activity.findViewById(R.id.recycler_view);
|
||||||
|
|
||||||
|
UiUtils.waitUntilCondition(5000,
|
||||||
|
() -> rv.findViewById(R.id.main_switch_bar) != null);
|
||||||
|
|
||||||
|
View mainSwitchBar = rv.findViewById(R.id.main_switch_bar);
|
||||||
|
|
||||||
|
assertThat(mainSwitchBar.isEnabled()).isEqualTo(false);
|
||||||
|
|
||||||
|
UiUtils.waitForActivitiesInStage(1000, Stage.RESUMED);
|
||||||
|
|
||||||
|
for (int i = 0; i < ((ViewGroup) rv).getChildCount(); i++) {
|
||||||
|
if (((ViewGroup) rv).getChildAt(i) instanceof LinearLayout) {
|
||||||
|
Switch sWidget = rv.findViewById(R.id.switchWidget);
|
||||||
|
if (sWidget != null) {
|
||||||
|
assertThat(sWidget.isEnabled()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -17,8 +17,11 @@
|
|||||||
package com.android.settings.testutils;
|
package com.android.settings.testutils;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
|
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
|
||||||
import androidx.test.runner.lifecycle.Stage;
|
import androidx.test.runner.lifecycle.Stage;
|
||||||
|
|
||||||
@@ -27,6 +30,7 @@ import java.util.Collection;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class UiUtils {
|
public class UiUtils {
|
||||||
|
private static final String TAG = "UI_UTILS";
|
||||||
|
|
||||||
public static void waitUntilCondition(long timeoutInMillis, Supplier<Boolean> condition) {
|
public static void waitUntilCondition(long timeoutInMillis, Supplier<Boolean> condition) {
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
@@ -42,17 +46,48 @@ public class UiUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (System.nanoTime() - start >= (timeoutInMillis * 1000000)) {
|
||||||
|
Log.w(TAG, "Condition not match and timeout for waiting " + timeoutInMillis + "(ms).");
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Condition matched.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean waitForActivitiesInStage(long timeoutInMillis, Stage stage) {
|
public static boolean waitForActivitiesInStage(long timeoutInMillis, Stage stage) {
|
||||||
final Collection<Activity> activities = new ArrayList<>();
|
final Collection<Activity> activities = new ArrayList<>();
|
||||||
waitUntilCondition(Constants.ACTIVITY_LAUNCH_WAIT_TIMEOUT, () -> {
|
waitUntilCondition(Constants.ACTIVITY_LAUNCH_WAIT_TIMEOUT, () -> {
|
||||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> activities.addAll(
|
activities.addAll(
|
||||||
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(
|
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(
|
||||||
Stage.RESUMED)));
|
Stage.RESUMED));
|
||||||
return activities.size() > 0;
|
return activities.size() > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
return activities.size() > 0;
|
return activities.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void dumpView(View view) {
|
||||||
|
dumpViewRecursive(view, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static View getFirstViewFromActivity(Activity activity) {
|
||||||
|
return ((FragmentActivity) activity).getSupportFragmentManager().getFragments().get(
|
||||||
|
0).getView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dumpViewRecursive(View view, int layer, int index, int total) {
|
||||||
|
if (view instanceof ViewGroup) {
|
||||||
|
Log.i(TAG, "L[" + layer + "] PARENT -> " + (index + 1) + "/" + total + " >> "
|
||||||
|
+ view.toString());
|
||||||
|
System.out.println(
|
||||||
|
TAG + " L[" + layer + "] PARENT -> " + (index + 1) + "/" + total + " >> "
|
||||||
|
+ view.toString());
|
||||||
|
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
|
||||||
|
dumpViewRecursive(((ViewGroup) view).getChildAt(i), layer + 1, i + 1,
|
||||||
|
((ViewGroup) view).getChildCount());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "L[" + layer + "] =END= -> " + (index + 1) + "/" + total + " >> "
|
||||||
|
+ view.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user