Commit be1e9636 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Omnibox] Use ActivityState to check if we are in browser mode


In multi windows mode, check if we are in browser mode by WindowAndroid
is not working, should check ActivityState instead.

Bug: 1102640
Change-Id: I35a720a2aa6f337cc9f9ae43e39d83c9368fcb5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2286478
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786636}
parent 5028dd66
......@@ -20,6 +20,7 @@ import androidx.annotation.Px;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ActivityState;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.IntentUtils;
......@@ -578,7 +579,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
// When invoked directly from a browser, we want to trigger switch to tab animation.
// If invoded from other activitiies, ex. searchActivity, we do not need to trigger the
// animation since Android will show the animation for switching apps.
if (mWindowAndroid.equals(tab.getWindowAndroid())) {
if (tab.getWindowAndroid().getActivityState() != ActivityState.STOPPED
&& tab.getWindowAndroid().getActivityState() != ActivityState.DESTROYED) {
// TODO(1097292): Do not use Activity to get TabModelSelector.
assert tab.getWindowAndroid().getActivity().get() instanceof ChromeActivity;
......@@ -589,13 +591,13 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
chromeActivity.getTabModelSelector().getCurrentModel().setIndex(
tabIndex, TabSelectionType.FROM_OMNIBOX);
} else {
// Browser is in background, bring to to foreground and switch to the tab.
Intent newIntent = ChromeIntentUtil.createBringTabToFrontIntent(tab.getId());
if (newIntent != null) {
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentUtils.safeStartActivity(ContextUtils.getApplicationContext(), newIntent);
}
}
recordMetrics(position, WindowOpenDisposition.SWITCH_TO_TAB, suggestion);
}
......
......@@ -24,6 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ActivityState;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf;
import org.chromium.chrome.R;
......@@ -245,7 +246,7 @@ public class SwitchToTabTest {
@Test
@MediumTest
@EnableFeatures("OmniboxTabSwitchSuggestions")
public void testSwitchToTabInSearchActiviy() throws InterruptedException {
public void testSwitchToTabInSearchActivity() throws InterruptedException {
mTestServer = EmbeddedTestServer.createAndStartHTTPSServer(
InstrumentationRegistry.getInstrumentation().getContext(),
ServerCertificate.CERT_OK);
......@@ -257,6 +258,13 @@ public class SwitchToTabTest {
mActivityTestRule.loadUrlInNewTab(testHttpsUrl3);
final SearchActivity searchActivity = startSearchActivity();
CriteriaHelper.pollUiThread(() -> {
Tab tab = mActivityTestRule.getActivity().getActivityTab();
Criteria.checkThat(tab, Matchers.notNullValue());
// Make sure chrome fully in background.
Criteria.checkThat(tab.getWindowAndroid().getActivityState(),
Matchers.isOneOf(ActivityState.STOPPED, ActivityState.DESTROYED));
});
final LocationBarLayout locationBarLayout =
(LocationBarLayout) searchActivity.findViewById(R.id.search_location_bar);
......@@ -276,11 +284,11 @@ public class SwitchToTabTest {
CriteriaHelper.pollUiThread(() -> {
Tab tab = mActivityTestRule.getActivity().getActivityTab();
if (tab == null) return false;
// Make sure tab is in either upload page or result page. cannot only verify one of
// them since on fast device tab jump to result page really quick but on slow device
// may stay on upload page for a really long time.
return tab.getUrlString().equals(testHttpsUrl1);
Criteria.checkThat(tab, Matchers.notNullValue());
Criteria.checkThat(tab.getUrlString(), Matchers.is(testHttpsUrl1));
// Make sure tab is loaded and in foreground.
Criteria.checkThat(
tab.getWindowAndroid().getActivityState(), Matchers.is(ActivityState.RESUMED));
});
}
}
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