This source file includes following definitions.
- openLanguagePanel
- verifyInfoBarText
- findInfoBarText
package org.chromium.chrome.test.util;
import android.test.ActivityInstrumentationTestCase2;
import android.text.SpannableString;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.content.browser.test.util.TestTouchUtils;
public class TranslateUtil {
public static boolean openLanguagePanel(ActivityInstrumentationTestCase2<?> test,
InfoBar infoBar) {
View view = infoBar.getContentWrapper().findViewById(R.id.infobar_message);
if (view == null) {
return false;
}
TextView text = (TextView) view.findViewById(R.id.infobar_message);
SpannableString spannable = (SpannableString) text.getText();
ClickableSpan[] clickable =
spannable.getSpans(0, spannable.length() -1, ClickableSpan.class);
if (clickable.length <= 0) {
return false;
}
int x = spannable.getSpanStart(clickable[0]) + 1;
float nChars = text.getLayout().getLineVisibleEnd(0);
float sizePerChar = text.getLayout().getLineWidth(0) / nChars;
float xPos = text.getPaddingLeft() + (sizePerChar * x);
float yPos = text.getHeight() / (float) 2;
TestTouchUtils.singleClickView(test.getInstrumentation(), text, (int) xPos, (int) yPos);
return verifyInfoBarText(infoBar,
test.getActivity().getString(R.string.translate_infobar_change_languages));
}
public static boolean verifyInfoBarText(InfoBar infoBar, String text) {
View view = infoBar.getContentWrapper().findViewById(R.id.infobar_message);
if (view == null) {
return false;
}
String infoBarText = findInfoBarText(view);
return text.equals(infoBarText);
}
private static String findInfoBarText(View view) {
TextView text = (TextView) view.findViewById(R.id.infobar_message);
return text != null ? text.getText().toString() : null;
}
}