summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.bp55
-rw-r--r--tests/Android.mk61
-rw-r--r--tests/src/com/android/wallpaper/picker/PreviewActivityTest.java30
-rw-r--r--tests/src/com/android/wallpaper/picker/individual/IndividualPickerActivityTest.java86
-rw-r--r--tests/src/com/android/wallpaper/testing/TestAsset.java2
-rw-r--r--tests/src/com/android/wallpaper/testing/TestBitmapCropper.java4
-rw-r--r--tests/src/com/android/wallpaper/testing/TestCategoryProvider.java8
-rw-r--r--tests/src/com/android/wallpaper/testing/TestInjector.java11
-rw-r--r--tests/src/com/android/wallpaper/testing/TestUserEventLogger.java4
-rw-r--r--tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java2
10 files changed, 156 insertions, 107 deletions
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..5d291be
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,55 @@
+// 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.
+//
+
+//
+// Build rule for WallpaperPicker2 tests
+//
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "WallpaperPicker2Tests",
+
+ static_libs: [
+ "androidx.annotation_annotation",
+ "androidx.test.core",
+ "androidx.test.runner",
+ "androidx.test.rules",
+ "androidx.test.espresso.contrib",
+ "androidx.test.espresso.intents",
+ "mockito-target-minus-junit4",
+ "androidx.test.espresso.core",
+ "hamcrest-library",
+ "hamcrest",
+ "wallpaper-common-deps",
+ ],
+
+ platform_apis: true,
+
+
+ optimize: {
+ enabled: false,
+ },
+
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
+
+ manifest: "AndroidManifest.xml",
+
+ instrumentation_for: "WallpaperPicker2",
+}
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index ee7e5f3..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,61 +0,0 @@
-# Copyright (C) 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-#
-# Build rule for WallpaperPicker2 tests
-#
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
- androidx.annotation_annotation \
- androidx.test.core \
- androidx.test.runner \
- androidx.test.rules \
- androidx.test.espresso.contrib \
- androidx.test.espresso.intents \
- mockito-target-minus-junit4 \
- androidx.test.espresso.core \
- hamcrest-library \
- hamcrest
-
-ifneq (,$(wildcard frameworks/base))
- LOCAL_PRIVATE_PLATFORM_APIS := true
-else
- LOCAL_SDK_VERSION := 29
- LOCAL_MIN_SDK_VERSION := 26
-endif
-
-LOCAL_PROGUARD_ENABLED := disabled
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_STATIC_ANDROID_LIBRARIES := WallpaperPicker2CommonDepsLib
-
-LOCAL_FULL_LIBS_MANIFEST_FILES := $(LOCAL_PATH)/AndroidManifest.xml
-LOCAL_MANIFEST_FILE := AndroidManifest.xml
-
-LOCAL_INSTRUMENTATION_FOR := WallpaperPicker2
-
-LOCAL_PACKAGE_NAME := WallpaperPicker2Tests
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-
-include $(BUILD_PACKAGE)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/src/com/android/wallpaper/picker/PreviewActivityTest.java b/tests/src/com/android/wallpaper/picker/PreviewActivityTest.java
index 98855fa..eee481a 100644
--- a/tests/src/com/android/wallpaper/picker/PreviewActivityTest.java
+++ b/tests/src/com/android/wallpaper/picker/PreviewActivityTest.java
@@ -147,7 +147,7 @@ public class PreviewActivityTest {
launchActivityIntentWithMockWallpaper();
assertNull(mWallpaperPersister.getCurrentHomeWallpaper());
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Home screen".
onView(withText(R.string.set_wallpaper_home_screen_destination)).perform(click());
@@ -175,7 +175,7 @@ public class PreviewActivityTest {
launchActivityIntentWithMockWallpaper();
assertNull(mWallpaperPersister.getCurrentLockWallpaper());
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Lock screen."
onView(withText(R.string.set_wallpaper_lock_screen_destination)).perform(click());
@@ -204,7 +204,7 @@ public class PreviewActivityTest {
assertNull(mWallpaperPersister.getCurrentHomeWallpaper());
assertNull(mWallpaperPersister.getCurrentLockWallpaper());
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Both."
onView(withText(R.string.set_wallpaper_both_destination)).perform(click());
@@ -237,7 +237,7 @@ public class PreviewActivityTest {
mWallpaperPersister.setFailNextCall(true);
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Home screen."
onView(withText(R.string.set_wallpaper_home_screen_destination)).perform(click());
@@ -276,7 +276,7 @@ public class PreviewActivityTest {
mWallpaperPersister.setFailNextCall(true);
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Lock screen."
onView(withText(R.string.set_wallpaper_lock_screen_destination)).perform(click());
@@ -316,7 +316,7 @@ public class PreviewActivityTest {
mWallpaperPersister.setFailNextCall(true);
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Both."
onView(withText(R.string.set_wallpaper_both_destination)).perform(click());
@@ -355,7 +355,7 @@ public class PreviewActivityTest {
// Scale should not have a meaningful value before clicking "set wallpaper".
assertTrue(mWallpaperPersister.getScale() < 0);
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Home screen".
onView(withText(R.string.set_wallpaper_home_screen_destination)).perform(click());
@@ -380,7 +380,7 @@ public class PreviewActivityTest {
throws Throwable {
launchActivityIntentWithMockWallpaper();
mWallpaperPersister.setFailNextCall(true);
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Home screen".
onView(withText(R.string.set_wallpaper_home_screen_destination)).perform(click());
@@ -396,7 +396,7 @@ public class PreviewActivityTest {
@Test
public void testClickSetWallpaper_ShowsDestinationDialog() {
launchActivityIntentWithMockWallpaper();
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
onView(withText(R.string.set_wallpaper_dialog_message)).check(matches(isDisplayed()));
}
@@ -451,7 +451,7 @@ public class PreviewActivityTest {
assertNotEquals(ActivityInfo.SCREEN_ORIENTATION_LOCKED, activity.getRequestedOrientation());
// Show SetWallpaperDialog.
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LOCKED, activity.getRequestedOrientation());
@@ -468,7 +468,7 @@ public class PreviewActivityTest {
assertNotEquals(ActivityInfo.SCREEN_ORIENTATION_LOCKED, activity.getRequestedOrientation());
// Show SetWallpaperDialog.
- onView(withId(R.id.preview_attribution_pane_set_wallpaper_button)).perform(click());
+ onView(withId(R.id.action_apply)).perform(click());
// Destination dialog is shown; click "Home screen".
onView(withText(R.string.set_wallpaper_home_screen_destination)).perform(click());
@@ -486,13 +486,13 @@ public class PreviewActivityTest {
launchActivityIntentWithMockWallpaper();
PreviewActivity activity = mActivityRule.getActivity();
- TextView titleView = activity.findViewById(R.id.preview_attribution_pane_title);
+ TextView titleView = activity.findViewById(R.id.wallpaper_info_title);
assertEquals("Title", titleView.getText());
- TextView subtitle1View = activity.findViewById(R.id.preview_attribution_pane_subtitle1);
+ TextView subtitle1View = activity.findViewById(R.id.wallpaper_info_subtitle1);
assertEquals("Subtitle 1", subtitle1View.getText());
- TextView subtitle2View = activity.findViewById(R.id.preview_attribution_pane_subtitle2);
+ TextView subtitle2View = activity.findViewById(R.id.wallpaper_info_subtitle2);
assertEquals("Subtitle 2", subtitle2View.getText());
}
@@ -522,7 +522,7 @@ public class PreviewActivityTest {
mExploreIntentChecker.setViewHandlerExists(false);
launchActivityIntentWithMockWallpaper();
- onView(withId(R.id.preview_attribution_pane_explore_button)).check(
+ onView(withId(R.id.wallpaper_info_explore_button)).check(
matches(not(isDisplayed())));
}
}
diff --git a/tests/src/com/android/wallpaper/picker/individual/IndividualPickerActivityTest.java b/tests/src/com/android/wallpaper/picker/individual/IndividualPickerActivityTest.java
index c9170bc..93c2b01 100644
--- a/tests/src/com/android/wallpaper/picker/individual/IndividualPickerActivityTest.java
+++ b/tests/src/com/android/wallpaper/picker/individual/IndividualPickerActivityTest.java
@@ -42,7 +42,6 @@ import android.content.Context;
import android.content.Intent;
import androidx.recyclerview.widget.RecyclerView;
-import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.intent.Intents;
import androidx.test.filters.MediumTest;
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
@@ -55,7 +54,6 @@ import com.android.wallpaper.model.PickerIntentFactory;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.model.WallpaperRotationInitializer;
import com.android.wallpaper.model.WallpaperRotationInitializer.RotationInitializationState;
-import com.android.wallpaper.module.FormFactorChecker;
import com.android.wallpaper.module.Injector;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.testing.TestCategoryProvider;
@@ -63,6 +61,7 @@ import com.android.wallpaper.testing.TestFormFactorChecker;
import com.android.wallpaper.testing.TestInjector;
import com.android.wallpaper.testing.TestWallpaperCategory;
import com.android.wallpaper.testing.TestWallpaperInfo;
+import com.android.wallpaper.testing.TestWallpaperPreferences;
import com.android.wallpaper.testing.TestWallpaperRotationInitializer;
import org.hamcrest.Matcher;
@@ -99,6 +98,9 @@ public class IndividualPickerActivityTest {
private TestWallpaperCategory mTestCategory;
+ private TestWallpaperPreferences mPreferences;
+ private ArrayList<WallpaperInfo> mWallpapers;
+
@Rule
public ActivityTestRule<IndividualPickerActivity> mActivityRule =
new ActivityTestRule<>(IndividualPickerActivity.class, false, false);
@@ -116,6 +118,15 @@ public class IndividualPickerActivityTest {
sWallpaperInfo1.setAttributions(Arrays.asList(
"Attribution 0", "Attribution 1", "Attribution 2"));
+
+ sWallpaperInfo1.setCollectionId("collection");
+
+ mPreferences = (TestWallpaperPreferences) mInjector.getPreferences(context);
+
+ mWallpapers = new ArrayList<>();
+ mWallpapers.add(sWallpaperInfo1);
+ mWallpapers.add(sWallpaperInfo2);
+ mWallpapers.add(sWallpaperInfo3);
}
@After
@@ -136,15 +147,8 @@ public class IndividualPickerActivityTest {
private void setActivityWithMockWallpapers(boolean isRotationEnabled,
@RotationInitializationState int rotationState) {
- sWallpaperInfo1.setCollectionId("collection");
-
- ArrayList<WallpaperInfo> wallpapers = new ArrayList<>();
- wallpapers.add(sWallpaperInfo1);
- wallpapers.add(sWallpaperInfo2);
- wallpapers.add(sWallpaperInfo3);
-
mTestCategory = new TestWallpaperCategory(
- "Test category", "collection", wallpapers, 0 /* priority */);
+ "Test category", "collection", mWallpapers, 0 /* priority */);
mTestCategory.setIsRotationEnabled(isRotationEnabled);
mTestCategory.setRotationInitializationState(rotationState);
@@ -176,22 +180,6 @@ public class IndividualPickerActivityTest {
}
@Test
- public void testClickTile_Mobile_showsBottomActions() {
- mTestFormFactorChecker.setFormFactor(FormFactorChecker.FORM_FACTOR_MOBILE);
-
- setActivityWithMockWallpapers(false /* isRotationEnabled */,
- WallpaperRotationInitializer.ROTATION_NOT_INITIALIZED);
- getActivity();
-
- onView(withId(R.id.wallpaper_grid)).perform(
- RecyclerViewActions.actionOnItemAtPosition(0, click()));
-
- onView(withId(R.id.action_back)).check(matches(isDisplayed()));
- onView(withId(R.id.action_information)).check(matches(isDisplayed()));
- onView(withId(R.id.action_apply)).check(matches(isDisplayed()));
- }
-
- @Test
public void testClickDailyRefreshAction_ShowsStartRotationDialog() {
setActivityWithMockWallpapers(true /* isRotationEnabled */,
WallpaperRotationInitializer.ROTATION_NOT_INITIALIZED);
@@ -406,4 +394,50 @@ public class IndividualPickerActivityTest {
assertEquals("Attribution 0", holder.itemView.findViewById(R.id.tile)
.getContentDescription());
}
+
+ /**
+ * Tests whether the selected wallpaper has a clipped thumbnail: first wallpaper.
+ */
+ @Test
+ public void testSelectFirstWallpaper_ShowsClippedThumbnail() {
+ runSelectWallpaperTest(0);
+ }
+
+ /**
+ * Tests whether the selected wallpaper has a clipped thumbnail: second wallpaper.
+ */
+ @Test
+ public void testSelectSecondWallpaper_ShowsClippedThumbnail() {
+ runSelectWallpaperTest(1);
+ }
+
+ /**
+ * Tests whether the selected wallpaper has a clipped thumbnail: third wallpaper.
+ */
+ @Test
+ public void testSelectThirdWallpaper_ShowsClippedThumbnail() {
+ runSelectWallpaperTest(2);
+ }
+
+ private void runSelectWallpaperTest(int selectedWallpaperIndex) {
+ mPreferences.setHomeWallpaperRemoteId(
+ mWallpapers.get(selectedWallpaperIndex).getWallpaperId());
+
+ setActivityWithMockWallpapers(false /* isRotationEnabled */,
+ WallpaperRotationInitializer.ROTATION_NOT_INITIALIZED);
+ IndividualPickerActivity activity = getActivity();
+
+ RecyclerView recyclerView = activity.findViewById(R.id.wallpaper_grid);
+
+ for (int index = 0; index < 3; index++) {
+ assertNotNull(recyclerView.findViewHolderForAdapterPosition(index));
+
+ CustomShapeImageView thumbnail =
+ recyclerView.findViewHolderForAdapterPosition(index)
+ .itemView.findViewById(R.id.thumbnail);
+
+ // Assert that only the selected wallpaper has a clipped thumbnail.
+ assertEquals(thumbnail.getClipped(), index == selectedWallpaperIndex);
+ }
+ }
}
diff --git a/tests/src/com/android/wallpaper/testing/TestAsset.java b/tests/src/com/android/wallpaper/testing/TestAsset.java
index 368919a..505946a 100644
--- a/tests/src/com/android/wallpaper/testing/TestAsset.java
+++ b/tests/src/com/android/wallpaper/testing/TestAsset.java
@@ -62,7 +62,7 @@ public final class TestAsset extends Asset {
@Override
public void decodeBitmapRegion(Rect unused, int targetWidth, int targetHeight,
- BitmapReceiver receiver) {
+ boolean shouldAdjustForRtl, BitmapReceiver receiver) {
receiver.onBitmapDecoded(mBitmap);
}
diff --git a/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java b/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java
index 7daeeab..778561d 100644
--- a/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java
+++ b/tests/src/com/android/wallpaper/testing/TestBitmapCropper.java
@@ -34,7 +34,7 @@ public class TestBitmapCropper implements BitmapCropper {
}
@Override
- public void cropAndScaleBitmap(Asset asset, float scale, Rect cropRect,
+ public void cropAndScaleBitmap(Asset asset, float scale, Rect cropRect, boolean adjustRtl,
Callback callback) {
if (mFailNextCall) {
callback.onError(null /* throwable */);
@@ -47,7 +47,7 @@ public class TestBitmapCropper implements BitmapCropper {
Math.round((float) cropRect.right / scale),
Math.round((float) cropRect.bottom / scale));
- asset.decodeBitmapRegion(scaledCropRect, cropRect.width(), cropRect.height(),
+ asset.decodeBitmapRegion(scaledCropRect, cropRect.width(), cropRect.height(), adjustRtl,
new BitmapReceiver() {
@Override
public void onBitmapDecoded(Bitmap bitmap) {
diff --git a/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java
index 9354958..d6fa979 100644
--- a/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java
+++ b/tests/src/com/android/wallpaper/testing/TestCategoryProvider.java
@@ -93,8 +93,14 @@ public class TestCategoryProvider implements CategoryProvider {
}
@Override
- public void resetIfNeeded() {
+ public boolean resetIfNeeded() {
mCategories.clear();
+ return true;
+ }
+
+ @Override
+ public boolean isFeaturedCollectionAvailable() {
+ return false;
}
/** Returns a list of test Category objects used by this TestCategoryProvider. */
diff --git a/tests/src/com/android/wallpaper/testing/TestInjector.java b/tests/src/com/android/wallpaper/testing/TestInjector.java
index 9b7927f..fd9f68a 100644
--- a/tests/src/com/android/wallpaper/testing/TestInjector.java
+++ b/tests/src/com/android/wallpaper/testing/TestInjector.java
@@ -31,6 +31,7 @@ import com.android.wallpaper.module.DefaultLiveWallpaperInfoFactory;
import com.android.wallpaper.module.DrawableLayerResolver;
import com.android.wallpaper.module.ExploreIntentChecker;
import com.android.wallpaper.module.FormFactorChecker;
+import com.android.wallpaper.module.CustomizationSections;
import com.android.wallpaper.module.Injector;
import com.android.wallpaper.module.LiveWallpaperInfoFactory;
import com.android.wallpaper.module.LoggingOptInStatusProvider;
@@ -243,10 +244,20 @@ public class TestInjector implements Injector {
}
@Override
+ public String getDownloadableIntentAction() {
+ return null;
+ }
+
+ @Override
public PerformanceMonitor getPerformanceMonitor() {
if (mPerformanceMonitor == null) {
mPerformanceMonitor = new TestPerformanceMonitor();
}
return mPerformanceMonitor;
}
+
+ @Override
+ public CustomizationSections getCustomizationSections() {
+ return null;
+ }
}
diff --git a/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java b/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java
index 63ae94e..bb70e93 100644
--- a/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java
+++ b/tests/src/com/android/wallpaper/testing/TestUserEventLogger.java
@@ -15,6 +15,8 @@
*/
package com.android.wallpaper.testing;
+import android.content.Intent;
+
import com.android.wallpaper.module.UserEventLogger;
import com.android.wallpaper.module.WallpaperPersister.WallpaperPosition;
@@ -66,7 +68,7 @@ public class TestUserEventLogger implements UserEventLogger {
}
@Override
- public void logAppLaunched() {
+ public void logAppLaunched(Intent launchSource) {
// Do nothing.
}
diff --git a/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java b/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java
index c0ccee6..c4328c5 100644
--- a/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java
+++ b/tests/src/com/android/wallpaper/testing/TestWallpaperInfo.java
@@ -73,6 +73,7 @@ public class TestWallpaperInfo extends WallpaperInfo {
}
private TestWallpaperInfo(Parcel in) {
+ super(in);
mPixelColor = in.readInt();
mAttributions = in.createStringArrayList();
mActionUrl = in.readString();
@@ -200,6 +201,7 @@ public class TestWallpaperInfo extends WallpaperInfo {
@Override
public void writeToParcel(Parcel parcel, int i) {
+ super.writeToParcel(parcel, i);
parcel.writeInt(mPixelColor);
parcel.writeStringList(mAttributions);
parcel.writeString(mActionUrl);