Commit 0e69cdc6 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Disable Offline Indicator feature in ChromeActivityTestRule

The offline indicator will show up when the network is disconnected,
i.e., the bot is put in airplane mode or does not connect to WIFI.
This can cause problems to some tests that need to grab UI elements
from the page. To avoid this, we disable offline indicator feature
in ChromeActivityTestRule.

Bug: none
Change-Id: I8828ac7ac340acff3cef129f37e4052f7d6c2ba6
Reviewed-on: https://chromium-review.googlesource.com/c/1252362Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595902}
parent 20142b79
......@@ -56,6 +56,7 @@ public class OfflineIndicatorController implements ConnectivityDetector.Observer
@SuppressLint("StaticFieldLeak")
private static OfflineIndicatorController sInstance;
private static int sTimeToWaitForStableOfflineForTesting;
private boolean mIsShowingOfflineIndicator;
// Set to true if the offline indicator has been shown once since the activity has resumed.
......@@ -266,9 +267,14 @@ public class OfflineIndicatorController implements ConnectivityDetector.Observer
}
int getTimeToWaitForStableOffline() {
int seconds = ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
ChromeFeatureList.OFFLINE_INDICATOR, PARAM_STABLE_OFFLINE_WAIT_SECONDS,
STABLE_OFFLINE_DEFAULT_WAIT_SECONDS);
int seconds;
if (sTimeToWaitForStableOfflineForTesting != 0) {
seconds = sTimeToWaitForStableOfflineForTesting;
} else {
seconds = ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
ChromeFeatureList.OFFLINE_INDICATOR, PARAM_STABLE_OFFLINE_WAIT_SECONDS,
STABLE_OFFLINE_DEFAULT_WAIT_SECONDS);
}
return seconds * 1000;
}
......@@ -279,6 +285,11 @@ public class OfflineIndicatorController implements ConnectivityDetector.Observer
return !useBottomSnackbar;
}
@VisibleForTesting
static void setTimeToWaitForStableOfflineForTesting(int waitSeconds) {
sTimeToWaitForStableOfflineForTesting = waitSeconds;
}
@VisibleForTesting
ConnectivityDetector getConnectivityDetectorForTesting() {
return mConnectivityDetector;
......
......@@ -51,7 +51,8 @@ public class FeaturesAnnotationsTest {
List<String> finalDisabledList = getArgsList(false);
assertThat(finalDisabledList, hasItems("Two"));
assertThat(finalDisabledList.size(), equalTo(1));
// ChromeActivityTestRule disables OFFLINE_INDICATOR feature.
assertThat(finalDisabledList.size(), equalTo(2));
}
/**
......
......@@ -353,8 +353,7 @@ public class FullscreenManagerTest {
@Test
@LargeTest
@Feature({"Fullscreen"})
@Features.DisableFeatures(
{ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_BUTTON, ChromeFeatureList.OFFLINE_INDICATOR})
@Features.DisableFeatures({ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_BUTTON})
public void testHidingBrowserControlsRemovesSurfaceFlingerOverlay()
throws InterruptedException {
FullscreenManagerTestUtils.disableBrowserOverrides();
......
......@@ -34,6 +34,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.MenuUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.offlinepages.SavePageResult;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.test.util.Criteria;
......@@ -47,11 +48,7 @@ import java.util.concurrent.TimeUnit;
/** Unit tests for offline indicator interacting with chrome activity. */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"enable-features=" + ChromeFeatureList.OFFLINE_INDICATOR + "<FakeStudy",
"force-fieldtrials=FakeStudy/FakeGroup",
"force-fieldtrial-params=FakeStudy.FakeGroup:"
+ OfflineIndicatorController.PARAM_STABLE_OFFLINE_WAIT_SECONDS + "/1"})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
// TODO(jianli): Add test for disabled feature.
public class OfflineIndicatorControllerTest {
@Rule
......@@ -67,6 +64,10 @@ public class OfflineIndicatorControllerTest {
@Before
public void setUp() throws Exception {
// ChromeActivityTestRule disables offline indicator feature. We want to enable it to do
// our own testing.
Features.getInstance().enable(ChromeFeatureList.OFFLINE_INDICATOR);
OfflineIndicatorController.setTimeToWaitForStableOfflineForTesting(1);
ConnectivityDetector.skipSystemCheckForTesting();
ConnectivityDetector.skipHttpProbeForTesting();
mActivityTestRule.startMainActivityOnBlankPage();
......
......@@ -30,6 +30,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
......@@ -115,6 +116,10 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
// https://crbug.com/577185
Calendar.getInstance();
// Disable offline indicator UI to prevent it from popping up to obstruct other UI
// views that may make tests flaky.
Features.getInstance().disable(ChromeFeatureList.OFFLINE_INDICATOR);
base.evaluate();
}
}, description);
......
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