WapPushOverSmsTest.java revision 60a81bdb47cf64972c8edf5b0c51e8059765e5a0
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(mContextFixture.getTestDouble()); 44 } 45 46 @After 47 public void tearDown() throws Exception { 48 mWapPushOverSmsUT = null; 49 } 50 51 @Test @SmallTest 52 public void testDispatchWapPdu() { 53 doReturn(true).when(mWspTypeDecoder).decodeUintvarInteger(anyInt()); 54 doReturn((long)2).when(mWspTypeDecoder).getValue32(); 55 doReturn(2).when(mWspTypeDecoder).getDecodedDataLength(); 56 doReturn(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO).when(mWspTypeDecoder).getValueString(); 57 byte[] pdu = new byte[]{ 58 (byte) 0xFF, 59 (byte) 0x06, 60 (byte) 0xFF, 61 (byte) 0xFF, 62 (byte) 0xFF, 63 (byte) 0xFF, 64 (byte) 0xFF 65 }; 66 67 mWapPushOverSmsUT.dispatchWapPdu(pdu, null, mInboundSmsHandler); 68 69 ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); 70 verify(mInboundSmsHandler).dispatchIntent(intentArgumentCaptor.capture(), 71 eq(android.Manifest.permission.RECEIVE_MMS), eq(AppOpsManager.OP_RECEIVE_MMS), 72 any(Bundle.class), isNull(BroadcastReceiver.class), eq(UserHandle.SYSTEM)); 73 Intent intent = intentArgumentCaptor.getValue(); 74 assertEquals(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION, intent.getAction()); 75 assertEquals(0xFF, intent.getIntExtra("transactionId", 0)); 76 assertEquals(0x06, intent.getIntExtra("pduType", 0)); 77 assertEquals(new byte[]{(byte) 0xFF, (byte) 0xFF}, intent.getByteArrayExtra("header")); 78 assertEquals(pdu, intent.getByteArrayExtra("data")); 79 assertEquals(mWspTypeDecoder.getContentParameters(), 80 intent.getSerializableExtra("contentTypeParameters")); 81 } 82}