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

Unified Diff: base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java

Issue 10690190: Upstream GestureDetectorProxyTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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: base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java
diff --git a/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java b/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java
new file mode 100644
index 0000000000000000000000000000000000000000..9dede747cc62c18170b07d1b482d31d133e7a2bd
--- /dev/null
+++ b/base/android/javatests/src/org/chromium/base/test/ScalableTimeout.java
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 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.base.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Arrays;
+
+/**
+ * Utility class for scaling various timeouts by a common factor.
+ * For example, to run tests under Valgrind, you might want the following:
+ * adb shell "echo 20.0 > /data/local/chrome_timeout_scale"
bulach 2012/07/16 13:22:44 nit: I think this is /data/local/tmp/ now..
+ */
+public class ScalableTimeout {
+ private static Double sTimeoutScale = null;
+ private static final String PROPERTY_FILE = "/data/local/chrome_timeout_scale";
+
+ public static long ScaleTimeout(long timeout) {
+ if (sTimeoutScale == null) {
+ try {
+ char[] data = readUtf8FileFully(PROPERTY_FILE, 32);
+ sTimeoutScale = Double.parseDouble(new String(data));
+ } catch (Exception e) {
+ // NumberFormatException, FileNotFoundException, IOException
+ sTimeoutScale = 1.0;
+ }
+ }
+ return (long)(timeout * sTimeoutScale);
+ }
+
+ /**
+ * @param fileName the file to read in.
+ * @param sizeLimit cap on the file size: will throw an exception if exceeded
+ * @return Array of chars read from the file
+ * @throws FileNotFoundException file does not exceed
+ * @throws IOException error encountered accessing the file
+ */
+ private static char[] readUtf8FileFully(String fileName, int sizeLimit) throws
brettw 2012/07/17 19:45:03 In C++ we have ReadFileToString. I wonder if we sh
bulach 2012/07/18 17:15:14 that's a good idea, we can certainly do both (move
+ FileNotFoundException, IOException {
+ Reader reader = null;
+ try {
+ File f = new File(fileName);
+ if (f.length() > sizeLimit) {
+ throw new IOException("File " + fileName + " length " + f.length() +
+ " exceeds limit " + sizeLimit);
+ }
+ char[] buffer = new char[(int) f.length()];
+ reader = new InputStreamReader(new FileInputStream(f), "UTF-8");
+ int charsRead = reader.read(buffer);
+ // Debug check that we've exhausted the input stream (will fail e.g. if the
+ // file grew after we inspected its length).
+ assert !reader.ready();
+ return charsRead < buffer.length ? Arrays.copyOfRange(buffer, 0, charsRead) : buffer;
+ } finally {
+ if (reader != null) reader.close();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698