Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/media/router/MockMediaRouteProvider.java

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
9 import org.chromium.base.Log; 7 import org.chromium.base.Log;
10 import org.chromium.base.ThreadUtils; 8 import org.chromium.base.ThreadUtils;
11 import org.chromium.chrome.browser.media.router.cast.MediaSink; 9 import org.chromium.chrome.browser.media.router.cast.MediaSink;
12 10
13 import java.util.ArrayList; 11 import java.util.ArrayList;
14 import java.util.HashMap; 12 import java.util.HashMap;
15 import java.util.Map; 13 import java.util.Map;
16 14
17 /** 15 /**
18 * Mocked {@link MediaRouteProvider}. 16 * Mocked {@link MediaRouteProvider}.
19 */ 17 */
20 public class MockMediaRouteProvider implements MediaRouteProvider { 18 public class MockMediaRouteProvider implements MediaRouteProvider {
21 private static final String TAG = "MediaRouter"; 19 private static final String TAG = "MediaRouter";
22 20
23 private static final String SINK_ID1 = "test_sink_id_1"; 21 private static final String SINK_ID1 = "test_sink_id_1";
24 private static final String SINK_ID2 = "test_sink_id_2"; 22 private static final String SINK_ID2 = "test_sink_id_2";
25 private static final String SINK_NAME1 = "test-sink-1"; 23 private static final String SINK_NAME1 = "test-sink-1";
26 private static final String SINK_NAME2 = "test-sink-2"; 24 private static final String SINK_NAME2 = "test-sink-2";
27 25
28 private Context mApplicationContext;
29 private MediaRouteManager mManager; 26 private MediaRouteManager mManager;
30 27
31 private final Map<String, MediaRoute> mRoutes = new HashMap<String, MediaRou te>(); 28 private final Map<String, MediaRoute> mRoutes = new HashMap<String, MediaRou te>();
32 private final Map<String, MediaRoute> mPresentationIdToRoute = 29 private final Map<String, MediaRoute> mPresentationIdToRoute =
33 new HashMap<String, MediaRoute>(); 30 new HashMap<String, MediaRoute>();
34 31
35 private int mSinksObservedDelayMillis = 0; 32 private int mSinksObservedDelayMillis = 0;
36 private int mCreateRouteDelayMillis = 0; 33 private int mCreateRouteDelayMillis = 0;
37 private boolean mIsSupportsSource = true; 34 private boolean mIsSupportsSource = true;
38 private String mCreateRouteErrorMessage = null; 35 private String mCreateRouteErrorMessage = null;
39 private String mJoinRouteErrorMessage = null; 36 private String mJoinRouteErrorMessage = null;
40 private boolean mCloseRouteWithErrorOnSend = false; 37 private boolean mCloseRouteWithErrorOnSend = false;
41 38
42 /** 39 /**
43 * Builder for {@link MockMediaRouteProvider}. 40 * Builder for {@link MockMediaRouteProvider}.
44 */ 41 */
45 public static class Builder implements MediaRouteProvider.Builder { 42 public static class Builder implements MediaRouteProvider.Builder {
46 public static final MockMediaRouteProvider sProvider = new MockMediaRout eProvider(); 43 public static final MockMediaRouteProvider sProvider = new MockMediaRout eProvider();
47 44
48 @Override 45 @Override
49 public MediaRouteProvider create(Context applicationContext, MediaRouteM anager manager) { 46 public MediaRouteProvider create(MediaRouteManager manager) {
50 sProvider.mApplicationContext = applicationContext;
51 sProvider.mManager = manager; 47 sProvider.mManager = manager;
52 return sProvider; 48 return sProvider;
53 } 49 }
54 } 50 }
55 51
56 private MockMediaRouteProvider() {} 52 private MockMediaRouteProvider() {}
57 53
58 public void setCreateRouteDelayMillis(int delayMillis) { 54 public void setCreateRouteDelayMillis(int delayMillis) {
59 assert delayMillis >= 0; 55 assert delayMillis >= 0;
60 mCreateRouteDelayMillis = delayMillis; 56 mCreateRouteDelayMillis = delayMillis;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 170
175 @Override 171 @Override
176 public void sendStringMessage(String routeId, String message, int nativeCall backId) { 172 public void sendStringMessage(String routeId, String message, int nativeCall backId) {
177 if (mCloseRouteWithErrorOnSend) { 173 if (mCloseRouteWithErrorOnSend) {
178 mManager.onRouteClosedWithError(routeId, "Sending message failed. Cl osing the route."); 174 mManager.onRouteClosedWithError(routeId, "Sending message failed. Cl osing the route.");
179 } else { 175 } else {
180 mManager.onMessage(routeId, "Pong: " + message); 176 mManager.onMessage(routeId, "Pong: " + message);
181 } 177 }
182 } 178 }
183 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698