OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / tests / permission / src / com / android / framework / permission / tests / PmPermissionsTests.java
1 /*
2  * Copyright (C) 2006 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 com.android.framework.permission.tests;
18
19 import junit.framework.TestCase;
20 import android.content.pm.PackageManager;
21 import android.test.AndroidTestCase;
22 import android.test.suitebuilder.annotation.SmallTest;
23
24 /**
25  * Verify PackageManager api's that require specific permissions.
26  */
27 public class PmPermissionsTests extends AndroidTestCase {
28     private PackageManager mPm;
29     private String mPkgName = "com.android.framework.permission.tests";
30
31     @Override
32     protected void setUp() throws Exception {
33         super.setUp();
34         mPm = getContext().getPackageManager();
35     }
36
37     /*
38      * This test verifies that PackageManger.getPackageSizeInfo enforces permission
39      * android.permission.GET_PACKAGE_SIZE
40      */
41     @SmallTest
42     public void testGetPackageSize() {
43         try {
44             mPm.getPackageSizeInfo(mPkgName, null);
45             fail("PackageManager.getPackageSizeInfo" +
46                     "did not throw SecurityException as expected");
47         } catch (SecurityException e) {
48             // expected
49         }
50     }
51
52     /*
53      * This test verifies that PackageManger.DeleteApplicationCacheFiles enforces permission
54      * android.permission.DELETE_CACHE_FILES
55      */
56     @SmallTest
57     public void testDeleteApplicationCacheFiles() {
58         try {
59             mPm.deleteApplicationCacheFiles(mPkgName, null);
60             fail("PackageManager.deleteApplicationCacheFiles" +
61                     "did not throw SecurityException as expected");
62         } catch (SecurityException e) {
63             // expected
64         }
65     }
66
67     /*
68      * This test verifies that PackageManger.installPackage enforces permission
69      * android.permission.INSTALL_PACKAGES
70      */
71     @SmallTest
72     public void testInstallPackage() {
73         try {
74             mPm.installPackage(null, null, 0, null);
75             fail("PackageManager.installPackage" +
76                     "did not throw SecurityException as expected");
77         } catch (SecurityException e) {
78             // expected
79         }
80     }
81
82     /*
83      * This test verifies that PackageManger.freeStorage
84      * enforces permission android.permission.CLEAR_APP_CACHE
85      */
86     @SmallTest
87     public void testFreeStorage1() {
88         try {
89             mPm.freeStorage(100000, null);
90             fail("PackageManager.freeStorage " +
91                    "did not throw SecurityException as expected");
92         } catch (SecurityException e) {
93             // expected
94         }
95     }
96
97     /*
98      * This test verifies that PackageManger.freeStorageAndNotify
99      * enforces permission android.permission.CLEAR_APP_CACHE
100      */
101     @SmallTest
102     public void testFreeStorage2() {
103         try {
104             mPm.freeStorageAndNotify(100000, null);
105             fail("PackageManager.freeStorageAndNotify" +
106                     " did not throw SecurityException as expected");
107         } catch (SecurityException e) {
108             // expected
109         }
110     }
111
112     /*
113      * This test verifies that PackageManger.clearApplicationUserData
114      * enforces permission android.permission.CLEAR_APP_USER_DATA
115      */
116     @SmallTest
117     public void testClearApplicationUserData() {
118         try {
119             mPm.clearApplicationUserData(mPkgName, null);
120             fail("PackageManager.clearApplicationUserData" +
121                     "did not throw SecurityException as expected");
122         } catch (SecurityException e) {
123             // expected
124         }
125     }
126
127     /*
128      * This test verifies that PackageManger.deletePackage
129      * enforces permission android.permission.DELETE_PACKAGES
130      */
131     @SmallTest
132     public void testDeletePackage() {
133         try {
134             mPm.deletePackage(mPkgName, null, 0);
135             fail("PackageManager.deletePackage" +
136                    "did not throw SecurityException as expected");
137         } catch (SecurityException e) {
138             // expected
139         }
140     }
141 }