CTS for widget description & layout preview Test: CtsAppWidgetTestCases passed. Bug: 179063291 Change-Id: Ifd139363af97653606295a64a28e721fe5836749
diff --git a/tests/tests/appwidget/res/layout/preview_layout.xml b/tests/tests/appwidget/res/layout/preview_layout.xml new file mode 100644 index 0000000..6a5153a --- /dev/null +++ b/tests/tests/appwidget/res/layout/preview_layout.xml
@@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * 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. + --> +<TextView android:id="@+id/widget_preview" + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="Widget preview" /> \ No newline at end of file
diff --git a/tests/tests/appwidget/res/values/strings.xml b/tests/tests/appwidget/res/values/strings.xml new file mode 100644 index 0000000..ef4e5b8e --- /dev/null +++ b/tests/tests/appwidget/res/values/strings.xml
@@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * 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. + --> +<resources> + <string name="widget_description">Widget description</string> +</resources> \ No newline at end of file
diff --git a/tests/tests/appwidget/res/xml/first_appwidget_info.xml b/tests/tests/appwidget/res/xml/first_appwidget_info.xml index d7c1028..e98ed62 100644 --- a/tests/tests/appwidget/res/xml/first_appwidget_info.xml +++ b/tests/tests/appwidget/res/xml/first_appwidget_info.xml
@@ -25,7 +25,9 @@ android:resizeMode="horizontal|vertical" android:widgetCategory="home_screen|keyguard" android:initialLayout="@layout/first_initial_layout" + android:description="@string/widget_description" android:initialKeyguardLayout="@layout/first_initial_keyguard_layout" android:previewImage="@drawable/first_android_icon" + android:previewLayout="@layout/preview_layout" android:autoAdvanceViewId="@id/first_auto_advance_view_id"> </appwidget-provider>
diff --git a/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTest.java b/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTest.java index f3120a9..4f1faad 100644 --- a/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTest.java +++ b/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTest.java
@@ -16,6 +16,8 @@ package android.appwidget.cts; +import static com.google.common.truth.Truth.assertThat; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -518,6 +520,10 @@ Drawable previewImage = foundProvider.loadPreviewImage(context, 0); assertNotNull(previewImage); + + assertThat(foundProvider.loadDescription(context)).isEqualTo("Widget description"); + + assertThat(foundProvider.previewLayout).isEqualTo(R.layout.preview_layout); } finally { // Clean up. host.deleteAppWidgetId(appWidgetId);
diff --git a/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTestCase.java b/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTestCase.java index c4d4fcd..e175299 100644 --- a/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTestCase.java +++ b/tests/tests/appwidget/src/android/appwidget/cts/AppWidgetTestCase.java
@@ -109,6 +109,10 @@ provider.previewImage); assertEquals(android.appwidget.cts.R.id.first_auto_advance_view_id, provider.autoAdvanceViewId); + assertEquals(android.appwidget.cts.R.string.widget_description, + provider.descriptionResource); + assertEquals(android.appwidget.cts.R.layout.preview_layout, + provider.previewLayout); firstProviderVerified = true; } else if (secondComponentName.equals(provider.provider) && android.os.Process.myUserHandle().equals(provider.getProfile())) {