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

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

Issue 2045703003: Enable NQE when Cronet Engine is built (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mef comments Created 4 years, 6 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
Index: components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..c4574a50f537fef4ac8026912a7173340a22aa69
--- /dev/null
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
@@ -0,0 +1,51 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.net;
+
+import static junit.framework.Assert.assertEquals;
+
+import android.os.ConditionVariable;
+
+import java.util.concurrent.Executor;
+
+class TestNetworkQualityThroughputListener extends NetworkQualityThroughputListener {
+ // Lock to ensure that observation counts can be updated and read by different threads.
+ private final Object mLock = new Object();
+ private final ConditionVariable mWaitForThroughput;
+ private int mThroughputObservationCount;
+ private Thread mExecutorThread;
+
+ TestNetworkQualityThroughputListener(Executor executor, ConditionVariable waitForThroughput) {
+ super(executor);
+ mWaitForThroughput = waitForThroughput;
+ }
+
+ @Override
+ public void onThroughputObservation(int throughputKbps, long when, int source) {
+ synchronized (mLock) {
+ if (mWaitForThroughput != null) {
+ mWaitForThroughput.open();
+ }
+ mThroughputObservationCount++;
+ if (mExecutorThread == null) {
+ mExecutorThread = Thread.currentThread();
+ }
+ // Verify that the listener is always notified on the same thread.
+ assertEquals(mExecutorThread, Thread.currentThread());
+ }
+ }
+
+ public int throughputObservationCount() {
+ synchronized (mLock) {
+ return mThroughputObservationCount;
+ }
+ }
+
+ public Thread getThread() {
+ synchronized (mLock) {
+ return mExecutorThread;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698