Bug 1396324 - [robocop] Configure bookmarks panel as default panel before loading URLs. r?JanH,walkingice
We found sometimes Robocop operates wrong UI components when it deals with a complex layout.
Since default panel shows Activity Stream which contains complex UI components, we configure
bookmarks panel as default panel to keep the layout as simple as possible.
MozReview-Commit-ID: 12xhVOdlIRK
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomeConfig.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomeConfig.java
@@ -1119,16 +1119,17 @@ public final class HomeConfig {
*/
public boolean isDefault() {
return mIsDefault;
}
/**
* Creates an {@code Editor} for this state.
*/
+ @RobocopTarget
public Editor edit() {
return new Editor(mHomeConfig, this);
}
}
/**
* {@code Editor} allows you to make changes to a {@code State}. You
* can create {@code Editor} by calling {@code edit()} on the target
@@ -1268,31 +1269,33 @@ public final class HomeConfig {
panelConfig.setIsDisabled(disabled);
mEnabledCount += (disabled ? -1 : 1);
}
/**
* Gets the ID of the current default panel.
*/
+ @RobocopTarget
public String getDefaultPanelId() {
ThreadUtils.assertOnThread(mOriginalThread);
if (mDefaultPanel == null) {
return null;
}
return mDefaultPanel.getId();
}
/**
* Set a new default panel.
*
* @param panelId the ID of the new default panel.
*/
+ @RobocopTarget
public void setDefault(String panelId) {
ThreadUtils.assertOnThread(mOriginalThread);
final PanelConfig panelConfig = getPanelOrThrow(panelId);
if (isCurrentDefaultPanel(panelConfig)) {
return;
}
@@ -1478,16 +1481,17 @@ public final class HomeConfig {
}
/**
* Saves the current {@code Editor} state asynchronously in the
* background thread.
*
* @return the resulting {@code State} instance.
*/
+ @RobocopTarget
public State apply() {
ThreadUtils.assertOnThread(mOriginalThread);
// We're about to save the current state in the background thread
// so we should use a deep copy of the PanelConfig instances to
// avoid saving corrupted state.
final State newConfigState =
new State(mHomeConfig, makeOrderedCopy(true), isDefault());
@@ -1612,16 +1616,17 @@ public final class HomeConfig {
private static final String DEPRECATED_READING_LIST_PANEL_ID = "20f4549a-64ad-4c32-93e4-1dcef792733b";
private final HomeConfigBackend mBackend;
public HomeConfig(HomeConfigBackend backend) {
mBackend = backend;
}
+ @RobocopTarget
public State load() {
final State configState = mBackend.load();
configState.setHomeConfig(this);
return configState;
}
public String getLocale() {
@@ -1655,16 +1660,17 @@ public final class HomeConfig {
case COMBINED_HISTORY:
return R.string.home_history_title;
default:
throw new IllegalArgumentException("Only for built-in panel types: " + panelType);
}
}
+ @RobocopTarget
public static String getIdForBuiltinPanelType(PanelType panelType) {
switch (panelType) {
case TOP_SITES:
return TOP_SITES_PANEL_ID;
case BOOKMARKS:
return BOOKMARKS_PANEL_ID;
@@ -1690,12 +1696,13 @@ public final class HomeConfig {
public static PanelConfig createBuiltinPanelConfig(Context context, PanelType panelType, EnumSet<PanelConfig.Flags> flags) {
final int titleId = getTitleResourceIdForBuiltinPanelType(panelType);
final String id = getIdForBuiltinPanelType(panelType);
return new PanelConfig(panelType, context.getString(titleId), id, flags);
}
+ @RobocopTarget
public static HomeConfig getDefault(Context context) {
return new HomeConfig(new HomeConfigPrefsBackend(context));
}
}
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testSessionOOMSave.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testSessionOOMSave.java
@@ -1,20 +1,45 @@
package org.mozilla.gecko.tests;
import android.util.Log;
import org.mozilla.gecko.Actions;
+import org.mozilla.gecko.home.HomeConfig;
/**
* Tests session OOM save behavior.
*
* Builds a session and tests that the saved state is correct.
*/
public class testSessionOOMSave extends SessionTest {
+
+ private HomeConfig.Editor mEditor;
+ private String mDefaultPanelId;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ final HomeConfig homeConfig = HomeConfig.getDefault(getInstrumentation().getTargetContext());
+ final HomeConfig.State state = homeConfig.load();
+ mEditor = state.edit();
+ mDefaultPanelId = mEditor.getDefaultPanelId();
+ mEditor.setDefault(HomeConfig.getIdForBuiltinPanelType(HomeConfig.PanelType.BOOKMARKS));
+ mEditor.apply();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ mEditor.setDefault(mDefaultPanelId);
+ mEditor.apply();
+
+ super.tearDown();
+ }
+
public void testSessionOOMSave() {
final Actions.EventExpecter pageShowExpecter =
mActions.expectGlobalEvent(Actions.EventType.UI, "Content:PageShow");
pageShowExpecter.blockForEvent();
pageShowExpecter.unregisterListener();
final Session session = createTestSession(/*selected tab*/ 1);