| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.media.router; | 5 package org.chromium.chrome.browser.media.router; |
| 6 | 6 |
| 7 import android.content.Context; |
| 8 |
| 7 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
| 8 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 9 import org.chromium.chrome.browser.media.router.cast.MediaSink; | 11 import org.chromium.chrome.browser.media.router.cast.MediaSink; |
| 10 | 12 |
| 11 import java.util.ArrayList; | 13 import java.util.ArrayList; |
| 12 import java.util.HashMap; | 14 import java.util.HashMap; |
| 13 import java.util.Map; | 15 import java.util.Map; |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Mocked {@link MediaRouteProvider}. | 18 * Mocked {@link MediaRouteProvider}. |
| 17 */ | 19 */ |
| 18 public class MockMediaRouteProvider implements MediaRouteProvider { | 20 public class MockMediaRouteProvider implements MediaRouteProvider { |
| 19 private static final String TAG = "MediaRouter"; | 21 private static final String TAG = "MediaRouter"; |
| 20 | 22 |
| 21 private static final String SINK_ID1 = "test_sink_id_1"; | 23 private static final String SINK_ID1 = "test_sink_id_1"; |
| 22 private static final String SINK_ID2 = "test_sink_id_2"; | 24 private static final String SINK_ID2 = "test_sink_id_2"; |
| 23 private static final String SINK_NAME1 = "test-sink-1"; | 25 private static final String SINK_NAME1 = "test-sink-1"; |
| 24 private static final String SINK_NAME2 = "test-sink-2"; | 26 private static final String SINK_NAME2 = "test-sink-2"; |
| 25 | 27 |
| 28 private Context mApplicationContext; |
| 26 private MediaRouteManager mManager; | 29 private MediaRouteManager mManager; |
| 27 | 30 |
| 28 private final Map<String, MediaRoute> mRoutes = new HashMap<String, MediaRou
te>(); | 31 private final Map<String, MediaRoute> mRoutes = new HashMap<String, MediaRou
te>(); |
| 29 private final Map<String, MediaRoute> mPresentationIdToRoute = | 32 private final Map<String, MediaRoute> mPresentationIdToRoute = |
| 30 new HashMap<String, MediaRoute>(); | 33 new HashMap<String, MediaRoute>(); |
| 31 | 34 |
| 32 private int mSinksObservedDelayMillis = 0; | 35 private int mSinksObservedDelayMillis = 0; |
| 33 private int mCreateRouteDelayMillis = 0; | 36 private int mCreateRouteDelayMillis = 0; |
| 34 private boolean mIsSupportsSource = true; | 37 private boolean mIsSupportsSource = true; |
| 35 private String mCreateRouteErrorMessage = null; | 38 private String mCreateRouteErrorMessage = null; |
| 36 private String mJoinRouteErrorMessage = null; | 39 private String mJoinRouteErrorMessage = null; |
| 37 private boolean mCloseRouteWithErrorOnSend = false; | 40 private boolean mCloseRouteWithErrorOnSend = false; |
| 38 | 41 |
| 39 /** | 42 /** |
| 40 * Builder for {@link MockMediaRouteProvider}. | 43 * Builder for {@link MockMediaRouteProvider}. |
| 41 */ | 44 */ |
| 42 public static class Builder implements MediaRouteProvider.Builder { | 45 public static class Builder implements MediaRouteProvider.Builder { |
| 43 public static final MockMediaRouteProvider sProvider = new MockMediaRout
eProvider(); | 46 public static final MockMediaRouteProvider sProvider = new MockMediaRout
eProvider(); |
| 44 | 47 |
| 45 @Override | 48 @Override |
| 46 public MediaRouteProvider create(MediaRouteManager manager) { | 49 public MediaRouteProvider create(Context applicationContext, MediaRouteM
anager manager) { |
| 50 sProvider.mApplicationContext = applicationContext; |
| 47 sProvider.mManager = manager; | 51 sProvider.mManager = manager; |
| 48 return sProvider; | 52 return sProvider; |
| 49 } | 53 } |
| 50 } | 54 } |
| 51 | 55 |
| 52 private MockMediaRouteProvider() {} | 56 private MockMediaRouteProvider() {} |
| 53 | 57 |
| 54 public void setCreateRouteDelayMillis(int delayMillis) { | 58 public void setCreateRouteDelayMillis(int delayMillis) { |
| 55 assert delayMillis >= 0; | 59 assert delayMillis >= 0; |
| 56 mCreateRouteDelayMillis = delayMillis; | 60 mCreateRouteDelayMillis = delayMillis; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 174 |
| 171 @Override | 175 @Override |
| 172 public void sendStringMessage(String routeId, String message, int nativeCall
backId) { | 176 public void sendStringMessage(String routeId, String message, int nativeCall
backId) { |
| 173 if (mCloseRouteWithErrorOnSend) { | 177 if (mCloseRouteWithErrorOnSend) { |
| 174 mManager.onRouteClosedWithError(routeId, "Sending message failed. Cl
osing the route."); | 178 mManager.onRouteClosedWithError(routeId, "Sending message failed. Cl
osing the route."); |
| 175 } else { | 179 } else { |
| 176 mManager.onMessage(routeId, "Pong: " + message); | 180 mManager.onMessage(routeId, "Pong: " + message); |
| 177 } | 181 } |
| 178 } | 182 } |
| 179 } | 183 } |
| OLD | NEW |