Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.chooser; |
| 18 | |
| 19 | import static org.mockito.Mockito.any; |
| 20 | import static org.mockito.Mockito.anyBoolean; |
| 21 | import static org.mockito.Mockito.anyInt; |
| 22 | import static org.mockito.Mockito.eq; |
| 23 | import static org.mockito.Mockito.mock; |
| 24 | import static org.mockito.Mockito.times; |
| 25 | import static org.mockito.Mockito.verify; |
| 26 | import static org.mockito.Mockito.when; |
| 27 | |
| 28 | import android.app.Activity; |
| 29 | import android.app.ActivityTaskManager; |
| 30 | import android.content.Intent; |
| 31 | import android.os.Binder; |
| 32 | import android.support.test.runner.AndroidJUnit4; |
| 33 | import android.test.suitebuilder.annotation.SmallTest; |
| 34 | |
| 35 | import com.android.systemui.SysuiTestCase; |
| 36 | |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
| 39 | |
| 40 | @SmallTest |
| 41 | @RunWith(AndroidJUnit4.class) |
| 42 | public class ChooserHelperTest extends SysuiTestCase { |
| 43 | |
| 44 | @Test |
| 45 | public void testOnChoose_CallsStartActivityAsCallerWithToken() { |
| 46 | final Intent intent = new Intent(); |
| 47 | final Binder token = new Binder(); |
| 48 | intent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, token); |
| 49 | |
| 50 | final Activity mockActivity = mock(Activity.class); |
| 51 | when(mockActivity.getIntent()).thenReturn(intent); |
| 52 | |
| 53 | ChooserHelper.onChoose(mockActivity); |
| 54 | verify(mockActivity, times(1)).startActivityAsCaller( |
| 55 | any(), any(), eq(token), anyBoolean(), anyInt()); |
| 56 | } |
| 57 | } |