WapPushOverSmsTest.java revision f152b32a20be664788536a223b9ac7a52f69e4dd
1/*
2 * Copyright (C) 2016 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.internal.telephony;
18
19import android.app.AppOpsManager;
20import android.content.BroadcastReceiver;
21import android.content.Intent;
22import android.os.Bundle;
23import android.os.UserHandle;
24import android.provider.Telephony;
25import android.test.suitebuilder.annotation.SmallTest;
26
27import static org.junit.Assert.*;
28import static org.mockito.Mockito.*;
29
30import org.junit.After;
31import org.junit.Before;
32import org.junit.Test;
33import org.mockito.ArgumentCaptor;
34import org.mockito.MockitoAnnotations;
35
36public class WapPushOverSmsTest extends TelephonyTest {
37    private WapPushOverSms mWapPushOverSmsUT;
38
39    @Before
40    public void setUp() throws Exception {
41        super.setUp("WapPushOverSmsTest");
42
43        mWapPushOverSmsUT = new WapPushOverSms(mContext);
44    }
45
46    @After
47    public void tearDown() throws Exception {
48        mWapPushOverSmsUT = null;
49        super.tearDown();
50    }
51
52    @Test @SmallTest
53    public void testDispatchWapPdu() {
54        doReturn(true).when(mWspTypeDecoder).decodeUintvarInteger(anyInt());
55        doReturn(true).when(mWspTypeDecoder).decodeContentType(anyInt());
56        doReturn((long)2).when(mWspTypeDecoder).getValue32();
57        doReturn(2).when(mWspTypeDecoder).getDecodedDataLength();
58        doReturn(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO).when(mWspTypeDecoder).getValueString();
59        byte[] pdu = new byte[]{
60                (byte) 0xFF,
61                (byte) 0x06,
62                (byte) 0xFF,
63                (byte) 0xFF,
64                (byte) 0xFF,
65                (byte) 0xFF,
66                (byte) 0xFF
67        };
68
69        mWapPushOverSmsUT.dispatchWapPdu(pdu, null, mInboundSmsHandler);
70
71        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
72        verify(mInboundSmsHandler).dispatchIntent(intentArgumentCaptor.capture(),
73                eq(android.Manifest.permission.RECEIVE_WAP_PUSH),
74                eq(AppOpsManager.OP_RECEIVE_WAP_PUSH),
75                any(Bundle.class),
76                isNull(BroadcastReceiver.class),
77                eq(UserHandle.SYSTEM));
78        Intent intent = intentArgumentCaptor.getValue();
79        assertEquals(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION, intent.getAction());
80        assertEquals(0xFF, intent.getIntExtra("transactionId", 0));
81        assertEquals(0x06, intent.getIntExtra("pduType", 0));
82
83        byte[] header = intent.getByteArrayExtra("header");
84        assertEquals(2, header.length);
85        for (int i = 0; i < header.length; i++) {
86            assertEquals((byte)0xFF, header[i]);
87        }
88
89        byte[] data = intent.getByteArrayExtra("data");
90        assertEquals(pdu.length, data.length);
91        for (int i = 0; i < pdu.length; i++) {
92            assertEquals(pdu[i], data[i]);
93        }
94
95        assertEquals(mWspTypeDecoder.getContentParameters(),
96                intent.getSerializableExtra("contentTypeParameters"));
97    }
98}