Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2009 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 android.content.res.Configuration;
     20 import android.os.Binder;
     21 import android.os.RemoteException;
     22 import android.os.ServiceManager;
     23 import android.test.suitebuilder.annotation.SmallTest;
     24 import android.view.IWindowManager;
     25 import junit.framework.TestCase;
     26 
     27 import static android.view.Display.DEFAULT_DISPLAY;
     28 
     29 /**
     30  * TODO: Remove this. This is only a placeholder, need to implement this.
     31  */
     32 public class WindowManagerPermissionTests extends TestCase {
     33     IWindowManager mWm;
     34 
     35     @Override
     36     protected void setUp() throws Exception {
     37         super.setUp();
     38         mWm = IWindowManager.Stub.asInterface(
     39                 ServiceManager.getService("window"));
     40     }
     41 
     42     @SmallTest
     43     public void testMANAGE_APP_TOKENS() {
     44         try {
     45             mWm.setEventDispatching(true);
     46             fail("IWindowManager.setEventDispatching did not throw SecurityException as"
     47                     + " expected");
     48         } catch (SecurityException e) {
     49             // expected
     50         } catch (RemoteException e) {
     51             fail("Unexpected remote exception");
     52         }
     53 
     54         try {
     55             mWm.addWindowToken(null, 0, DEFAULT_DISPLAY);
     56             fail("IWindowManager.addWindowToken did not throw SecurityException as"
     57                     + " expected");
     58         } catch (SecurityException e) {
     59             // expected
     60         } catch (RemoteException e) {
     61             fail("Unexpected remote exception");
     62         }
     63 
     64         try {
     65             mWm.removeWindowToken(null, DEFAULT_DISPLAY);
     66             fail("IWindowManager.removeWindowToken did not throw SecurityException as"
     67                     + " expected");
     68         } catch (SecurityException e) {
     69             // expected
     70         } catch (RemoteException e) {
     71             fail("Unexpected remote exception");
     72         }
     73 
     74         try {
     75             mWm.updateOrientationFromAppTokens(new Configuration(),
     76                     null /* freezeThisOneIfNeeded */, DEFAULT_DISPLAY);
     77             fail("IWindowManager.updateOrientationFromAppTokens did not throw SecurityException as"
     78                     + " expected");
     79         } catch (SecurityException e) {
     80             // expected
     81         } catch (RemoteException e) {
     82             fail("Unexpected remote exception");
     83         }
     84 
     85         try {
     86             mWm.setFocusedApp(null, false);
     87             fail("IWindowManager.setFocusedApp did not throw SecurityException as"
     88                     + " expected");
     89         } catch (SecurityException e) {
     90             // expected
     91         } catch (RemoteException e) {
     92             fail("Unexpected remote exception");
     93         }
     94 
     95         try {
     96             mWm.prepareAppTransition(0, false);
     97             fail("IWindowManager.prepareAppTransition did not throw SecurityException as"
     98                     + " expected");
     99         } catch (SecurityException e) {
    100             // expected
    101         } catch (RemoteException e) {
    102             fail("Unexpected remote exception");
    103         }
    104 
    105         try {
    106             mWm.executeAppTransition();
    107             fail("IWindowManager.executeAppTransition did not throw SecurityException as"
    108                     + " expected");
    109         } catch (SecurityException e) {
    110             // expected
    111         } catch (RemoteException e) {
    112             fail("Unexpected remote exception");
    113         }
    114     }
    115 
    116     @SmallTest
    117     public void testDISABLE_KEYGUARD() {
    118         Binder token = new Binder();
    119         try {
    120             mWm.disableKeyguard(token, "foo");
    121             fail("IWindowManager.disableKeyguard did not throw SecurityException as"
    122                     + " expected");
    123         } catch (SecurityException e) {
    124             // expected
    125         } catch (RemoteException e) {
    126             fail("Unexpected remote exception");
    127         }
    128 
    129         try {
    130             mWm.reenableKeyguard(token);
    131             fail("IWindowManager.reenableKeyguard did not throw SecurityException as"
    132                     + " expected");
    133         } catch (SecurityException e) {
    134             // expected
    135         } catch (RemoteException e) {
    136             fail("Unexpected remote exception");
    137         }
    138 
    139         try {
    140             mWm.exitKeyguardSecurely(null);
    141             fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as"
    142                     + " expected");
    143         } catch (SecurityException e) {
    144             // expected
    145         } catch (RemoteException e) {
    146             fail("Unexpected remote exception");
    147         }
    148     }
    149 
    150     @SmallTest
    151     public void testSET_ANIMATION_SCALE() {
    152         try {
    153             mWm.setAnimationScale(0, 1);
    154             fail("IWindowManager.setAnimationScale did not throw SecurityException as"
    155                     + " expected");
    156         } catch (SecurityException e) {
    157             // expected
    158         } catch (RemoteException e) {
    159             fail("Unexpected remote exception");
    160         }
    161 
    162         try {
    163             mWm.setAnimationScales(new float[1]);
    164             fail("IWindowManager.setAnimationScales did not throw SecurityException as"
    165                     + " expected");
    166         } catch (SecurityException e) {
    167             // expected
    168         } catch (RemoteException e) {
    169             fail("Unexpected remote exception");
    170         }
    171     }
    172 
    173     @SmallTest
    174     public void testSET_ORIENTATION() {
    175         try {
    176             mWm.updateRotation(true, false);
    177             fail("IWindowManager.updateRotation did not throw SecurityException as"
    178                     + " expected");
    179         } catch (SecurityException e) {
    180             // expected
    181         } catch (RemoteException e) {
    182             fail("Unexpected remote exception");
    183         }
    184 
    185         try {
    186             mWm.freezeRotation(-1);
    187             fail("IWindowManager.freezeRotation did not throw SecurityException as"
    188                     + " expected");
    189         } catch (SecurityException e) {
    190             // expected
    191         } catch (RemoteException e) {
    192             fail("Unexpected remote exception");
    193         }
    194 
    195         try {
    196             mWm.thawRotation();
    197             fail("IWindowManager.thawRotation did not throw SecurityException as"
    198                     + " expected");
    199         } catch (SecurityException e) {
    200             // expected
    201         } catch (RemoteException e) {
    202             fail("Unexpected remote exception");
    203         }
    204     }
    205 }
    206