Commit 0c79e1e7 authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Commit Bot

Remove incognito CCT silent notification from Android.

The "Close incognito tabs" notification we show in Android also closes
the incognito tabs opened in CCT.

This CL:

1) Disallows the close incognito notification for tabs opened in
incognito CCT.

2) For regular incognito "tabbed" Activity there's no change of
behaviour when the user clicks on the notification i.e we will continue
to close the incognito tabs opened by the Chrome "tabbed" Activity.

3) From Point 2) clicking on the notification wouldn't affect any
incognito CCT tabs.

This CL also adds instrumentation tests.

Bug: 1131844
Change-Id: Ia375bb61b6f54940c1315c0512921b0407d27aa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426433Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812082}
parent 099ab24e
......@@ -84,6 +84,8 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.gesturenav.NavigationSheet;
import org.chromium.chrome.browser.homepage.HomepageManager;
import org.chromium.chrome.browser.incognito.IncognitoNotificationManager;
import org.chromium.chrome.browser.incognito.IncognitoNotificationPresenceController;
import org.chromium.chrome.browser.incognito.IncognitoProfileDestroyer;
import org.chromium.chrome.browser.incognito.IncognitoTabLauncher;
import org.chromium.chrome.browser.incognito.IncognitoTabSnapshotController;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
......@@ -1443,6 +1445,10 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
public void performPostInflationStartup() {
super.performPostInflationStartup();
TabModelSelector tabModelSelector = getTabModelSelector();
IncognitoProfileDestroyer.observeTabModelSelector(tabModelSelector);
IncognitoNotificationPresenceController.observeTabModelSelector(tabModelSelector);
// Critical path for startup. Create the minimum objects needed
// to allow a blank screen draw (without depending on any native code)
// and then yield ASAP.
......
......@@ -104,8 +104,6 @@ import org.chromium.chrome.browser.gsa.ContextReporter;
import org.chromium.chrome.browser.gsa.GSAAccountChangeListener;
import org.chromium.chrome.browser.gsa.GSAState;
import org.chromium.chrome.browser.history.HistoryManagerUtils;
import org.chromium.chrome.browser.incognito.IncognitoNotificationPresenceController;
import org.chromium.chrome.browser.incognito.IncognitoProfileDestroyer;
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.chrome.browser.init.StartupTabPreloader;
......@@ -657,9 +655,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
mIncognitoTabCreator = tabCreators.second;
OfflinePageUtils.observeTabModelSelector(this, mTabModelSelector);
IncognitoProfileDestroyer.observeTabModelSelector(mTabModelSelector);
IncognitoNotificationPresenceController.observeTabModelSelector(mTabModelSelector);
if (mTabModelSelectorTabObserver != null) mTabModelSelectorTabObserver.destroy();
mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {
......
......@@ -11,6 +11,8 @@ import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.customtabs.CustomTabsTestUtils.addActionButtonToIntent;
import static org.chromium.chrome.browser.customtabs.CustomTabsTestUtils.createTestBitmap;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
......@@ -37,19 +39,17 @@ import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils.OnFinishedForTest;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbar;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils;
import org.chromium.chrome.browser.incognito.IncognitoNotificationService;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServerRule;
......@@ -194,16 +194,21 @@ public class CustomTabActivityIncognitoTest {
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
@DisabledTest
// TODO(crbug.com/1023759) : The test is flaky on marshmallow.
// Need to investigate.
public void incognitoNotificationClosesIncognitoCustomTab() throws Exception {
@SuppressLint("NewApi")
public void closeAllIncognitoNotificationIsNotDisplayed() throws Exception {
// It may happen that some previous incognito notification from tabbed activity may be
// already be lying around. So, we test the delta instead to be 0.
Context context = ContextUtils.getApplicationContext();
NotificationManager nm =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int startCount = nm.getActiveNotifications().length;
// Launch incognito CCT
Intent intent = createMinimalIncognitoCustomTabIntent();
CustomTabActivity activity = launchIncognitoCustomTab(intent);
IncognitoNotificationService.getRemoveAllIncognitoTabsIntent(activity)
.getPendingIntent()
.send();
CriteriaHelper.pollUiThread(activity::isFinishing);
int endCount = nm.getActiveNotifications().length;
assertEquals(0, endCount - startCount);
}
@Test
......
......@@ -4,6 +4,10 @@
package org.chromium.chrome.browser.incognito;
import static org.junit.Assert.assertEquals;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
......@@ -18,6 +22,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
......@@ -178,4 +183,26 @@ public class IncognitoNotificationServiceTest {
TestThreadUtils.runOnUiThreadBlocking(
() -> Assert.assertFalse(LibraryLoader.getInstance().isInitialized()));
}
@Test
@Feature("Incognito")
@MediumTest
@SuppressLint("NewApi")
public void testCloseAllIncognitoNotificationIsDisplayed() {
mActivityTestRule.startMainActivityOnBlankPage();
createTabOnUiThread();
createTabOnUiThread();
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(
mActivityTestRule.getActivity().getTabModelSelector().getModel(true).getCount(),
Matchers.is(2));
});
Context context = ContextUtils.getApplicationContext();
NotificationManager nm =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
assertEquals(1, nm.getActiveNotifications().length);
}
}
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