Commit d4a3c43e authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Commit Bot

Avoid firing activity if not necessary in IncognitoDataTestUtils.

IncognitoDataTestUtils#launchUrlInTab is called when we want to load a
URL in Chrome tabbed activity. This chrome tabbed activity is
fired once in the setUp method of the incognito leakage tests and in
subsequent calls to the launchUrlInTab method.

The reason for firing activity in the launchUrlInTab method is to
bring back the ChromeTabbedActivity (which was fired in the setUp
method), if the previous activity fired was of type CustomTabActivity.
To make the code more readable no checks were introduced and chrome
tabbed activity was fired un-conditionally.

However due to this we have some instances were the application was
killed due to memory pressure.

This CL adds the check to fire a ChromeTabbedActivity only if the
previous activity which was fired was CustomTabbedActivity.

Bug: 1081748, 1084709, 1035770
Change-Id: I1a232c44767821af17de2d7a859b4ecab50dbc91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213525
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772595}
parent 7b226865
...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.incognito; ...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.incognito;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.test.params.ParameterProvider; import org.chromium.base.test.params.ParameterProvider;
import org.chromium.base.test.params.ParameterSet; import org.chromium.base.test.params.ParameterSet;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule; import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils; import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
...@@ -120,11 +123,19 @@ public class IncognitoDataTestUtils { ...@@ -120,11 +123,19 @@ public class IncognitoDataTestUtils {
} }
} }
private static boolean isChromeTabbedActivityRunningOnTop() {
Activity topActivity = ApplicationStatus.getLastTrackedFocusedActivity();
if (topActivity == null) return false;
return (topActivity instanceof ChromeTabbedActivity);
}
private static Tab launchUrlInTab( private static Tab launchUrlInTab(
ChromeActivityTestRule testRule, String url, boolean incognito) { ChromeActivityTestRule testRule, String url, boolean incognito) {
// This helps to bring back the "existing" chrome tabbed activity to foreground // This helps to bring back the "existing" chrome tabbed activity to foreground
// in case the custom tab activity was launched before. // in case the custom tab activity was launched before.
testRule.startMainActivityOnBlankPage(); if (!isChromeTabbedActivityRunningOnTop()) {
testRule.startMainActivityOnBlankPage();
}
Tab tab = testRule.loadUrlInNewTab(url, incognito); Tab tab = testRule.loadUrlInNewTab(url, incognito);
......
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