blob: c43fa7492e26e212df83189033678fa9f2a76db0 [file] [log] [blame]
Leland Miller67370f12019-09-23 16:09:52 -07001/*
2 * Copyright (C) 2019 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.mms.service;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.testng.Assert.assertThrows;
22
23import android.content.Intent;
24import android.net.Uri;
25import android.os.Process;
26import android.os.RemoteException;
27
28import com.android.internal.telephony.IMms;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33import org.robolectric.Robolectric;
34import org.robolectric.RobolectricTestRunner;
35import org.robolectric.shadows.ShadowBinder;
36
37@RunWith(RobolectricTestRunner.class)
38public final class MmsServiceRoboTest {
39 private IMms.Stub binder;
40
41 @Before
42 public void setUp() {
43 MmsService mmsService = Robolectric.setupService(MmsService.class);
44
45 final Intent intent = new Intent();
46
47 binder = (IMms.Stub) mmsService.onBind(intent);
48 }
49
50 @Test
51 public void testOnBind_IsNotNull() {
52 assertThat(binder).isNotNull();
53 }
54
55 @Test
56 public void testSendMessage_DoesNotThrowIfSystemUid() throws RemoteException {
57 ShadowBinder.setCallingUid(Process.SYSTEM_UID);
58 binder.sendMessage(/* subId= */ 0, "callingPkg", Uri.parse("contentUri"),
Tom Taylor3e08db92020-01-23 14:39:25 -080059 "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null,
60 /* messageId= */ 0L);
Leland Miller67370f12019-09-23 16:09:52 -070061 }
62
63 @Test
64 public void testSendMessageThrows_IfNotSystemUid() {
65 assertThrows(SecurityException.class,
66 () -> binder.sendMessage(/* subId= */ 0, "callingPkg", Uri.parse("contentUri"),
Tom Taylor3e08db92020-01-23 14:39:25 -080067 "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null,
68 /* messageId= */ 0L));
Leland Miller67370f12019-09-23 16:09:52 -070069 }
70}