Search in sources :

Example 21 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class Tab method swapWebContents.

/** This is currently called when committing a pre-rendered page. */
@VisibleForTesting
@CalledByNative
public void swapWebContents(WebContents webContents, boolean didStartLoad, boolean didFinishLoad) {
    ContentViewCore cvc = new ContentViewCore(mThemedApplicationContext, PRODUCT_VERSION);
    ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
    cv.setContentDescription(mThemedApplicationContext.getResources().getString(R.string.accessibility_content_view));
    cvc.initialize(ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents, getWindowAndroid());
    swapContentViewCore(cvc, false, didStartLoad, didFinishLoad);
}
Also used : ContentViewCore(org.chromium.content.browser.ContentViewCore) ContentView(org.chromium.content.browser.ContentView) VisibleForTesting(org.chromium.base.VisibleForTesting) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 22 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class AbstractMediaRouteController method setPlayerStateForMediaItemState.

@VisibleForTesting
void setPlayerStateForMediaItemState(int state) {
    PlayerState playerState = PlayerState.STOPPED;
    switch(state) {
        case MediaItemStatus.PLAYBACK_STATE_BUFFERING:
            playerState = PlayerState.LOADING;
            break;
        case MediaItemStatus.PLAYBACK_STATE_CANCELED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_ERROR:
            playerState = PlayerState.ERROR;
            break;
        case MediaItemStatus.PLAYBACK_STATE_FINISHED:
            playerState = PlayerState.FINISHED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_INVALIDATED:
            playerState = PlayerState.INVALIDATED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PAUSED:
            if (isAtEndOfVideo(getPosition(), getDuration())) {
                playerState = PlayerState.FINISHED;
            } else {
                playerState = PlayerState.PAUSED;
            }
            break;
        case MediaItemStatus.PLAYBACK_STATE_PENDING:
            playerState = PlayerState.PAUSED;
            break;
        case MediaItemStatus.PLAYBACK_STATE_PLAYING:
            playerState = PlayerState.PLAYING;
            break;
        default:
            break;
    }
    mRemotePlayerState = playerState;
}
Also used : PlayerState(org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 23 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class DelayedInvalidationsController method addPendingInvalidation.

/**
     * Stores preferences to indicate that an invalidation has arrived, but dropped on the floor.
     */
@VisibleForTesting
void addPendingInvalidation(Context context, String account, PendingInvalidation invalidation) {
    SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
    String oldAccount = prefs.getString(DELAYED_ACCOUNT_NAME, null);
    // Make sure to construct a new set so it can be modified safely. See crbug.com/568369.
    Set<String> invals = new HashSet<String>(prefs.getStringSet(DELAYED_INVALIDATIONS, new HashSet<String>(1)));
    assert invals.isEmpty() || oldAccount != null;
    if (oldAccount != null && !oldAccount.equals(account)) {
        invals.clear();
    }
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(DELAYED_ACCOUNT_NAME, account);
    if (invalidation.mObjectSource == 0 || (oldAccount != null && invals.isEmpty())) {
        editor.putStringSet(DELAYED_INVALIDATIONS, null);
    } else {
        invals.add(invalidation.encodeToString());
        editor.putStringSet(DELAYED_INVALIDATIONS, invals);
    }
    editor.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences) HashSet(java.util.HashSet) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 24 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class CastMessageHandler method buildInternalMessage.

@VisibleForTesting
String buildInternalMessage(String type, String message, String clientId, int sequenceNumber) {
    JSONObject json = new JSONObject();
    try {
        json.put("type", type);
        json.put("sequenceNumber", sequenceNumber);
        json.put("timeoutMillis", 0);
        json.put("clientId", clientId);
        // messages.
        if (message == null || "remove_session".equals(type) || "disconnect_session".equals(type)) {
            json.put("message", message);
        } else {
            JSONObject jsonMessage = new JSONObject(message);
            if ("v2_message".equals(type) && "MEDIA_STATUS".equals(jsonMessage.getString("type"))) {
                sanitizeMediaStatusMessage(jsonMessage);
            }
            json.put("message", jsonMessage);
        }
    } catch (JSONException e) {
        Log.e(TAG, "Failed to build the reply: " + e);
    }
    return json.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 25 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class CastMessageHandler method handleAppMessage.

// An example of the Cast application message:
// {
//   "type":"app_message",
//   "message": {
//     "sessionId":"...",
//     "namespaceName":"...",
//     "message": ...
//   },
//   "sequenceNumber":0,
//   "timeoutMillis":3000,
//   "clientId":"14417311915272175"
// }
@VisibleForTesting
boolean handleAppMessage(JSONObject jsonMessage) throws JSONException {
    assert "app_message".equals(jsonMessage.getString("type"));
    String clientId = jsonMessage.getString("clientId");
    if (clientId == null || !mRouteProvider.getClients().contains(clientId))
        return false;
    JSONObject jsonAppMessageWrapper = jsonMessage.getJSONObject("message");
    if (!mSession.getSessionId().equals(jsonAppMessageWrapper.getString("sessionId"))) {
        return false;
    }
    String namespaceName = jsonAppMessageWrapper.getString("namespaceName");
    if (namespaceName == null || namespaceName.isEmpty())
        return false;
    if (!mSession.getNamespaces().contains(namespaceName))
        return false;
    int sequenceNumber = jsonMessage.optInt("sequenceNumber", INVALID_SEQUENCE_NUMBER);
    Object actualMessageObject = jsonAppMessageWrapper.get("message");
    if (actualMessageObject == null)
        return false;
    if (actualMessageObject instanceof String) {
        String actualMessage = jsonAppMessageWrapper.getString("message");
        return mSession.sendStringCastMessage(actualMessage, namespaceName, clientId, sequenceNumber);
    }
    JSONObject actualMessage = jsonAppMessageWrapper.getJSONObject("message");
    return sendJsonCastMessage(actualMessage, namespaceName, clientId, sequenceNumber);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2