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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 8
9 import junit.framework.Assert;
10
9 import org.chromium.base.annotations.CalledByNative; 11 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.JNINamespace; 12 import org.chromium.base.annotations.JNINamespace;
11 13
12 /** 14 /**
13 * Class to watch for Sdch dictionary events. The native implementation 15 * Class to watch for Sdch dictionary events. The native implementation
14 * unregisters itself when an event happens. Therefore, an instance of this 16 * unregisters itself when an event happens. Therefore, an instance of this
15 * class is only able to receive a notification of the earliest event. 17 * class is only able to receive a notification of the earliest event.
16 * Currently, implemented events include {@link #onDictionaryAdded}.
17 */ 18 */
18 @JNINamespace("cronet") 19 @JNINamespace("cronet")
19 public class SdchObserver { 20 public class SdchObserver {
20 protected boolean mDictionaryAlreadyPresent = false; 21 private static final int BLOCK_WAIT_TIMEOUT_SEC = 20;
21 private final ConditionVariable mAddBlock = new ConditionVariable(); 22 private final ConditionVariable mAddBlock = new ConditionVariable();
22 23
23 /** 24 /**
24 * Constructor. 25 * Constructor.
25 * @param targetUrl the target url on which sdch encoding will be used. 26 * @param targetUrl the target url on which sdch encoding will be used.
26 * @param contextAdapter the native context adapter to register the observer . 27 * @param contextAdapter the native context adapter to register the observer .
27 */ 28 */
28 public SdchObserver(String targetUrl, long contextAdapter) { 29 public SdchObserver(String targetUrl, long contextAdapter) {
29 nativeAddSdchObserver(targetUrl, contextAdapter); 30 nativeAddSdchObserver(targetUrl, contextAdapter);
30 mAddBlock.block();
31 mAddBlock.close();
32 } 31 }
33 32
34 /** 33 /**
35 * Called when a dictionary is added to the SdchManager for the target url. 34 * Called when a dictionary is added to the SdchManager for the target url.
36 * Override this method if caller would like to get notified.
37 */ 35 */
38 @CalledByNative 36 @CalledByNative
39 public void onDictionaryAdded() { 37 protected void onDictionaryAdded() {
38 mAddBlock.open();
39 }
40
41 /**
42 * Called after the observer has been registered.
43 */
44 @CalledByNative
45 protected void onAddSdchObserverCompleted() {
40 // Left blank; 46 // Left blank;
41 } 47 }
42 48
49 /**
50 * Called if the dictionary was added before the observer registration.
51 */
43 @CalledByNative 52 @CalledByNative
44 private void onAddSdchObserverCompleted() { 53 protected void onDictionarySetAlreadyPresent() {
45 mAddBlock.open(); 54 mAddBlock.open();
46 } 55 }
47 56
48 @CalledByNative 57 public void waitForDictionaryAdded() {
49 private void onDictionarySetAlreadyPresent() { 58 boolean success = mAddBlock.block(BLOCK_WAIT_TIMEOUT_SEC * 1000);
50 mDictionaryAlreadyPresent = true; 59 if (!success) {
51 mAddBlock.open(); 60 Assert.fail("Timeout: the dictionary hasn't been added after waiting for "
61 + BLOCK_WAIT_TIMEOUT_SEC + " seconds");
62 }
52 } 63 }
53 64
54 private native void nativeAddSdchObserver(String targetUrl, long contextAdap ter); 65 private native void nativeAddSdchObserver(String targetUrl, long contextAdap ter);
55 } 66 }
OLDNEW
« 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