OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.webapk.test; | 5 package org.chromium.webapk.test; |
6 | 6 |
7 import android.content.pm.ApplicationInfo; | 7 import android.content.pm.ApplicationInfo; |
8 import android.content.pm.PackageInfo; | 8 import android.content.pm.PackageInfo; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 | 10 |
11 import org.robolectric.RuntimeEnvironment; | 11 import org.robolectric.RuntimeEnvironment; |
12 import org.robolectric.res.builder.RobolectricPackageManager; | 12 import org.robolectric.res.builder.RobolectricPackageManager; |
13 | 13 |
14 /** | 14 /** |
15 * Helper class for WebAPK JUnit tests. | 15 * Helper class for WebAPK JUnit tests. |
16 */ | 16 */ |
17 public class WebApkTestHelper { | 17 public class WebApkTestHelper { |
18 /** | 18 /** |
19 * Package name of the WebAPK registered by {@link #registerWebApkWithMetaDa
ta}. | 19 * Package name of the WebAPK registered by {@link #registerWebApkWithMetaDa
ta}. |
20 */ | 20 */ |
21 public static String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_package
"; | 21 public static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.test_p
ackage"; |
22 | 22 |
23 /** | 23 /** |
24 * Registers WebAPK. | 24 * Registers WebAPK. |
25 * @param metaData Bundle with meta data from WebAPK's Android Manifest. | 25 * @param metaData Bundle with meta data from WebAPK's Android Manifest. |
26 */ | 26 */ |
27 public static void registerWebApkWithMetaData(Bundle metaData) { | 27 public static void registerWebApkWithMetaData(Bundle metaData) { |
28 RobolectricPackageManager packageManager = | 28 RobolectricPackageManager packageManager = |
29 (RobolectricPackageManager) RuntimeEnvironment.application.getPa
ckageManager(); | 29 (RobolectricPackageManager) RuntimeEnvironment.application.getPa
ckageManager(); |
30 packageManager.addPackage(newPackageInfo(WEBAPK_PACKAGE_NAME, metaData))
; | 30 packageManager.addPackage(newPackageInfo(WEBAPK_PACKAGE_NAME, metaData))
; |
31 } | 31 } |
32 | 32 |
33 private static PackageInfo newPackageInfo(String packageName, Bundle metaDat
a) { | 33 private static PackageInfo newPackageInfo(String packageName, Bundle metaDat
a) { |
34 ApplicationInfo applicationInfo = new ApplicationInfo(); | 34 ApplicationInfo applicationInfo = new ApplicationInfo(); |
35 applicationInfo.metaData = metaData; | 35 applicationInfo.metaData = metaData; |
36 PackageInfo packageInfo = new PackageInfo(); | 36 PackageInfo packageInfo = new PackageInfo(); |
37 packageInfo.packageName = packageName; | 37 packageInfo.packageName = packageName; |
38 packageInfo.applicationInfo = applicationInfo; | 38 packageInfo.applicationInfo = applicationInfo; |
39 return packageInfo; | 39 return packageInfo; |
40 } | 40 } |
41 } | 41 } |
OLD | NEW |