mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
Bug 1236431 - Use contentDescription to verify URL in tests. r=mcomella
MozReview-Commit-ID: IrcsLaNExEM --HG-- extra : rebase_source : 5cf0a2dc496f67e000016a9f9a0094a7e1354122
This commit is contained in:
parent
3e4f6499b8
commit
ac57938a24
@ -235,6 +235,7 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout {
|
||||
// "Enter Search or Address" placeholder text.
|
||||
if (AboutPages.isTitlelessAboutPage(url)) {
|
||||
setTitle(null);
|
||||
setContentDescription(null);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,6 +247,7 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout {
|
||||
builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
setTitle(builder);
|
||||
setContentDescription(null);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -257,9 +259,13 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout {
|
||||
strippedURL = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(strippedURL));
|
||||
}
|
||||
|
||||
// This value is not visible to screen readers but we rely on it when running UI tests. Screen
|
||||
// readers will instead focus BrowserToolbar and read the "base domain" from there. UI tests
|
||||
// will read the content description to obtain the full URL for performing assertions.
|
||||
setContentDescription(strippedURL);
|
||||
|
||||
if (!TextUtils.isEmpty(baseDomain)) {
|
||||
setTitle(baseDomain);
|
||||
setContentDescription(strippedURL);
|
||||
} else {
|
||||
setTitle(strippedURL);
|
||||
}
|
||||
|
@ -249,6 +249,22 @@ abstract class BaseTest extends BaseRobocopTest {
|
||||
}
|
||||
}
|
||||
|
||||
class VerifyContentDescription implements Condition {
|
||||
private final View view;
|
||||
private final String expected;
|
||||
|
||||
public VerifyContentDescription(View view, String expected) {
|
||||
this.view = view;
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied() {
|
||||
final CharSequence actual = view.getContentDescription();
|
||||
return TextUtils.equals(actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
protected final String getAbsoluteUrl(String url) {
|
||||
return mBaseHostnameUrl + "/" + url.replaceAll("(^/)", "");
|
||||
}
|
||||
@ -471,6 +487,33 @@ abstract class BaseTest extends BaseRobocopTest {
|
||||
mAsserter.is(pageTitle, expected, "Page title is correct");
|
||||
}
|
||||
|
||||
public final void verifyUrlInContentDescription(String url) {
|
||||
mAsserter.isnot(url, null, "The url argument is not null");
|
||||
|
||||
final String expected;
|
||||
if (mStringHelper.ABOUT_HOME_URL.equals(url)) {
|
||||
expected = mStringHelper.ABOUT_HOME_TITLE;
|
||||
} else if (url.startsWith(URL_HTTP_PREFIX)) {
|
||||
expected = url.substring(URL_HTTP_PREFIX.length());
|
||||
} else {
|
||||
expected = url;
|
||||
}
|
||||
|
||||
final View urlDisplayLayout = mSolo.getView(R.id.display_layout);
|
||||
assertNotNull("ToolbarDisplayLayout is not null", urlDisplayLayout);
|
||||
|
||||
String actualUrl = null;
|
||||
|
||||
// Wait for the title to make sure it has been displayed in case the view
|
||||
// does not update fast enough
|
||||
waitForCondition(new VerifyContentDescription(urlDisplayLayout, expected), MAX_WAIT_VERIFY_PAGE_TITLE_MS);
|
||||
if (urlDisplayLayout.getContentDescription() != null) {
|
||||
actualUrl = urlDisplayLayout.getContentDescription().toString();
|
||||
}
|
||||
|
||||
mAsserter.is(actualUrl, expected, "Url is correct");
|
||||
}
|
||||
|
||||
public final void verifyTabCount(int expectedTabCount) {
|
||||
Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter);
|
||||
String tabCountText = tabCount.getText();
|
||||
|
@ -63,7 +63,9 @@ public class ToolbarComponent extends BaseComponent {
|
||||
expected = absoluteURL;
|
||||
}
|
||||
|
||||
fAssertEquals("The Toolbar title is " + expected, expected, getTitle());
|
||||
// Since we only display a shortened "base domain" (See bug 1236431) we use the content
|
||||
// description to obtain the full URL.
|
||||
fAssertEquals("The Toolbar title is " + expected, expected, getUrlFromContentDescription());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -148,8 +150,15 @@ public class ToolbarComponent extends BaseComponent {
|
||||
return getToolbarView().findViewById(R.id.edit_cancel);
|
||||
}
|
||||
|
||||
private String getTitle() {
|
||||
return getTitleHelper(true);
|
||||
private String getUrlFromContentDescription() {
|
||||
assertIsNotEditing();
|
||||
|
||||
final CharSequence contentDescription = getUrlDisplayLayout().getContentDescription();
|
||||
if (contentDescription == null) {
|
||||
return "";
|
||||
} else {
|
||||
return contentDescription.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,14 +19,14 @@ public class testAboutPage extends PixelTest {
|
||||
String url = mStringHelper.ABOUT_SCHEME;
|
||||
loadAndPaint(url);
|
||||
|
||||
verifyUrlBarTitle(url);
|
||||
verifyUrlInContentDescription(url);
|
||||
|
||||
// Open a new page to remove the about: page from the current tab.
|
||||
url = getAbsoluteUrl(mStringHelper.ROBOCOP_BLANK_PAGE_01_URL);
|
||||
loadUrlAndWait(url);
|
||||
|
||||
// At this point the page title should have been set.
|
||||
verifyUrlBarTitle(url);
|
||||
verifyUrlInContentDescription(url);
|
||||
|
||||
// Set up listeners to catch the page load we're about to do.
|
||||
Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
|
||||
@ -42,6 +42,6 @@ public class testAboutPage extends PixelTest {
|
||||
contentEventExpecter.unregisterListener();
|
||||
|
||||
// Make sure the about: page was loaded.
|
||||
verifyUrlBarTitle(mStringHelper.ABOUT_SCHEME);
|
||||
verifyUrlInContentDescription(mStringHelper.ABOUT_SCHEME);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class testPictureLinkContextMenu extends ContentContextMenuTest {
|
||||
PICTURE_PAGE_URL=getAbsoluteUrl(mStringHelper.ROBOCOP_PICTURE_LINK_URL);
|
||||
BLANK_PAGE_URL=getAbsoluteUrl(mStringHelper.ROBOCOP_BLANK_PAGE_02_URL);
|
||||
loadAndPaint(PICTURE_PAGE_URL);
|
||||
verifyUrlBarTitle(PICTURE_PAGE_URL);
|
||||
verifyUrlInContentDescription(PICTURE_PAGE_URL);
|
||||
|
||||
switchTabs(imageTitle);
|
||||
verifyContextMenuItems(photoMenuItems);
|
||||
|
Loading…
Reference in New Issue
Block a user