Commit 6029cf83 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Improve the stability of OfflineIndicatorControllerTest

Bug: 885144,890091
Change-Id: Idbf08df67e8783ef305e273680cc12287ac1d53d
Reviewed-on: https://chromium-review.googlesource.com/1250169Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595264}
parent c0b6dfdf
......@@ -115,6 +115,7 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
private static final int CONNECTIVITY_CHECK_MAX_DELAY_MS = 2 * 60 * 1000;
private static boolean sSkipSystemCheckForTesting;
private static boolean sSkipHttpProbeForTesting;
private static String sDefaultProbeUrl = DEFAULT_PROBE_URL;
private static String sFallbackProbeUrl = FALLBACK_PROBE_URL;
private static String sProbeMethod = PROBE_METHOD;
......@@ -174,6 +175,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
return;
}
if (sSkipHttpProbeForTesting) {
updateConnectionState(ConnectionState.VALIDATED);
return;
}
// Do manual check via sending HTTP probes to server.
mConnectivityCheckDelayMs = 0;
mConnectivityCheckStartTimeMs = SystemClock.elapsedRealtime();
......@@ -411,6 +417,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
sSkipSystemCheckForTesting = true;
}
@VisibleForTesting
static void skipHttpProbeForTesting() {
sSkipHttpProbeForTesting = true;
}
@VisibleForTesting
static void overrideDefaultProbeUrlForTesting(String url) {
sDefaultProbeUrl = url;
......
......@@ -68,6 +68,7 @@ public class OfflineIndicatorControllerTest {
@Before
public void setUp() throws Exception {
ConnectivityDetector.skipSystemCheckForTesting();
ConnectivityDetector.skipHttpProbeForTesting();
mActivityTestRule.startMainActivityOnBlankPage();
ThreadUtils.runOnUiThreadBlocking(() -> {
if (!NetworkChangeNotifier.isInitialized()) {
......@@ -75,6 +76,9 @@ public class OfflineIndicatorControllerTest {
}
NetworkChangeNotifier.forceConnectivityState(true);
OfflineIndicatorController.initialize();
OfflineIndicatorController.getInstance()
.getConnectivityDetectorForTesting()
.updateConnectionState(ConnectivityDetector.ConnectionState.VALIDATED);
});
}
......@@ -245,7 +249,7 @@ public class OfflineIndicatorControllerTest {
public void testDoNotShowOfflineIndicatorOnPageLoadingWhenOffline() throws Exception {
EmbeddedTestServer testServer =
EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
String testUrl = testServer.getURL(TEST_PAGE);
String testUrl = testServer.getURL("/slow?1");
// Load a page without waiting it to finish.
loadPageWithoutWaiting(testUrl, null);
......@@ -303,6 +307,8 @@ public class OfflineIndicatorControllerTest {
private void waitForPageLoaded(String pageUrl) throws Exception {
Tab tab = mActivityTestRule.getActivity().getActivityTab();
ChromeTabUtils.waitForTabPageLoaded(tab, pageUrl);
ChromeTabUtils.waitForInteractable(tab);
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
private void savePage(String url) throws InterruptedException {
......
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