Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2200)

Unified Diff: components/cronet/android/test/src/org/chromium/net/SdchObserver.java

Issue 2709003002: Fix of flaky SdchTest#testSdchEnabled test. (Closed)
Patch Set: Moved static field before non-static. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/SdchTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/test/src/org/chromium/net/SdchObserver.java
diff --git a/components/cronet/android/test/src/org/chromium/net/SdchObserver.java b/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
index 8e8fe127baab8542b42cf87bff6798284d80d1b4..2028c09040c7b3170ade5627ea3dd9974c8058ec 100644
--- a/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
+++ b/components/cronet/android/test/src/org/chromium/net/SdchObserver.java
@@ -6,6 +6,8 @@ package org.chromium.net;
import android.os.ConditionVariable;
+import junit.framework.Assert;
+
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -13,11 +15,10 @@ import org.chromium.base.annotations.JNINamespace;
* Class to watch for Sdch dictionary events. The native implementation
* unregisters itself when an event happens. Therefore, an instance of this
* class is only able to receive a notification of the earliest event.
- * Currently, implemented events include {@link #onDictionaryAdded}.
*/
@JNINamespace("cronet")
public class SdchObserver {
- protected boolean mDictionaryAlreadyPresent = false;
+ private static final int BLOCK_WAIT_TIMEOUT_SEC = 20;
private final ConditionVariable mAddBlock = new ConditionVariable();
/**
@@ -27,29 +28,39 @@ public class SdchObserver {
*/
public SdchObserver(String targetUrl, long contextAdapter) {
nativeAddSdchObserver(targetUrl, contextAdapter);
- mAddBlock.block();
- mAddBlock.close();
}
/**
* Called when a dictionary is added to the SdchManager for the target url.
- * Override this method if caller would like to get notified.
*/
@CalledByNative
- public void onDictionaryAdded() {
- // Left blank;
+ protected void onDictionaryAdded() {
+ mAddBlock.open();
}
+ /**
+ * Called after the observer has been registered.
+ */
@CalledByNative
- private void onAddSdchObserverCompleted() {
- mAddBlock.open();
+ protected void onAddSdchObserverCompleted() {
+ // Left blank;
}
+ /**
+ * Called if the dictionary was added before the observer registration.
+ */
@CalledByNative
- private void onDictionarySetAlreadyPresent() {
- mDictionaryAlreadyPresent = true;
+ protected void onDictionarySetAlreadyPresent() {
mAddBlock.open();
}
+ public void waitForDictionaryAdded() {
+ boolean success = mAddBlock.block(BLOCK_WAIT_TIMEOUT_SEC * 1000);
+ if (!success) {
+ Assert.fail("Timeout: the dictionary hasn't been added after waiting for "
+ + BLOCK_WAIT_TIMEOUT_SEC + " seconds");
+ }
+ }
+
private native void nativeAddSdchObserver(String targetUrl, long contextAdapter);
}
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/SdchTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698