hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 17 | package com.android.settingslib.media; |
| 18 | |
hughchen | e8c79b0 | 2020-04-21 17:26:21 +0800 | [diff] [blame] | 19 | import static android.media.MediaRoute2Info.TYPE_BLUETOOTH_A2DP; |
| 20 | import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER; |
| 21 | import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER; |
| 22 | import static android.media.MediaRoute2Info.TYPE_USB_DEVICE; |
| 23 | import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET; |
hughchen | 063a35a | 2020-03-04 17:51:57 +0800 | [diff] [blame] | 24 | import static android.media.MediaRoute2ProviderService.REASON_NETWORK_ERROR; |
| 25 | import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR; |
| 26 | |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 27 | import static com.google.common.truth.Truth.assertThat; |
| 28 | |
hughchen | e8c79b0 | 2020-04-21 17:26:21 +0800 | [diff] [blame] | 29 | import static org.mockito.ArgumentMatchers.any; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 30 | import static org.mockito.Mockito.mock; |
| 31 | import static org.mockito.Mockito.verify; |
| 32 | import static org.mockito.Mockito.when; |
| 33 | |
hughchen | e8c79b0 | 2020-04-21 17:26:21 +0800 | [diff] [blame] | 34 | import android.bluetooth.BluetoothDevice; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 35 | import android.content.Context; |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 36 | import android.media.MediaRoute2Info; |
| 37 | import android.media.MediaRouter2Manager; |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 38 | import android.media.RoutingSessionInfo; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 39 | |
hughchen | e8c79b0 | 2020-04-21 17:26:21 +0800 | [diff] [blame] | 40 | import com.android.settingslib.bluetooth.CachedBluetoothDevice; |
| 41 | import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; |
hughchen | 491b9fc | 2020-02-05 18:31:36 +0800 | [diff] [blame] | 42 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 43 | import com.android.settingslib.testutils.shadow.ShadowRouter2Manager; |
hughchen | 491b9fc | 2020-02-05 18:31:36 +0800 | [diff] [blame] | 44 | |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 45 | import org.junit.Before; |
| 46 | import org.junit.Test; |
| 47 | import org.junit.runner.RunWith; |
| 48 | import org.mockito.Mock; |
| 49 | import org.mockito.MockitoAnnotations; |
| 50 | import org.robolectric.RobolectricTestRunner; |
| 51 | import org.robolectric.RuntimeEnvironment; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 52 | import org.robolectric.annotation.Config; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 53 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 54 | import java.util.ArrayList; |
| 55 | import java.util.List; |
| 56 | |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 57 | @RunWith(RobolectricTestRunner.class) |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 58 | @Config(shadows = {ShadowRouter2Manager.class}) |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 59 | public class InfoMediaManagerTest { |
| 60 | |
| 61 | private static final String TEST_PACKAGE_NAME = "com.test.packagename"; |
| 62 | private static final String TEST_ID = "test_id"; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 63 | private static final String TEST_NAME = "test_name"; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 64 | |
| 65 | @Mock |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 66 | private MediaRouter2Manager mRouterManager; |
hughchen | 491b9fc | 2020-02-05 18:31:36 +0800 | [diff] [blame] | 67 | @Mock |
| 68 | private LocalBluetoothManager mLocalBluetoothManager; |
hughchen | 063a35a | 2020-03-04 17:51:57 +0800 | [diff] [blame] | 69 | @Mock |
| 70 | private MediaManager.MediaDeviceCallback mCallback; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 71 | |
| 72 | private InfoMediaManager mInfoMediaManager; |
| 73 | private Context mContext; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 74 | private ShadowRouter2Manager mShadowRouter2Manager; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 75 | |
| 76 | @Before |
| 77 | public void setUp() { |
| 78 | MockitoAnnotations.initMocks(this); |
| 79 | mContext = RuntimeEnvironment.application; |
| 80 | |
hughchen | 491b9fc | 2020-02-05 18:31:36 +0800 | [diff] [blame] | 81 | mInfoMediaManager = |
| 82 | new InfoMediaManager(mContext, TEST_PACKAGE_NAME, null, mLocalBluetoothManager); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 83 | mShadowRouter2Manager = ShadowRouter2Manager.getShadow(); |
| 84 | mInfoMediaManager.mRouterManager = MediaRouter2Manager.getInstance(mContext); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Test |
hughchen | 0d20204 | 2020-01-17 18:30:03 +0800 | [diff] [blame] | 88 | public void onRouteAdded_getAvailableRoutes_shouldAddMediaDevice() { |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 89 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 90 | final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); |
| 91 | routingSessionInfos.add(sessionInfo); |
| 92 | final List<String> selectedRoutes = new ArrayList<>(); |
| 93 | selectedRoutes.add(TEST_ID); |
| 94 | when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes); |
| 95 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 96 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 97 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 98 | when(info.getId()).thenReturn(TEST_ID); |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 99 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 100 | |
| 101 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 102 | routes.add(info); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 103 | mShadowRouter2Manager.setAvailableRoutes(routes); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 104 | |
| 105 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 106 | assertThat(mediaDevice).isNull(); |
| 107 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 108 | mInfoMediaManager.mMediaRouterCallback.onRoutesAdded(routes); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 109 | |
| 110 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 111 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 112 | assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice); |
| 113 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Test |
hughchen | 0d20204 | 2020-01-17 18:30:03 +0800 | [diff] [blame] | 117 | public void onRouteAdded_buildAllRoutes_shouldAddMediaDevice() { |
| 118 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 119 | when(info.getId()).thenReturn(TEST_ID); |
| 120 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
hughchen | 61bced0 | 2020-02-20 18:46:32 +0800 | [diff] [blame] | 121 | when(info.isSystemRoute()).thenReturn(true); |
hughchen | 0d20204 | 2020-01-17 18:30:03 +0800 | [diff] [blame] | 122 | |
| 123 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 124 | routes.add(info); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 125 | mShadowRouter2Manager.setAllRoutes(routes); |
hughchen | 0d20204 | 2020-01-17 18:30:03 +0800 | [diff] [blame] | 126 | |
| 127 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 128 | assertThat(mediaDevice).isNull(); |
| 129 | |
| 130 | mInfoMediaManager.mPackageName = ""; |
| 131 | mInfoMediaManager.mMediaRouterCallback.onRoutesAdded(routes); |
| 132 | |
| 133 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 134 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 135 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 136 | } |
| 137 | |
| 138 | @Test |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 139 | public void onControlCategoriesChanged_samePackageName_shouldAddMediaDevice() { |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 140 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 141 | final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); |
| 142 | routingSessionInfos.add(sessionInfo); |
| 143 | final List<String> selectedRoutes = new ArrayList<>(); |
| 144 | selectedRoutes.add(TEST_ID); |
| 145 | when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes); |
| 146 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 147 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 148 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 149 | when(info.getId()).thenReturn(TEST_ID); |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 150 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 151 | |
| 152 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 153 | routes.add(info); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 154 | mShadowRouter2Manager.setAvailableRoutes(routes); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 155 | |
| 156 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 157 | assertThat(mediaDevice).isNull(); |
| 158 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 159 | mInfoMediaManager.mMediaRouterCallback.onControlCategoriesChanged(TEST_PACKAGE_NAME, null); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 160 | |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 161 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 162 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 163 | assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice); |
| 164 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 165 | } |
| 166 | |
| 167 | @Test |
| 168 | public void onControlCategoriesChanged_differentPackageName_doNothing() { |
| 169 | mInfoMediaManager.mMediaRouterCallback.onControlCategoriesChanged("com.fake.play", null); |
| 170 | |
| 171 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(0); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 172 | } |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 173 | |
| 174 | @Test |
| 175 | public void onRoutesChanged_getAvailableRoutes_shouldAddMediaDevice() { |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 176 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 177 | final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); |
| 178 | routingSessionInfos.add(sessionInfo); |
| 179 | final List<String> selectedRoutes = new ArrayList<>(); |
| 180 | selectedRoutes.add(TEST_ID); |
| 181 | when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes); |
| 182 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 183 | |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 184 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 185 | when(info.getId()).thenReturn(TEST_ID); |
| 186 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 187 | |
| 188 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 189 | routes.add(info); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 190 | mShadowRouter2Manager.setAvailableRoutes(routes); |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 191 | |
| 192 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 193 | assertThat(mediaDevice).isNull(); |
| 194 | |
| 195 | mInfoMediaManager.mMediaRouterCallback.onRoutesChanged(routes); |
| 196 | |
| 197 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 198 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 199 | assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice); |
| 200 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 201 | } |
| 202 | |
| 203 | @Test |
| 204 | public void onRoutesChanged_buildAllRoutes_shouldAddMediaDevice() { |
| 205 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 206 | when(info.getId()).thenReturn(TEST_ID); |
| 207 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
hughchen | 61bced0 | 2020-02-20 18:46:32 +0800 | [diff] [blame] | 208 | when(info.isSystemRoute()).thenReturn(true); |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 209 | |
| 210 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 211 | routes.add(info); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 212 | mShadowRouter2Manager.setAllRoutes(routes); |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 213 | |
| 214 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 215 | assertThat(mediaDevice).isNull(); |
| 216 | |
| 217 | mInfoMediaManager.mPackageName = ""; |
| 218 | mInfoMediaManager.mMediaRouterCallback.onRoutesChanged(routes); |
| 219 | |
| 220 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 221 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 222 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 223 | } |
| 224 | |
| 225 | @Test |
| 226 | public void connectDeviceWithoutPackageName_noSession_returnFalse() { |
| 227 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 228 | final MediaDevice device = new InfoMediaDevice(mContext, mInfoMediaManager.mRouterManager, |
| 229 | info, TEST_PACKAGE_NAME); |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 230 | |
| 231 | final List<RoutingSessionInfo> infos = new ArrayList<>(); |
| 232 | |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 233 | mShadowRouter2Manager.setActiveSessions(infos); |
hughchen | df7b838 | 2020-02-03 17:48:49 +0800 | [diff] [blame] | 234 | |
| 235 | assertThat(mInfoMediaManager.connectDeviceWithoutPackageName(device)).isFalse(); |
| 236 | } |
hughchen | b3d68f6 | 2020-02-11 14:30:14 +0800 | [diff] [blame] | 237 | |
| 238 | @Test |
| 239 | public void onRoutesRemoved_getAvailableRoutes_shouldAddMediaDevice() { |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 240 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 241 | final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); |
| 242 | routingSessionInfos.add(sessionInfo); |
| 243 | final List<String> selectedRoutes = new ArrayList<>(); |
| 244 | selectedRoutes.add(TEST_ID); |
| 245 | when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes); |
| 246 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 247 | |
hughchen | b3d68f6 | 2020-02-11 14:30:14 +0800 | [diff] [blame] | 248 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 249 | when(info.getId()).thenReturn(TEST_ID); |
| 250 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 251 | |
| 252 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 253 | routes.add(info); |
| 254 | when(mRouterManager.getAvailableRoutes(TEST_PACKAGE_NAME)).thenReturn(routes); |
| 255 | |
| 256 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 257 | assertThat(mediaDevice).isNull(); |
| 258 | |
| 259 | mInfoMediaManager.mMediaRouterCallback.onRoutesRemoved(routes); |
| 260 | |
| 261 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 262 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 263 | assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice); |
| 264 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 265 | } |
| 266 | |
| 267 | @Test |
| 268 | public void onRoutesRemoved_buildAllRoutes_shouldAddMediaDevice() { |
| 269 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 270 | when(info.getId()).thenReturn(TEST_ID); |
| 271 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
hughchen | 61bced0 | 2020-02-20 18:46:32 +0800 | [diff] [blame] | 272 | when(info.isSystemRoute()).thenReturn(true); |
hughchen | b3d68f6 | 2020-02-11 14:30:14 +0800 | [diff] [blame] | 273 | |
| 274 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 275 | routes.add(info); |
| 276 | when(mRouterManager.getAllRoutes()).thenReturn(routes); |
| 277 | |
| 278 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 279 | assertThat(mediaDevice).isNull(); |
| 280 | |
| 281 | mInfoMediaManager.mPackageName = ""; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 282 | mInfoMediaManager.mMediaRouterCallback.onRoutesRemoved(routes); |
hughchen | b3d68f6 | 2020-02-11 14:30:14 +0800 | [diff] [blame] | 283 | |
| 284 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 285 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 286 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 287 | } |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 288 | |
| 289 | @Test |
| 290 | public void addDeviceToPlayMedia_packageNameIsNull_returnFalse() { |
| 291 | mInfoMediaManager.mPackageName = null; |
| 292 | final MediaDevice device = mock(MediaDevice.class); |
| 293 | |
| 294 | assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); |
| 295 | } |
| 296 | |
| 297 | @Test |
| 298 | public void addDeviceToPlayMedia_containSelectableRoutes_returnTrue() { |
| 299 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 300 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 301 | routingSessionInfos.add(info); |
| 302 | |
| 303 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 304 | final MediaDevice device = |
| 305 | new InfoMediaDevice(mContext, mInfoMediaManager.mRouterManager, route2Info, |
| 306 | TEST_PACKAGE_NAME); |
| 307 | |
| 308 | final List<String> list = new ArrayList<>(); |
| 309 | list.add(TEST_ID); |
| 310 | |
| 311 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 312 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 313 | when(info.getSelectableRoutes()).thenReturn(list); |
| 314 | when(route2Info.getId()).thenReturn(TEST_ID); |
| 315 | when(route2Info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 316 | |
| 317 | assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isTrue(); |
| 318 | } |
| 319 | |
| 320 | @Test |
| 321 | public void addDeviceToPlayMedia_notContainSelectableRoutes_returnFalse() { |
| 322 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 323 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 324 | routingSessionInfos.add(info); |
| 325 | |
| 326 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 327 | final MediaDevice device = |
| 328 | new InfoMediaDevice(mContext, mInfoMediaManager.mRouterManager, route2Info, |
| 329 | TEST_PACKAGE_NAME); |
| 330 | |
| 331 | final List<String> list = new ArrayList<>(); |
| 332 | list.add("fake_id"); |
| 333 | |
| 334 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 335 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 336 | when(info.getSelectableRoutes()).thenReturn(list); |
| 337 | when(route2Info.getId()).thenReturn(TEST_ID); |
| 338 | when(route2Info.getName()).thenReturn(TEST_NAME); |
| 339 | when(route2Info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 340 | |
| 341 | assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); |
| 342 | } |
| 343 | |
| 344 | @Test |
| 345 | public void removeDeviceFromMedia_packageNameIsNull_returnFalse() { |
| 346 | mInfoMediaManager.mPackageName = null; |
| 347 | final MediaDevice device = mock(MediaDevice.class); |
| 348 | |
| 349 | assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); |
| 350 | } |
| 351 | |
| 352 | @Test |
| 353 | public void removeDeviceFromMedia_containSelectedRoutes_returnTrue() { |
| 354 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 355 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 356 | routingSessionInfos.add(info); |
| 357 | |
| 358 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 359 | final MediaDevice device = |
| 360 | new InfoMediaDevice(mContext, mInfoMediaManager.mRouterManager, route2Info, |
| 361 | TEST_PACKAGE_NAME); |
| 362 | |
| 363 | final List<String> list = new ArrayList<>(); |
| 364 | list.add(TEST_ID); |
| 365 | |
| 366 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 367 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 368 | when(info.getSelectedRoutes()).thenReturn(list); |
| 369 | when(route2Info.getId()).thenReturn(TEST_ID); |
| 370 | when(route2Info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 371 | |
| 372 | assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isTrue(); |
| 373 | } |
| 374 | |
| 375 | @Test |
| 376 | public void removeDeviceFromMedia_notContainSelectedRoutes_returnFalse() { |
| 377 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 378 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 379 | routingSessionInfos.add(info); |
| 380 | |
| 381 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 382 | final MediaDevice device = |
| 383 | new InfoMediaDevice(mContext, mInfoMediaManager.mRouterManager, route2Info, |
| 384 | TEST_PACKAGE_NAME); |
| 385 | |
| 386 | final List<String> list = new ArrayList<>(); |
| 387 | list.add("fake_id"); |
| 388 | |
| 389 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 390 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 391 | when(info.getSelectedRoutes()).thenReturn(list); |
| 392 | when(route2Info.getId()).thenReturn(TEST_ID); |
| 393 | when(route2Info.getName()).thenReturn(TEST_NAME); |
| 394 | when(route2Info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 395 | |
| 396 | assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); |
| 397 | } |
| 398 | |
| 399 | @Test |
| 400 | public void getSelectableMediaDevice_packageNameIsNull_returnFalse() { |
| 401 | mInfoMediaManager.mPackageName = null; |
| 402 | |
| 403 | assertThat(mInfoMediaManager.getSelectableMediaDevice()).isEmpty(); |
| 404 | } |
| 405 | |
| 406 | @Test |
| 407 | public void getSelectableMediaDevice_notContainPackageName_returnEmpty() { |
| 408 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 409 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 410 | routingSessionInfos.add(info); |
| 411 | |
| 412 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 413 | when(info.getClientPackageName()).thenReturn("com.fake.packagename"); |
| 414 | |
| 415 | assertThat(mInfoMediaManager.getSelectableMediaDevice()).isEmpty(); |
| 416 | } |
| 417 | |
| 418 | @Test |
Tim Peng | 8a0f361 | 2020-04-30 12:33:20 +0800 | [diff] [blame^] | 419 | public void adjustSessionVolume_routingSessionInfoIsNull_noCrash() { |
| 420 | mInfoMediaManager.adjustSessionVolume(null, 10); |
| 421 | } |
| 422 | |
| 423 | @Test |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 424 | public void adjustSessionVolume_packageNameIsNull_noCrash() { |
| 425 | mInfoMediaManager.mPackageName = null; |
| 426 | |
| 427 | mInfoMediaManager.adjustSessionVolume(10); |
| 428 | } |
| 429 | |
| 430 | @Test |
| 431 | public void getSessionVolumeMax_packageNameIsNull_returnNotFound() { |
| 432 | mInfoMediaManager.mPackageName = null; |
| 433 | |
| 434 | assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); |
| 435 | } |
| 436 | |
| 437 | @Test |
| 438 | public void getSessionVolumeMax_containPackageName_returnMaxVolume() { |
| 439 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 440 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 441 | routingSessionInfos.add(info); |
| 442 | |
| 443 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 444 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 445 | |
| 446 | mInfoMediaManager.getSessionVolumeMax(); |
| 447 | |
| 448 | verify(info).getVolumeMax(); |
| 449 | } |
| 450 | |
| 451 | @Test |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 452 | public void getSessionVolumeMax_routeSessionInfoIsNull_returnNotFound() { |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 453 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 454 | final RoutingSessionInfo info = null; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 455 | routingSessionInfos.add(info); |
| 456 | |
| 457 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 458 | |
| 459 | assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); |
| 460 | } |
| 461 | |
| 462 | @Test |
| 463 | public void getSessionVolume_packageNameIsNull_returnNotFound() { |
| 464 | mInfoMediaManager.mPackageName = null; |
| 465 | |
| 466 | assertThat(mInfoMediaManager.getSessionVolume()).isEqualTo(-1); |
| 467 | } |
| 468 | |
| 469 | @Test |
| 470 | public void getSessionVolume_containPackageName_returnMaxVolume() { |
| 471 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 472 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 473 | routingSessionInfos.add(info); |
| 474 | |
| 475 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 476 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 477 | |
| 478 | mInfoMediaManager.getSessionVolume(); |
| 479 | |
| 480 | verify(info).getVolume(); |
| 481 | } |
| 482 | |
| 483 | @Test |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 484 | public void getSessionVolume_routeSessionInfoIsNull_returnNotFound() { |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 485 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 486 | final RoutingSessionInfo info = null; |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 487 | routingSessionInfos.add(info); |
| 488 | |
| 489 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
hughchen | 6ab62ca | 2020-02-12 10:40:04 +0800 | [diff] [blame] | 490 | |
| 491 | assertThat(mInfoMediaManager.getSessionVolume()).isEqualTo(-1); |
| 492 | } |
hughchen | 61bced0 | 2020-02-20 18:46:32 +0800 | [diff] [blame] | 493 | |
| 494 | @Test |
Tim Peng | 8a0f361 | 2020-04-30 12:33:20 +0800 | [diff] [blame^] | 495 | public void getActiveMediaSession_returnActiveSession() { |
| 496 | final List<RoutingSessionInfo> infos = new ArrayList<>(); |
| 497 | mShadowRouter2Manager.setActiveSessions(infos); |
| 498 | |
| 499 | assertThat(mInfoMediaManager.getActiveMediaSession()).containsExactlyElementsIn(infos); |
| 500 | } |
| 501 | |
| 502 | @Test |
hughchen | 61bced0 | 2020-02-20 18:46:32 +0800 | [diff] [blame] | 503 | public void releaseSession_packageNameIsNull_returnFalse() { |
| 504 | mInfoMediaManager.mPackageName = null; |
| 505 | |
| 506 | assertThat(mInfoMediaManager.releaseSession()).isFalse(); |
| 507 | } |
| 508 | |
| 509 | @Test |
| 510 | public void releaseSession_removeSuccessfully_returnTrue() { |
| 511 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 512 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 513 | routingSessionInfos.add(info); |
| 514 | |
| 515 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 516 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 517 | |
| 518 | assertThat(mInfoMediaManager.releaseSession()).isTrue(); |
| 519 | } |
Tim Peng | 635b04a | 2020-03-05 13:08:02 +0800 | [diff] [blame] | 520 | |
| 521 | @Test |
| 522 | public void getSessionName_packageNameIsNull_returnNull() { |
| 523 | mInfoMediaManager.mPackageName = null; |
| 524 | |
| 525 | assertThat(mInfoMediaManager.getSessionName()).isNull(); |
| 526 | } |
| 527 | |
| 528 | @Test |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 529 | public void getSessionName_routeSessionInfoIsNull_returnNull() { |
Tim Peng | 635b04a | 2020-03-05 13:08:02 +0800 | [diff] [blame] | 530 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
hughchen | 8e9e4b4 | 2020-03-23 18:59:58 +0800 | [diff] [blame] | 531 | final RoutingSessionInfo info = null; |
Tim Peng | 635b04a | 2020-03-05 13:08:02 +0800 | [diff] [blame] | 532 | routingSessionInfos.add(info); |
| 533 | |
| 534 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
Tim Peng | 635b04a | 2020-03-05 13:08:02 +0800 | [diff] [blame] | 535 | |
| 536 | assertThat(mInfoMediaManager.getSessionName()).isNull(); |
| 537 | } |
| 538 | |
| 539 | @Test |
| 540 | public void getSessionName_containPackageName_returnName() { |
| 541 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 542 | final RoutingSessionInfo info = mock(RoutingSessionInfo.class); |
| 543 | routingSessionInfos.add(info); |
| 544 | |
| 545 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 546 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 547 | when(info.getName()).thenReturn(TEST_NAME); |
| 548 | |
| 549 | assertThat(mInfoMediaManager.getSessionName()).isEqualTo(TEST_NAME); |
| 550 | } |
hughchen | 063a35a | 2020-03-04 17:51:57 +0800 | [diff] [blame] | 551 | |
| 552 | @Test |
| 553 | public void onTransferFailed_shouldDispatchOnRequestFailed() { |
| 554 | mInfoMediaManager.registerCallback(mCallback); |
| 555 | |
| 556 | mInfoMediaManager.mMediaRouterCallback.onTransferFailed(null, null); |
| 557 | |
| 558 | verify(mCallback).onRequestFailed(REASON_UNKNOWN_ERROR); |
| 559 | } |
| 560 | |
| 561 | @Test |
| 562 | public void onRequestFailed_shouldDispatchOnRequestFailed() { |
| 563 | mInfoMediaManager.registerCallback(mCallback); |
| 564 | |
| 565 | mInfoMediaManager.mMediaRouterCallback.onRequestFailed(REASON_NETWORK_ERROR); |
| 566 | |
| 567 | verify(mCallback).onRequestFailed(REASON_NETWORK_ERROR); |
| 568 | } |
hughchen | f961f2c | 2020-03-25 17:14:02 +0800 | [diff] [blame] | 569 | |
| 570 | @Test |
| 571 | public void onTransferred_getAvailableRoutes_shouldAddMediaDevice() { |
| 572 | final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); |
| 573 | final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); |
| 574 | routingSessionInfos.add(sessionInfo); |
| 575 | final List<String> selectedRoutes = new ArrayList<>(); |
| 576 | selectedRoutes.add(TEST_ID); |
| 577 | when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes); |
| 578 | mShadowRouter2Manager.setRoutingSessions(routingSessionInfos); |
| 579 | |
| 580 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 581 | mInfoMediaManager.registerCallback(mCallback); |
| 582 | |
| 583 | when(info.getId()).thenReturn(TEST_ID); |
| 584 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 585 | |
| 586 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 587 | routes.add(info); |
| 588 | mShadowRouter2Manager.setAvailableRoutes(routes); |
| 589 | |
| 590 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 591 | assertThat(mediaDevice).isNull(); |
| 592 | |
| 593 | mInfoMediaManager.mMediaRouterCallback.onTransferred(null, null); |
| 594 | |
| 595 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 596 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 597 | assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice); |
| 598 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 599 | verify(mCallback).onConnectedDeviceChanged(TEST_ID); |
| 600 | } |
| 601 | |
| 602 | @Test |
| 603 | public void onTransferred_buildAllRoutes_shouldAddMediaDevice() { |
| 604 | final MediaRoute2Info info = mock(MediaRoute2Info.class); |
| 605 | mInfoMediaManager.registerCallback(mCallback); |
| 606 | |
| 607 | when(info.getId()).thenReturn(TEST_ID); |
| 608 | when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); |
| 609 | when(info.isSystemRoute()).thenReturn(true); |
| 610 | |
| 611 | final List<MediaRoute2Info> routes = new ArrayList<>(); |
| 612 | routes.add(info); |
| 613 | mShadowRouter2Manager.setAllRoutes(routes); |
| 614 | |
| 615 | final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); |
| 616 | assertThat(mediaDevice).isNull(); |
| 617 | |
| 618 | mInfoMediaManager.mPackageName = ""; |
| 619 | mInfoMediaManager.mMediaRouterCallback.onTransferred(null, null); |
| 620 | |
| 621 | final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); |
| 622 | assertThat(infoDevice.getId()).isEqualTo(TEST_ID); |
| 623 | assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); |
| 624 | verify(mCallback).onConnectedDeviceChanged(null); |
| 625 | } |
hughchen | e8c79b0 | 2020-04-21 17:26:21 +0800 | [diff] [blame] | 626 | |
| 627 | @Test |
| 628 | public void addMediaDevice_verifyDeviceTypeCanCorrespondToMediaDevice() { |
| 629 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 630 | final CachedBluetoothDeviceManager cachedBluetoothDeviceManager = |
| 631 | mock(CachedBluetoothDeviceManager.class); |
| 632 | final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); |
| 633 | |
| 634 | when(route2Info.getType()).thenReturn(TYPE_REMOTE_SPEAKER); |
| 635 | mInfoMediaManager.addMediaDevice(route2Info); |
| 636 | assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof InfoMediaDevice).isTrue(); |
| 637 | |
| 638 | when(route2Info.getType()).thenReturn(TYPE_USB_DEVICE); |
| 639 | mInfoMediaManager.mMediaDevices.clear(); |
| 640 | mInfoMediaManager.addMediaDevice(route2Info); |
| 641 | assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue(); |
| 642 | |
| 643 | when(route2Info.getType()).thenReturn(TYPE_WIRED_HEADSET); |
| 644 | mInfoMediaManager.mMediaDevices.clear(); |
| 645 | mInfoMediaManager.addMediaDevice(route2Info); |
| 646 | assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue(); |
| 647 | |
| 648 | when(route2Info.getType()).thenReturn(TYPE_BLUETOOTH_A2DP); |
| 649 | when(route2Info.getOriginalId()).thenReturn("00:00:00:00:00:00"); |
| 650 | when(mLocalBluetoothManager.getCachedDeviceManager()) |
| 651 | .thenReturn(cachedBluetoothDeviceManager); |
| 652 | when(cachedBluetoothDeviceManager.findDevice(any(BluetoothDevice.class))) |
| 653 | .thenReturn(cachedDevice); |
| 654 | mInfoMediaManager.mMediaDevices.clear(); |
| 655 | mInfoMediaManager.addMediaDevice(route2Info); |
| 656 | assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof BluetoothMediaDevice).isTrue(); |
| 657 | |
| 658 | when(route2Info.getType()).thenReturn(TYPE_BUILTIN_SPEAKER); |
| 659 | mInfoMediaManager.mMediaDevices.clear(); |
| 660 | mInfoMediaManager.addMediaDevice(route2Info); |
| 661 | assertThat(mInfoMediaManager.mMediaDevices.get(0) instanceof PhoneMediaDevice).isTrue(); |
| 662 | } |
hughchen | 71a7f82 | 2020-04-24 14:59:05 +0800 | [diff] [blame] | 663 | |
| 664 | @Test |
| 665 | public void addMediaDevice_cachedBluetoothDeviceIsNull_shouldNotAdded() { |
| 666 | final MediaRoute2Info route2Info = mock(MediaRoute2Info.class); |
| 667 | final CachedBluetoothDeviceManager cachedBluetoothDeviceManager = |
| 668 | mock(CachedBluetoothDeviceManager.class); |
| 669 | |
| 670 | when(route2Info.getType()).thenReturn(TYPE_BLUETOOTH_A2DP); |
| 671 | when(route2Info.getOriginalId()).thenReturn("00:00:00:00:00:00"); |
| 672 | when(mLocalBluetoothManager.getCachedDeviceManager()) |
| 673 | .thenReturn(cachedBluetoothDeviceManager); |
| 674 | when(cachedBluetoothDeviceManager.findDevice(any(BluetoothDevice.class))) |
| 675 | .thenReturn(null); |
| 676 | |
| 677 | mInfoMediaManager.mMediaDevices.clear(); |
| 678 | mInfoMediaManager.addMediaDevice(route2Info); |
| 679 | |
| 680 | assertThat(mInfoMediaManager.mMediaDevices.size()).isEqualTo(0); |
| 681 | } |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 682 | } |