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

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.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/TestNetworkQualityRttListener.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..e43e4ad1e7f68555ff55c32522001bb986a65b30
--- /dev/null
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
@@ -0,0 +1,65 @@
+// 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.util.SparseIntArray;
+
+import java.util.concurrent.Executor;
+
+class TestNetworkQualityRttListener extends NetworkQualityRttListener {
+ // Lock to ensure that observation counts can be updated and read by different threads.
+ private final Object mLock = new Object();
+ private int mRttObservationCount;
+
+ // Holds the RTT observations counts indexed by source.
+ private SparseIntArray mRttObservationCountBySource = new SparseIntArray();
+
+ private Thread mExecutorThread;
+
+ // TODO(tbansal): http://crbug.com/618034 Reomve this constructor once all
+ // embedders start providing a non-null executor, and the tests for legacy
+ // API are removed.
+ TestNetworkQualityRttListener() {
+ super();
+ }
+
+ TestNetworkQualityRttListener(Executor executor) {
+ super(executor);
+ }
+
+ @Override
+ public void onRttObservation(int rttMs, long when, int source) {
+ synchronized (mLock) {
+ mRttObservationCount++;
+ mRttObservationCountBySource.put(source, mRttObservationCountBySource.get(source) + 1);
+
+ if (mExecutorThread == null) {
+ mExecutorThread = Thread.currentThread();
+ }
+ // Verify that the listener is always notified on the same thread.
+ assertEquals(mExecutorThread, Thread.currentThread());
+ }
+ }
+
+ public int rttObservationCount() {
+ synchronized (mLock) {
+ return mRttObservationCount;
+ }
+ }
+
+ public int rttObservationCount(int source) {
+ synchronized (mLock) {
+ return mRttObservationCountBySource.get(source);
+ }
+ }
+
+ public Thread getThread() {
+ synchronized (mLock) {
+ return mExecutorThread;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698