Commit c9e17380 authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

Reland "Merge tabs of multi-instance when display is changed."

Reland https://crrev.com/c/2272131

1. Enable only on P+
2. Use new Critical Helper API

Bug: 1088202
Change-Id: I9d07ceee98d138a6468c6280266a14aea8e20b8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2290961Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Lijin Shen <lazzzis@google.com>
Cr-Commit-Position: refs/heads/master@{#787925}
parent 7a75d73b
...@@ -20,6 +20,7 @@ import androidx.annotation.Nullable; ...@@ -20,6 +20,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ActivityState; import org.chromium.base.ActivityState;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
...@@ -85,6 +86,7 @@ public class MultiInstanceManager ...@@ -85,6 +86,7 @@ public class MultiInstanceManager
private boolean mShouldMergeOnConfigurationChange; private boolean mShouldMergeOnConfigurationChange;
private boolean mIsRecreating; private boolean mIsRecreating;
private int mDisplayId; private int mDisplayId;
private static List<Integer> sTestDisplayIds;
/** /**
* Create a new {@link MultiInstanceManager}. * Create a new {@link MultiInstanceManager}.
...@@ -220,7 +222,13 @@ public class MultiInstanceManager ...@@ -220,7 +222,13 @@ public class MultiInstanceManager
@Override @Override
public void onDisplayChanged(int displayId) { public void onDisplayChanged(int displayId) {
// TODO(crbug.com/824954): try to merge tabs sharing logic w/ onDisplayRemoved if (displayId == mDisplayId) return;
List<Integer> ids = sTestDisplayIds != null
? sTestDisplayIds
: ApiCompatibilityUtils.getTargetableDisplayIds(mActivity);
if (ids.size() == 1 && ids.get(0).equals(mDisplayId)) {
maybeMergeTabs();
}
} }
}; };
displayManager.registerDisplayListener(mDisplayListener, null); displayManager.registerDisplayListener(mDisplayListener, null);
...@@ -433,4 +441,9 @@ public class MultiInstanceManager ...@@ -433,4 +441,9 @@ public class MultiInstanceManager
public DisplayManager.DisplayListener getDisplayListenerForTesting() { public DisplayManager.DisplayListener getDisplayListenerForTesting() {
return mDisplayListener; return mDisplayListener;
} }
@VisibleForTesting
public static void setTestDisplayIds(List<Integer> testDisplayIds) {
sTestDisplayIds = testDisplayIds;
}
} }
...@@ -16,6 +16,7 @@ import android.support.test.InstrumentationRegistry; ...@@ -16,6 +16,7 @@ import android.support.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest; import androidx.test.filters.LargeTest;
import java.util.Collections;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -539,4 +540,48 @@ public class TabModelMergingTest { ...@@ -539,4 +540,48 @@ public class TabModelMergingTest {
mActivity1.finishAndRemoveTask(); mActivity1.finishAndRemoveTask();
mActivity2.finishAndRemoveTask(); mActivity2.finishAndRemoveTask();
} }
@Test
@LargeTest
@EnableFeatures(ChromeFeatureList.ANDROID_MULTIPLE_DISPLAY)
@DisableIf.Build(sdk_is_less_than = VERSION_CODES.P)
public void testMergeOnMultiDisplay_OnDisplayChanged() throws TimeoutException {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mActivity1.saveState();
mActivity2.saveState();
});
MultiInstanceManager m1 = mActivity1.getMultiInstanceMangerForTesting();
MultiInstanceManager m2 = mActivity2.getMultiInstanceMangerForTesting();
// Ensure Activity 1 is resumed on the front.
Intent intent = new Intent(mActivity1, mActivity1.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mActivity1.startActivity(intent);
waitForActivityStateChange(ActivityState.RESUMED, mActivity2, false);
waitForActivityStateChange(ActivityState.RESUMED, mActivity1, true);
MultiInstanceManager.setTestDisplayIds(Collections.singletonList(0));
m1.setCurrentDisplayIdForTesting(0);
m2.setCurrentDisplayIdForTesting(1);
TestThreadUtils.runOnUiThreadBlocking(() -> {
m1.getDisplayListenerForTesting().onDisplayChanged(1);
m2.getDisplayListenerForTesting().onDisplayChanged(1);
});
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("Total tab count incorrect.",
mActivity1.getTabModelSelector().getTotalTabCount(), Matchers.is(7));
});
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("CTA should not be destroyed", mActivity1State,
Matchers.not(ActivityState.DESTROYED));
Criteria.checkThat("CTA2 should be destroyed", mActivity2State,
Matchers.is(ActivityState.DESTROYED));
});
mActivity1.finishAndRemoveTask();
mActivity2.finishAndRemoveTask();
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment