Bug 995696 - Make testNewTab more robust, and enable on Android 2.3; r=snorp

This commit is contained in:
Geoff Brown 2014-07-07 13:19:10 -06:00
parent 6de3623e9b
commit b8f4fda609
3 changed files with 23 additions and 55 deletions

View File

@ -10,6 +10,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import org.json.JSONArray;
import org.json.JSONException;
@ -80,6 +81,7 @@ abstract class BaseTest extends BaseRobocopTest {
protected StringHelper mStringHelper;
protected int mScreenMidWidth;
protected int mScreenMidHeight;
private HashSet<Integer> mKnownTabIDs = new HashSet<Integer>();
protected void blockForGeckoReady() {
try {
@ -554,9 +556,21 @@ abstract class BaseTest extends BaseRobocopTest {
}
}, MAX_WAIT_MS);
mAsserter.ok(success, "waiting for add tab view", "add tab view available");
Actions.EventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow");
final Actions.RepeatedEventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow");
mSolo.clickOnView(mSolo.getView(R.id.add_tab));
pageShowExpecter.blockForEvent();
// Wait until we get a PageShow event for a new tab ID
for(;;) {
try {
JSONObject data = new JSONObject(pageShowExpecter.blockForEventData());
int tabID = data.getInt("tabID");
if (!mKnownTabIDs.contains(tabID)) {
mKnownTabIDs.add(tabID);
break;
}
} catch(JSONException e) {
mAsserter.ok(false, "Exception in addTab", getStackTraceString(e));
}
}
pageShowExpecter.unregisterListener();
}
@ -567,6 +581,12 @@ abstract class BaseTest extends BaseRobocopTest {
inputAndLoadUrl(url);
}
public void closeAddedTabs() {
for(int tabID : mKnownTabIDs) {
closeTab(tabID);
}
}
/**
* Gets the AdapterView of the tabs list.
*

View File

@ -59,8 +59,6 @@ skip-if = android_version == "10" || processor == "x86"
# disabled on 4.0; bug 1006242
# skip-if = android_version == "10" || android_version == "15"
[testNewTab]
# disabled on 2.3; bug 995696
skip-if = android_version == "10"
[testOverscroll]
# disabled on 2.3; bug 836818
skip-if = android_version == "10"

View File

@ -42,57 +42,7 @@ public class testNewTab extends BaseTest {
mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased");
// cleanup: close all opened tabs
//closeTabs();
}
private void closeTabs() {
final int closeTabId = closeTab.getId();
String tabCountText = null;
// open tabs panel
boolean clicked = tabs.click();
if (!clicked) {
mAsserter.ok(clicked != false, "checking that tabs clicked", "tabs element clicked");
}
// wait for closeTab to appear (this is usually immediate)
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
View closeTabView = getActivity().findViewById(closeTabId);
if (closeTabView == null) {
return false;
}
return true;
}
}, MAX_WAIT_MS);
if (!success) {
mAsserter.ok(success != false, "waiting for close tab view", "close tab view available");
}
// close tabs until only one remains
tabCountText = tabCount.getText();
tabCountInt = Integer.parseInt(tabCountText);
while (tabCountInt > 1) {
clicked = closeTab.click();
if (!clicked) {
mAsserter.ok(clicked != false, "checking that close_tab clicked", "close_tab element clicked");
}
success = waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
String newTabCountText = tabCount.getText();
int newTabCount = Integer.parseInt(newTabCountText);
if (newTabCount < tabCountInt) {
tabCountInt = newTabCount;
return true;
}
return false;
}
}, MAX_WAIT_MS);
mAsserter.ok(success, "Checking tab closed", "number of tabs now "+tabCountInt);
}
closeAddedTabs();
}
private void getTabCount(final int expected) {