AppErrorDialogTest.java revision 0da67d661e20a3361f0ee4f10a19d1b8edf5e73d
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
17package com.android.server.am;
18
19import android.content.Context;
20import android.os.Handler;
21import android.support.test.InstrumentationRegistry;
22import android.support.test.annotation.UiThreadTest;
23import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
25
26import com.android.server.AppOpsService;
27
28import org.junit.Before;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31
32import java.io.File;
33
34/**
35 * runtest -c com.android.server.am.AppErrorDialogTest frameworks-services
36 */
37@RunWith(AndroidJUnit4.class)
38@SmallTest
39public class AppErrorDialogTest {
40
41    private Context mContext;
42    private ActivityManagerService mService;
43
44    @Before
45    public void setUp() throws Exception {
46        mContext = InstrumentationRegistry.getTargetContext();
47        mService = new ActivityManagerService(new ActivityManagerService.Injector() {
48            @Override
49            public AppOpsService getAppOpsService(File file, Handler handler) {
50                return null;
51            }
52
53            @Override
54            public Handler getUiHandler(ActivityManagerService service) {
55                return null;
56            }
57
58            @Override
59            public boolean isNetworkRestrictedForUid(int uid) {
60                return false;
61            }
62        });
63    }
64
65    @Test
66    @UiThreadTest
67    public void testCreateWorks() throws Exception {
68        AppErrorDialog.Data data = new AppErrorDialog.Data();
69        data.proc = new ProcessRecord(null, mContext.getApplicationInfo(), "name", 12345);
70        data.result = new AppErrorResult();
71
72        AppErrorDialog dialog = new AppErrorDialog(mContext, mService, data);
73
74        dialog.create();
75    }
76}
77