This source file includes following definitions.
- getOnPageStartedHelper
- getOnPageFinishedHelper
- getOnReceivedErrorHelper
- getOnEvaluateJavaScriptResultHelper
- getShouldOverrideUrlLoadingHelper
- getAddMessageToConsoleHelper
- notifyCalled
- getLastScaleRatio
- getOnScaleChangedHelper
- getPictureListenerHelper
- onReceivedTitle
- getUpdatedTitle
- onPageStarted
- onPageFinished
- onReceivedError
- onConsoleMessage
- getLevel
- getMessage
- getLineNumber
- getSourceId
- notifyCalled
- onScaleChangedScaled
- getPicture
- notifyCalled
- onNewPicture
- setShouldOverrideUrlLoadingUrl
- setPreviousShouldOverrideUrlLoadingUrl
- setShouldOverrideUrlLoadingReturnValue
- getShouldOverrideUrlLoadingUrl
- getPreviousShouldOverrideUrlLoadingUrl
- getShouldOverrideUrlLoadingReturnValue
- notifyCalled
- shouldOverrideUrlLoading
package org.chromium.android_webview.test;
import android.graphics.Picture;
import android.webkit.ConsoleMessage;
import org.chromium.base.ThreadUtils;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageStartedHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper;
class TestAwContentsClient extends NullContentsClient {
private String mUpdatedTitle;
private final OnPageStartedHelper mOnPageStartedHelper;
private final OnPageFinishedHelper mOnPageFinishedHelper;
private final OnReceivedErrorHelper mOnReceivedErrorHelper;
private final OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHelper;
private final AddMessageToConsoleHelper mAddMessageToConsoleHelper;
private final OnScaleChangedHelper mOnScaleChangedHelper;
private final PictureListenerHelper mPictureListenerHelper;
private final ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper;
public TestAwContentsClient() {
super(ThreadUtils.getUiThreadLooper());
mOnPageStartedHelper = new OnPageStartedHelper();
mOnPageFinishedHelper = new OnPageFinishedHelper();
mOnReceivedErrorHelper = new OnReceivedErrorHelper();
mOnEvaluateJavaScriptResultHelper = new OnEvaluateJavaScriptResultHelper();
mAddMessageToConsoleHelper = new AddMessageToConsoleHelper();
mOnScaleChangedHelper = new OnScaleChangedHelper();
mPictureListenerHelper = new PictureListenerHelper();
mShouldOverrideUrlLoadingHelper = new ShouldOverrideUrlLoadingHelper();
}
public OnPageStartedHelper getOnPageStartedHelper() {
return mOnPageStartedHelper;
}
public OnPageFinishedHelper getOnPageFinishedHelper() {
return mOnPageFinishedHelper;
}
public OnReceivedErrorHelper getOnReceivedErrorHelper() {
return mOnReceivedErrorHelper;
}
public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper() {
return mOnEvaluateJavaScriptResultHelper;
}
public ShouldOverrideUrlLoadingHelper getShouldOverrideUrlLoadingHelper() {
return mShouldOverrideUrlLoadingHelper;
}
public AddMessageToConsoleHelper getAddMessageToConsoleHelper() {
return mAddMessageToConsoleHelper;
}
public static class OnScaleChangedHelper extends CallbackHelper {
private float mPreviousScale;
private float mCurrentScale;
public void notifyCalled(float oldScale, float newScale) {
mPreviousScale = oldScale;
mCurrentScale = newScale;
super.notifyCalled();
}
public float getLastScaleRatio() {
assert getCallCount() > 0;
return mCurrentScale / mPreviousScale;
}
}
public OnScaleChangedHelper getOnScaleChangedHelper() {
return mOnScaleChangedHelper;
}
public PictureListenerHelper getPictureListenerHelper() {
return mPictureListenerHelper;
}
@Override
public void onReceivedTitle(String title) {
mUpdatedTitle = title;
}
public String getUpdatedTitle() {
return mUpdatedTitle;
}
@Override
public void onPageStarted(String url) {
mOnPageStartedHelper.notifyCalled(url);
}
@Override
public void onPageFinished(String url) {
mOnPageFinishedHelper.notifyCalled(url);
}
@Override
public void onReceivedError(int errorCode, String description, String failingUrl) {
mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl);
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
mAddMessageToConsoleHelper.notifyCalled(consoleMessage.messageLevel().ordinal(),
consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId());
return false;
}
public static class AddMessageToConsoleHelper extends CallbackHelper {
private int mLevel;
private String mMessage;
private int mLineNumber;
private String mSourceId;
public int getLevel() {
assert getCallCount() > 0;
return mLevel;
}
public String getMessage() {
assert getCallCount() > 0;
return mMessage;
}
public int getLineNumber() {
assert getCallCount() > 0;
return mLineNumber;
}
public String getSourceId() {
assert getCallCount() > 0;
return mSourceId;
}
void notifyCalled(int level, String message, int lineNumer, String sourceId) {
mLevel = level;
mMessage = message;
mLineNumber = lineNumer;
mSourceId = sourceId;
notifyCalled();
}
}
@Override
public void onScaleChangedScaled(float oldScale, float newScale) {
mOnScaleChangedHelper.notifyCalled(oldScale, newScale);
}
public static class PictureListenerHelper extends CallbackHelper {
private Picture mPicture;
public Picture getPicture() {
assert getCallCount() > 0;
return mPicture;
}
void notifyCalled(Picture picture) {
mPicture = picture;
notifyCalled();
}
}
@Override
public void onNewPicture(Picture picture) {
mPictureListenerHelper.notifyCalled(picture);
}
public static class ShouldOverrideUrlLoadingHelper extends CallbackHelper {
private String mShouldOverrideUrlLoadingUrl;
private String mPreviousShouldOverrideUrlLoadingUrl;
private boolean mShouldOverrideUrlLoadingReturnValue = false;
void setShouldOverrideUrlLoadingUrl(String url) {
mShouldOverrideUrlLoadingUrl = url;
}
void setPreviousShouldOverrideUrlLoadingUrl(String url) {
mPreviousShouldOverrideUrlLoadingUrl = url;
}
void setShouldOverrideUrlLoadingReturnValue(boolean value) {
mShouldOverrideUrlLoadingReturnValue = value;
}
public String getShouldOverrideUrlLoadingUrl() {
assert getCallCount() > 0;
return mShouldOverrideUrlLoadingUrl;
}
public String getPreviousShouldOverrideUrlLoadingUrl() {
assert getCallCount() > 1;
return mPreviousShouldOverrideUrlLoadingUrl;
}
public boolean getShouldOverrideUrlLoadingReturnValue() {
return mShouldOverrideUrlLoadingReturnValue;
}
public void notifyCalled(String url) {
mPreviousShouldOverrideUrlLoadingUrl = mShouldOverrideUrlLoadingUrl;
mShouldOverrideUrlLoadingUrl = url;
notifyCalled();
}
}
@Override
public boolean shouldOverrideUrlLoading(String url) {
super.shouldOverrideUrlLoading(url);
boolean returnValue =
mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingReturnValue();
mShouldOverrideUrlLoadingHelper.notifyCalled(url);
return returnValue;
}
}