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 ...@@ -115,6 +115,7 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
private static final int CONNECTIVITY_CHECK_MAX_DELAY_MS = 2 * 60 * 1000; private static final int CONNECTIVITY_CHECK_MAX_DELAY_MS = 2 * 60 * 1000;
private static boolean sSkipSystemCheckForTesting; private static boolean sSkipSystemCheckForTesting;
private static boolean sSkipHttpProbeForTesting;
private static String sDefaultProbeUrl = DEFAULT_PROBE_URL; private static String sDefaultProbeUrl = DEFAULT_PROBE_URL;
private static String sFallbackProbeUrl = FALLBACK_PROBE_URL; private static String sFallbackProbeUrl = FALLBACK_PROBE_URL;
private static String sProbeMethod = PROBE_METHOD; private static String sProbeMethod = PROBE_METHOD;
...@@ -174,6 +175,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp ...@@ -174,6 +175,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
return; return;
} }
if (sSkipHttpProbeForTesting) {
updateConnectionState(ConnectionState.VALIDATED);
return;
}
// Do manual check via sending HTTP probes to server. // Do manual check via sending HTTP probes to server.
mConnectivityCheckDelayMs = 0; mConnectivityCheckDelayMs = 0;
mConnectivityCheckStartTimeMs = SystemClock.elapsedRealtime(); mConnectivityCheckStartTimeMs = SystemClock.elapsedRealtime();
...@@ -411,6 +417,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp ...@@ -411,6 +417,11 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
sSkipSystemCheckForTesting = true; sSkipSystemCheckForTesting = true;
} }
@VisibleForTesting
static void skipHttpProbeForTesting() {
sSkipHttpProbeForTesting = true;
}
@VisibleForTesting @VisibleForTesting
static void overrideDefaultProbeUrlForTesting(String url) { static void overrideDefaultProbeUrlForTesting(String url) {
sDefaultProbeUrl = url; sDefaultProbeUrl = url;
......
...@@ -68,6 +68,7 @@ public class OfflineIndicatorControllerTest { ...@@ -68,6 +68,7 @@ public class OfflineIndicatorControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ConnectivityDetector.skipSystemCheckForTesting(); ConnectivityDetector.skipSystemCheckForTesting();
ConnectivityDetector.skipHttpProbeForTesting();
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
if (!NetworkChangeNotifier.isInitialized()) { if (!NetworkChangeNotifier.isInitialized()) {
...@@ -75,6 +76,9 @@ public class OfflineIndicatorControllerTest { ...@@ -75,6 +76,9 @@ public class OfflineIndicatorControllerTest {
} }
NetworkChangeNotifier.forceConnectivityState(true); NetworkChangeNotifier.forceConnectivityState(true);
OfflineIndicatorController.initialize(); OfflineIndicatorController.initialize();
OfflineIndicatorController.getInstance()
.getConnectivityDetectorForTesting()
.updateConnectionState(ConnectivityDetector.ConnectionState.VALIDATED);
}); });
} }
...@@ -245,7 +249,7 @@ public class OfflineIndicatorControllerTest { ...@@ -245,7 +249,7 @@ public class OfflineIndicatorControllerTest {
public void testDoNotShowOfflineIndicatorOnPageLoadingWhenOffline() throws Exception { public void testDoNotShowOfflineIndicatorOnPageLoadingWhenOffline() throws Exception {
EmbeddedTestServer testServer = EmbeddedTestServer testServer =
EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext()); EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
String testUrl = testServer.getURL(TEST_PAGE); String testUrl = testServer.getURL("/slow?1");
// Load a page without waiting it to finish. // Load a page without waiting it to finish.
loadPageWithoutWaiting(testUrl, null); loadPageWithoutWaiting(testUrl, null);
...@@ -303,6 +307,8 @@ public class OfflineIndicatorControllerTest { ...@@ -303,6 +307,8 @@ public class OfflineIndicatorControllerTest {
private void waitForPageLoaded(String pageUrl) throws Exception { private void waitForPageLoaded(String pageUrl) throws Exception {
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = mActivityTestRule.getActivity().getActivityTab();
ChromeTabUtils.waitForTabPageLoaded(tab, pageUrl); ChromeTabUtils.waitForTabPageLoaded(tab, pageUrl);
ChromeTabUtils.waitForInteractable(tab);
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
private void savePage(String url) throws InterruptedException { 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