summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorpauljensen <pauljensen@chromium.org>2015-10-30 08:22:42 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-30 15:23:33 +0000
commit3c55da5faa5874d54f0ffa5e63b0dc6269a58990 (patch)
treeeed3cc973b022e7ba50b3998b1690643c50d530d /components
parentfc23940c808cf9b21c2a71c8747cf525dfb47352 (diff)
downloadchromium_src-3c55da5faa5874d54f0ffa5e63b0dc6269a58990.zip
chromium_src-3c55da5faa5874d54f0ffa5e63b0dc6269a58990.tar.gz
chromium_src-3c55da5faa5874d54f0ffa5e63b0dc6269a58990.tar.bz2
[Cronet] Remove CriteriaHelper
CriteriaHelper seems to be a carry-over from ContentShell testing code and isn't necessary for Cronet Sample instrumentation tests. R=xunjieli TEST=Instrumentation test CronetSampleTest Review URL: https://codereview.chromium.org/1419033005 Cr-Commit-Position: refs/heads/master@{#357107}
Diffstat (limited to 'components')
-rw-r--r--components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CriteriaHelper.java86
-rw-r--r--components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTest.java96
-rw-r--r--components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java31
-rw-r--r--components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleApplication.java4
-rw-r--r--components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java88
-rw-r--r--components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java7
6 files changed, 28 insertions, 284 deletions
diff --git a/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CriteriaHelper.java b/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CriteriaHelper.java
deleted file mode 100644
index c63a459..0000000
--- a/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CriteriaHelper.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2014 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.cronet_sample_apk;
-
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
-
-import android.os.SystemClock;
-
-/**
- * Helper methods for creating and managing criteria.
- * <p>
- * If possible, use callbacks or testing delegates instead of criteria as they
- * do not introduce any polling delays. Should only use Criteria if no suitable
- * other approach exists.
- */
-public class CriteriaHelper {
-
- /** The default maximum time to wait for a criteria to become valid. */
- public static final long DEFAULT_MAX_TIME_TO_POLL = scaleTimeout(3000);
-
- /**
- * The default polling interval to wait between checking for a satisfied
- * criteria.
- */
- public static final long DEFAULT_POLLING_INTERVAL = 50;
-
- /**
- * Checks whether the given Criteria is satisfied at a given interval, until
- * either the criteria is satisfied, or the specified maxTimeoutMs number of
- * ms has elapsed.
- *
- * @param criteria The Criteria that will be checked.
- * @param maxTimeoutMs The maximum number of ms that this check will be
- * performed for before timeout.
- * @param checkIntervalMs The number of ms between checks.
- * @return {@code true} iff checking has ended with the criteria being
- * satisfied.
- * @throws InterruptedException
- */
- public static boolean pollForCriteria(Criteria criteria, long maxTimeoutMs,
- long checkIntervalMs) throws InterruptedException {
- boolean isSatisfied = criteria.isSatisfied();
- long startTime = SystemClock.uptimeMillis();
- while (!isSatisfied && SystemClock.uptimeMillis() - startTime < maxTimeoutMs) {
- Thread.sleep(checkIntervalMs);
- isSatisfied = criteria.isSatisfied();
- }
- return isSatisfied;
- }
-
- /**
- * Checks whether the given Criteria is satisfied polling at a default
- * interval.
- *
- * @param criteria The Criteria that will be checked.
- * @return iff checking has ended with the criteria being satisfied.
- * @throws InterruptedException
- * @see #pollForCriteria(Criteria, long, long)
- */
- public static boolean pollForCriteria(Criteria criteria)
- throws InterruptedException {
- return pollForCriteria(criteria, DEFAULT_MAX_TIME_TO_POLL,
- DEFAULT_POLLING_INTERVAL);
- }
-
- /**
- * Performs the runnable action, then checks whether the given criteria are
- * satisfied until the specified timeout, using the pollForCriteria method.
- * If not, then the runnable action is performed again, to a maximum of
- * maxAttempts tries.
- */
- public static boolean runUntilCriteria(Runnable runnable, Criteria criteria,
- int maxAttempts, long maxTimeoutMs, long checkIntervalMs)
- throws InterruptedException {
- int count = 0;
- boolean success = false;
- while (count < maxAttempts && !success) {
- count++;
- runnable.run();
- success = pollForCriteria(criteria, maxTimeoutMs, checkIntervalMs);
- }
- return success;
- }
-}
diff --git a/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTest.java b/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTest.java
index 1c39c75..a686a57 100644
--- a/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTest.java
+++ b/components/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTest.java
@@ -7,31 +7,21 @@ package org.chromium.cronet_sample_apk;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
+import android.os.ConditionVariable;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.SmallTest;
-import android.text.TextUtils;
-
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.TextView;
import org.chromium.base.test.util.Feature;
-import java.util.concurrent.atomic.AtomicBoolean;
-
/**
* Base test class for all CronetSample based tests.
*/
public class CronetSampleTest extends
ActivityInstrumentationTestCase2<CronetSampleActivity> {
- /**
- * The maximum time the waitForActiveShellToBeDoneLoading method will wait.
- */
- private static final long
- WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000);
-
- protected static final long
- WAIT_PAGE_LOADING_TIMEOUT_SECONDS = scaleTimeout(15);
-
// URL used for base tests.
private static final String URL = "http://127.0.0.1:8000";
@@ -46,9 +36,28 @@ public class CronetSampleTest extends
// Make sure the activity was created as expected.
assertNotNull(activity);
- // Make sure that the URL is set as expected.
- assertEquals(URL, activity.getUrl());
- assertEquals(200, activity.getHttpStatusCode());
+
+ // Verify successful fetch.
+ final TextView textView = (TextView) activity.findViewById(R.id.resultView);
+ final ConditionVariable done = new ConditionVariable();
+ final TextWatcher textWatcher = new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {}
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ if (s.equals("Completed " + URL + " (200)")) {
+ done.open();
+ }
+ }
+ };
+ textView.addTextChangedListener(textWatcher);
+ // Check current text in case it changed before |textWatcher| was added.
+ textWatcher.onTextChanged(textView.getText(), 0, 0, 0);
+ done.block();
}
/**
@@ -63,59 +72,6 @@ public class CronetSampleTest extends
getInstrumentation().getTargetContext(),
CronetSampleActivity.class));
setActivityIntent(intent);
- try {
- waitForActiveShellToBeDoneLoading();
- } catch (Throwable e) {
- fail("Active shell has failed to load.");
- }
return getActivity();
}
-
- /**
- * Waits for the Active shell to finish loading. This times out after
- * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be
- * used for long loading pages. Instead it should be used more for test
- * initialization. The proper way to wait is to use a
- * TestCallbackHelperContainer after the initial load is completed.
- *
- * @return Whether or not the Shell was actually finished loading.
- * @throws InterruptedException
- */
- protected boolean waitForActiveShellToBeDoneLoading()
- throws InterruptedException {
- final CronetSampleActivity activity = getActivity();
-
- // Wait for the Content Shell to be initialized.
- return CriteriaHelper.pollForCriteria(new Criteria() {
- @Override
- public boolean isSatisfied() {
- try {
- final AtomicBoolean isLoaded = new AtomicBoolean(false);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (activity != null) {
- // There are two cases here that need to be
- // accounted for.
- // The first is that we've just created a Shell
- // and it isn't
- // loading because it has no URL set yet. The
- // second is that
- // we've set a URL and it actually is loading.
- isLoaded.set(!activity.isLoading() && !TextUtils
- .isEmpty(activity.getUrl()));
- } else {
- isLoaded.set(false);
- }
- }
- });
-
- return isLoaded.get();
- } catch (Throwable e) {
- return false;
- }
- }
- }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT,
- CriteriaHelper.DEFAULT_POLLING_INTERVAL);
- }
}
diff --git a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
index ea89061..fc2f6a1 100644
--- a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
+++ b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
@@ -39,8 +39,6 @@ public class CronetSampleActivity extends Activity {
private CronetEngine mCronetEngine;
private String mUrl;
- private boolean mLoading = false;
- private int mHttpStatusCode = 0;
private TextView mResultText;
private TextView mReceiveDataText;
@@ -79,16 +77,14 @@ public class CronetSampleActivity extends Activity {
@Override
public void onSucceeded(UrlRequest request, UrlResponseInfo info) {
- mHttpStatusCode = info.getHttpStatusCode();
- Log.i(TAG, "****** Request Completed, status code is " + mHttpStatusCode
+ Log.i(TAG, "****** Request Completed, status code is " + info.getHttpStatusCode()
+ ", total received bytes is " + info.getReceivedBytesCount());
final String receivedData = mBytesReceived.toString();
final String url = info.getUrl();
- final String text = "Completed " + url + " (" + mHttpStatusCode + ")";
+ final String text = "Completed " + url + " (" + info.getHttpStatusCode() + ")";
CronetSampleActivity.this.runOnUiThread(new Runnable() {
public void run() {
- mLoading = false;
mResultText.setText(text);
mReceiveDataText.setText(receivedData);
promptForURL(url);
@@ -104,7 +100,6 @@ public class CronetSampleActivity extends Activity {
final String text = "Failed " + mUrl + " (" + error.getMessage() + ")";
CronetSampleActivity.this.runOnUiThread(new Runnable() {
public void run() {
- mLoading = false;
mResultText.setText(text);
promptForURL(url);
}
@@ -208,7 +203,6 @@ public class CronetSampleActivity extends Activity {
private void startWithURL(String url, String postData) {
Log.i(TAG, "Cronet started: " + url);
mUrl = url;
- mLoading = false;
Executor executor = Executors.newSingleThreadExecutor();
UrlRequest.Callback callback = new SimpleUrlRequestCallback();
@@ -217,27 +211,6 @@ public class CronetSampleActivity extends Activity {
builder.build().start();
}
- /**
- * This method is used in testing.
- */
- public String getUrl() {
- return mUrl;
- }
-
- /**
- * This method is used in testing.
- */
- public boolean isLoading() {
- return mLoading;
- }
-
- /**
- * This method is used in testing.
- */
- public int getHttpStatusCode() {
- return mHttpStatusCode;
- }
-
private void startNetLog() {
mCronetEngine.startNetLogToFile(
Environment.getExternalStorageDirectory().getPath() + "/cronet_sample_netlog.json",
diff --git a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleApplication.java b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleApplication.java
index ca1c502..dc19cff 100644
--- a/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleApplication.java
+++ b/components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleApplication.java
@@ -10,8 +10,4 @@ import android.app.Application;
* Application for managing the Cronet Sample.
*/
public class CronetSampleApplication extends Application {
- @Override
- public void onCreate() {
- super.onCreate();
- }
}
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java b/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java
deleted file mode 100644
index 8a9ac7a7..0000000
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2014 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 org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
-
-import android.os.SystemClock;
-
-/**
- * Helper methods for creating and managing criteria.
- * <p>
- * If possible, use callbacks or testing delegates instead of criteria as they
- * do not introduce any polling delays. Should only use Criteria if no suitable
- * other approach exists.
- */
-public class CriteriaHelper {
-
- /** The default maximum time to wait for a criteria to become valid. */
- public static final long DEFAULT_MAX_TIME_TO_POLL = scaleTimeout(3000);
-
- /**
- * The default polling interval to wait between checking for a satisfied
- * criteria.
- */
- public static final long DEFAULT_POLLING_INTERVAL = 50;
-
- /**
- * Checks whether the given Criteria is satisfied at a given interval, until
- * either the criteria is satisfied, or the specified maxTimeoutMs number of
- * ms has elapsed.
- *
- * @param criteria The Criteria that will be checked.
- * @param maxTimeoutMs The maximum number of ms that this check will be
- * performed for before timeout.
- * @param checkIntervalMs The number of ms between checks.
- * @return {@code true} if checking has ended with the criteria being
- * satisfied.
- * @throws InterruptedException
- */
- public static boolean pollForCriteria(Criteria criteria, long maxTimeoutMs,
- long checkIntervalMs) throws InterruptedException {
- boolean isSatisfied = criteria.isSatisfied();
- long startTime = SystemClock.uptimeMillis();
- while (!isSatisfied
- && SystemClock.uptimeMillis() - startTime < maxTimeoutMs) {
- Thread.sleep(checkIntervalMs);
- isSatisfied = criteria.isSatisfied();
- }
- return isSatisfied;
- }
-
- /**
- * Checks whether the given Criteria is satisfied polling at a default
- * interval.
- *
- * @param criteria The Criteria that will be checked.
- * @return {@code true} if checking has ended with the criteria being
- * satisfied.
- * @throws InterruptedException
- * @see #pollForCriteria(Criteria, long, long)
- */
- public static boolean pollForCriteria(Criteria criteria)
- throws InterruptedException {
- return pollForCriteria(criteria, DEFAULT_MAX_TIME_TO_POLL,
- DEFAULT_POLLING_INTERVAL);
- }
-
- /**
- * Performs the runnable action, then checks whether the given criteria are
- * satisfied until the specified timeout, using the pollForCriteria method.
- * If not, then the runnable action is performed again, to a maximum of
- * maxAttempts tries.
- */
- public static boolean runUntilCriteria(Runnable runnable, Criteria criteria,
- int maxAttempts, long maxTimeoutMs, long checkIntervalMs)
- throws InterruptedException {
- int count = 0;
- boolean success = false;
- while (count < maxAttempts && !success) {
- count++;
- runnable.run();
- success = pollForCriteria(criteria, maxTimeoutMs, checkIntervalMs);
- }
- return success;
- }
-}
diff --git a/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java b/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
index 4870946..b202aba 100644
--- a/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
+++ b/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
@@ -72,7 +72,6 @@ public class CronetTestFramework {
private final Context mContext;
private String mUrl;
- private boolean mLoading = false;
private int mHttpStatusCode = 0;
// CronetEngine.Builder used for this activity.
@@ -91,7 +90,6 @@ public class CronetTestFramework {
@Override
public void onRequestComplete(HttpUrlRequest request) {
- mLoading = false;
mComplete.open();
}
@@ -250,7 +248,6 @@ public class CronetTestFramework {
public void startWithURL(String url) {
Log.i(TAG, "Cronet started: " + url);
mUrl = url;
- mLoading = true;
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
@@ -265,10 +262,6 @@ public class CronetTestFramework {
return mUrl;
}
- public boolean isLoading() {
- return mLoading;
- }
-
public int getHttpStatusCode() {
return mHttpStatusCode;
}