mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1067060: Refactor PanelType usage in Robocop. r=mcomella
This commit is contained in:
parent
1ffc4fea6c
commit
0c01e54769
@ -18,6 +18,10 @@ import android.widget.TextView;
|
||||
|
||||
import com.jayway.android.robotium.solo.Condition;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A class representing any interactions that take place on the Awesomescreen.
|
||||
@ -37,22 +41,21 @@ public class AboutHomeComponent extends BaseComponent {
|
||||
// TODO: Having a specific ordering of panels is prone to fail and thus temporary.
|
||||
// Hopefully the work in bug 940565 will alleviate the need for these enums.
|
||||
// Explicit ordering of HomePager panels on a phone.
|
||||
private enum PhonePanel {
|
||||
RECENT_TABS,
|
||||
HISTORY,
|
||||
TOP_SITES,
|
||||
BOOKMARKS,
|
||||
READING_LIST
|
||||
}
|
||||
private static final PanelType[] PANEL_ORDERING_PHONE = {
|
||||
PanelType.RECENT_TABS,
|
||||
PanelType.HISTORY,
|
||||
PanelType.TOP_SITES,
|
||||
PanelType.BOOKMARKS,
|
||||
PanelType.READING_LIST
|
||||
};
|
||||
|
||||
// Explicit ordering of HomePager panels on a tablet.
|
||||
private enum TabletPanel {
|
||||
TOP_SITES,
|
||||
BOOKMARKS,
|
||||
READING_LIST,
|
||||
HISTORY,
|
||||
RECENT_TABS
|
||||
}
|
||||
private static final PanelType[] PANEL_ORDERING_TABLET = {
|
||||
PanelType.TOP_SITES,
|
||||
PanelType.BOOKMARKS,
|
||||
PanelType.READING_LIST,
|
||||
PanelType.HISTORY,
|
||||
PanelType.RECENT_TABS
|
||||
};
|
||||
|
||||
// The percentage of the panel to swipe between 0 and 1. This value was set through
|
||||
// testing: 0.55f was tested on try and fails on armv6 devices.
|
||||
@ -77,7 +80,7 @@ public class AboutHomeComponent extends BaseComponent {
|
||||
public AboutHomeComponent assertCurrentPanel(final PanelType expectedPanel) {
|
||||
assertVisible();
|
||||
|
||||
final int expectedPanelIndex = getPanelIndexForDevice(expectedPanel.ordinal());
|
||||
final int expectedPanelIndex = getPanelIndexForDevice(expectedPanel);
|
||||
fAssertEquals("The current HomePager panel is " + expectedPanel,
|
||||
expectedPanelIndex, getHomePagerView().getCurrentItem());
|
||||
return this;
|
||||
@ -161,8 +164,7 @@ public class AboutHomeComponent extends BaseComponent {
|
||||
|
||||
// The panel on the left is a lower index and vice versa.
|
||||
final int unboundedPanelIndex = panelIndex + (panelDirection == Solo.LEFT ? -1 : 1);
|
||||
final int panelCount = DeviceHelper.isTablet() ?
|
||||
TabletPanel.values().length : PhonePanel.values().length;
|
||||
final int panelCount = getPanelOrderingForDevice().length;
|
||||
final int maxPanelIndex = panelCount - 1;
|
||||
final int expectedPanelIndex = Math.min(Math.max(0, unboundedPanelIndex), maxPanelIndex);
|
||||
|
||||
@ -170,12 +172,7 @@ public class AboutHomeComponent extends BaseComponent {
|
||||
}
|
||||
|
||||
private void waitForPanelIndex(final int expectedIndex) {
|
||||
final String panelName;
|
||||
if (DeviceHelper.isTablet()) {
|
||||
panelName = TabletPanel.values()[expectedIndex].name();
|
||||
} else {
|
||||
panelName = PhonePanel.values()[expectedIndex].name();
|
||||
}
|
||||
final String panelName = getPanelOrderingForDevice()[expectedIndex].name();
|
||||
|
||||
WaitHelper.waitFor("HomePager " + panelName + " panel", new Condition() {
|
||||
@Override
|
||||
@ -186,13 +183,19 @@ public class AboutHomeComponent extends BaseComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the panel index in the device specific Panel enum for the given index in the
|
||||
* PanelType enum.
|
||||
* Get the expected panel index for the given PanelType on this device. Different panel
|
||||
* orderings are expected on tables vs. phones.
|
||||
*/
|
||||
private int getPanelIndexForDevice(final int panelIndex) {
|
||||
final String panelName = PanelType.values()[panelIndex].name();
|
||||
final Class devicePanelEnum =
|
||||
DeviceHelper.isTablet() ? TabletPanel.class : PhonePanel.class;
|
||||
return Enum.valueOf(devicePanelEnum, panelName).ordinal();
|
||||
private int getPanelIndexForDevice(final PanelType panelType) {
|
||||
PanelType[] panelOrdering = getPanelOrderingForDevice();
|
||||
|
||||
return Arrays.asList(panelOrdering).indexOf(panelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of PanelType objects ordered as we want the panels to be ordered on this device.
|
||||
*/
|
||||
public static PanelType[] getPanelOrderingForDevice() {
|
||||
return HardwareUtils.isTablet() ? PANEL_ORDERING_TABLET : PANEL_ORDERING_PHONE;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user