Index: chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java |
diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java |
index 295a4b388230c75f8fce4fa148aa3c6a0b1c596f..0718e5ebf5f5af4421014ac87754b956357c74e1 100644 |
--- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java |
+++ b/chrome/android/javatests_shell/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java |
@@ -17,6 +17,8 @@ import org.chromium.content.browser.test.util.CriteriaHelper; |
import java.util.HashMap; |
import java.util.Map; |
+import java.util.concurrent.Semaphore; |
+import java.util.concurrent.TimeUnit; |
import java.util.concurrent.atomic.AtomicReference; |
/** |
@@ -35,7 +37,7 @@ public class ConnectivityTaskTest extends ConnectivityCheckerTestBase { |
// Intentionally make HTTPS-connection fail which should result in NOT_CONNECTED. |
ConnectivityChecker.overrideUrlsForTest(GENERATE_204_URL, GENERATE_404_URL); |
- task.set(ConnectivityTask.create(Profile.getLastUsedProfile(), TIMEOUT_MS)); |
+ task.set(ConnectivityTask.create(Profile.getLastUsedProfile(), TIMEOUT_MS, null)); |
} |
}); |
@@ -77,6 +79,75 @@ public class ConnectivityTaskTest extends ConnectivityCheckerTestBase { |
ConnectivityTask.getHumanReadableString(actualEntry.getValue())); |
} |
+ @SmallTest |
+ @Feature({"Feedback"}) |
+ public void testCallbackNormalCaseShouldWork() throws InterruptedException { |
+ final Semaphore semaphore = new Semaphore(0); |
+ final AtomicReference<ConnectivityTask> task = new AtomicReference<>(); |
+ final AtomicReference<FeedbackData> feedbackRef = new AtomicReference<>(); |
+ final ConnectivityTask.ConnectivityResult callback = |
+ new ConnectivityTask.ConnectivityResult() { |
+ @Override |
+ public void onResult(FeedbackData feedbackData) { |
+ feedbackRef.set(feedbackData); |
+ semaphore.release(); |
+ } |
+ }; |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ // Intentionally make HTTPS-connection fail which should result in NOT_CONNECTED. |
+ ConnectivityChecker.overrideUrlsForTest(GENERATE_204_URL, GENERATE_404_URL); |
+ |
+ task.set(ConnectivityTask.create( |
+ Profile.getLastUsedProfile(), TIMEOUT_MS, callback)); |
+ } |
+ }); |
+ |
+ if (!semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { |
+ fail("Failed to acquire semaphore."); |
+ } |
+ FeedbackData feedback = feedbackRef.get(); |
+ verifyConnections(feedback, ConnectivityCheckResult.NOT_CONNECTED); |
+ assertEquals("The timeout value is wrong.", TIMEOUT_MS, feedback.getTimeoutMs()); |
+ } |
+ |
+ @MediumTest |
+ @Feature({"Feedback"}) |
+ public void testCallbackTwoTimeouts() throws InterruptedException { |
+ final int checkTimeoutMs = 100; |
+ final Semaphore semaphore = new Semaphore(0); |
+ final AtomicReference<ConnectivityTask> task = new AtomicReference<>(); |
+ final AtomicReference<FeedbackData> feedbackRef = new AtomicReference<>(); |
+ final ConnectivityTask.ConnectivityResult callback = |
+ new ConnectivityTask.ConnectivityResult() { |
+ @Override |
+ public void onResult(FeedbackData feedbackData) { |
+ feedbackRef.set(feedbackData); |
+ semaphore.release(); |
+ } |
+ }; |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ // Intentionally make HTTPS connections slow which should result in TIMEOUT. |
+ ConnectivityChecker.overrideUrlsForTest(GENERATE_204_URL, GENERATE_204_SLOW_URL); |
+ |
+ task.set(ConnectivityTask.create( |
+ Profile.getLastUsedProfile(), checkTimeoutMs, callback)); |
+ } |
+ }); |
+ |
+ if (!semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { |
+ fail("Failed to acquire semaphore."); |
+ } |
+ FeedbackData feedback = feedbackRef.get(); |
+ // In the case of a timeout when using callbacks, the result will be TIMEOUT instead |
+ // of UNKNOWN. |
+ verifyConnections(feedback, ConnectivityCheckResult.TIMEOUT); |
+ assertEquals("The timeout value is wrong.", checkTimeoutMs, feedback.getTimeoutMs()); |
+ } |
+ |
@MediumTest |
@Feature({"Feedback"}) |
public void testTwoTimeoutsShouldFillInTheRest() throws InterruptedException { |
@@ -87,7 +158,7 @@ public class ConnectivityTaskTest extends ConnectivityCheckerTestBase { |
// Intentionally make HTTPS connections slow which should result in UNKNOWN. |
ConnectivityChecker.overrideUrlsForTest(GENERATE_204_URL, GENERATE_204_SLOW_URL); |
- task.set(ConnectivityTask.create(Profile.getLastUsedProfile(), TIMEOUT_MS)); |
+ task.set(ConnectivityTask.create(Profile.getLastUsedProfile(), TIMEOUT_MS, null)); |
} |
}); |