Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertTrue; |
| 21 | |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.pm.PackageManager; |
| 25 | import android.content.pm.ResolveInfo; |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 26 | import android.net.Uri; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 27 | import android.os.Parcel; |
| 28 | import android.service.wallpaper.WallpaperService; |
| 29 | import android.support.test.InstrumentationRegistry; |
| 30 | import android.support.test.filters.SmallTest; |
| 31 | import android.support.test.runner.AndroidJUnit4; |
| 32 | |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
| 36 | import java.util.List; |
| 37 | |
| 38 | /** |
| 39 | * Tests for hidden WallpaperInfo methods. |
| 40 | */ |
| 41 | @RunWith(AndroidJUnit4.class) |
| 42 | @SmallTest |
| 43 | public class WallpaperInfoTest { |
| 44 | |
| 45 | @Test |
| 46 | public void testSupportsAmbientMode() throws Exception { |
| 47 | Context context = InstrumentationRegistry.getTargetContext(); |
| 48 | |
| 49 | Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
| 50 | intent.setPackage("com.android.internal.tests"); |
| 51 | PackageManager pm = context.getPackageManager(); |
| 52 | List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); |
| 53 | assertEquals(1, result.size()); |
| 54 | ResolveInfo info = result.get(0); |
| 55 | WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); |
| 56 | |
| 57 | // Defined as true in the XML |
| 58 | assertTrue("supportsAmbientMode should be true, as defined in the XML.", |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 59 | wallpaperInfo.supportsAmbientMode()); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 60 | Parcel parcel = Parcel.obtain(); |
| 61 | wallpaperInfo.writeToParcel(parcel, 0 /* flags */); |
| 62 | parcel.setDataPosition(0); |
| 63 | WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); |
| 64 | assertTrue("supportsAmbientMode should have been restored from parcelable", |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 65 | fromParcel.supportsAmbientMode()); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 66 | parcel.recycle(); |
| 67 | } |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 68 | |
| 69 | @Test |
| 70 | public void testGetSettingsSliceUri() throws Exception { |
| 71 | Context context = InstrumentationRegistry.getTargetContext(); |
| 72 | |
| 73 | Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
| 74 | intent.setPackage("com.android.internal.tests"); |
| 75 | PackageManager pm = context.getPackageManager(); |
| 76 | List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); |
| 77 | assertEquals(1, result.size()); |
| 78 | ResolveInfo info = result.get(0); |
| 79 | WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); |
| 80 | |
| 81 | // This expected Uri must be the same as that in livewallpaper.xml |
| 82 | Uri expectedUri = Uri.parse("content://com.android.internal.tests/slice"); |
| 83 | Uri settingsUri = wallpaperInfo.getSettingsSliceUri(); |
| 84 | assertEquals("The loaded URI should equal to the string in livewallpaper.xml", |
| 85 | 0, expectedUri.compareTo(settingsUri)); |
| 86 | Parcel parcel = Parcel.obtain(); |
| 87 | wallpaperInfo.writeToParcel(parcel, 0 /* flags */); |
| 88 | parcel.setDataPosition(0); |
| 89 | WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); |
| 90 | assertEquals("settingsSliceUri should be restorable from parcelable", |
| 91 | 0, expectedUri.compareTo(fromParcel.getSettingsSliceUri())); |
| 92 | parcel.recycle(); |
| 93 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 94 | } |
| 95 | |