Index: chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTest.java |
diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTest.java b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTest.java |
index bec6f6e5a435f75f85f4473c8908806d30a073de..90342c7dcb14c15d3093caa8747a9627e2febcc6 100644 |
--- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTest.java |
+++ b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityCheckerTest.java |
@@ -7,13 +7,12 @@ package org.chromium.chrome.browser.feedback; |
import android.test.suitebuilder.annotation.MediumTest; |
import org.chromium.base.ThreadUtils; |
+import org.chromium.base.test.util.Feature; |
import org.chromium.chrome.browser.profiles.Profile; |
-import java.net.MalformedURLException; |
-import java.net.URL; |
import java.util.concurrent.Semaphore; |
import java.util.concurrent.TimeUnit; |
-import java.util.concurrent.atomic.AtomicBoolean; |
+import java.util.concurrent.atomic.AtomicInteger; |
/** |
* Tests for {@link ConnectivityChecker}. |
@@ -21,94 +20,98 @@ import java.util.concurrent.atomic.AtomicBoolean; |
public class ConnectivityCheckerTest extends ConnectivityCheckerTestBase { |
private static class Callback implements ConnectivityChecker.ConnectivityCheckerCallback { |
private final Semaphore mSemaphore; |
- private final AtomicBoolean mConnected = new AtomicBoolean(); |
+ private final AtomicInteger mResult = new AtomicInteger(); |
Callback(Semaphore semaphore) { |
mSemaphore = semaphore; |
} |
@Override |
- public void onResult(boolean connected) { |
- mConnected.set(connected); |
+ public void onResult(int result) { |
+ mResult.set(result); |
mSemaphore.release(); |
} |
- boolean isConnected() { |
- return mConnected.get(); |
- } |
- } |
- |
- private static URL getURLNoException(String url) { |
- try { |
- return new URL(url); |
- } catch (MalformedURLException e) { |
- return null; |
+ int getResult() { |
+ return mResult.get(); |
} |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testNoContentShouldWorkSystemStack() throws Exception { |
- executeTest(GENERATE_204_URL, true, TIMEOUT_MS, true); |
+ executeTest(GENERATE_204_URL, ConnectivityCheckResult.CONNECTED, TIMEOUT_MS, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testNoContentShouldWorkChromeStack() throws Exception { |
- executeTest(GENERATE_204_URL, true, TIMEOUT_MS, false); |
+ executeTest(GENERATE_204_URL, ConnectivityCheckResult.CONNECTED, TIMEOUT_MS, false); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testSlowNoContentShouldNotWorkSystemStack() throws Exception { |
// Force quick timeout. The server will wait TIMEOUT_MS, so this triggers well before. |
- executeTest(GENERATE_204_SLOW_URL, false, 100, true); |
+ executeTest(GENERATE_204_SLOW_URL, ConnectivityCheckResult.TIMEOUT, 100, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testSlowNoContentShouldNotWorkChromeStack() throws Exception { |
// Force quick timeout. The server will wait TIMEOUT_MS, so this triggers well before. |
- executeTest(GENERATE_204_SLOW_URL, false, 100, false); |
+ executeTest(GENERATE_204_SLOW_URL, ConnectivityCheckResult.TIMEOUT, 100, false); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testHttpOKShouldFailSystemStack() throws Exception { |
- executeTest(GENERATE_200_URL, false, TIMEOUT_MS, true); |
+ executeTest(GENERATE_200_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testHttpOKShouldFailChromeStack() throws Exception { |
- executeTest(GENERATE_200_URL, false, TIMEOUT_MS, false); |
+ executeTest(GENERATE_200_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, false); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testMovedTemporarilyShouldFailSystemStack() throws Exception { |
- executeTest(GENERATE_302_URL, false, TIMEOUT_MS, true); |
+ executeTest(GENERATE_302_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testMovedTemporarilyShouldFailChromeStack() throws Exception { |
- executeTest(GENERATE_302_URL, false, TIMEOUT_MS, false); |
+ executeTest(GENERATE_302_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, false); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testNotFoundShouldFailSystemStack() throws Exception { |
- executeTest(GENERATE_404_URL, false, TIMEOUT_MS, true); |
+ executeTest(GENERATE_404_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testNotFoundShouldFailChromeStack() throws Exception { |
- executeTest(GENERATE_404_URL, false, TIMEOUT_MS, false); |
+ executeTest(GENERATE_404_URL, ConnectivityCheckResult.NOT_CONNECTED, TIMEOUT_MS, false); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testInvalidURLShouldFailSystemStack() throws Exception { |
- executeTest("http:google.com:foo", false, TIMEOUT_MS, true); |
+ executeTest("http:google.com:foo", ConnectivityCheckResult.ERROR, TIMEOUT_MS, true); |
} |
@MediumTest |
+ @Feature({"Feedback"}) |
public void testInvalidURLShouldFailChromeStack() throws Exception { |
- executeTest("http:google.com:foo", false, TIMEOUT_MS, false); |
+ executeTest("http:google.com:foo", ConnectivityCheckResult.ERROR, TIMEOUT_MS, false); |
} |
- private void executeTest(final String url, boolean expectedResult, final int timeoutMs, |
+ private void executeTest(final String url, int expectedResult, final int timeoutMs, |
final boolean useSystemStack) throws Exception { |
Semaphore semaphore = new Semaphore(0); |
final Callback callback = new Callback(semaphore); |
@@ -117,7 +120,7 @@ public class ConnectivityCheckerTest extends ConnectivityCheckerTestBase { |
public void run() { |
if (useSystemStack) { |
ConnectivityChecker.checkConnectivitySystemNetworkStack( |
- getURLNoException(url), timeoutMs, callback); |
+ url, timeoutMs, callback); |
} else { |
ConnectivityChecker.checkConnectivityChromeNetworkStack( |
Profile.getLastUsedProfile(), url, timeoutMs, callback); |
@@ -126,8 +129,7 @@ public class ConnectivityCheckerTest extends ConnectivityCheckerTestBase { |
}); |
assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
- assertEquals("URL: " + url + ", got " + callback.isConnected() + ", want " + expectedResult, |
- expectedResult, callback.isConnected()); |
- |
+ assertEquals("URL: " + url + ", got " + callback.getResult() + ", want " + expectedResult, |
+ expectedResult, callback.getResult()); |
} |
} |