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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java

Issue 1276523003: Don't trigger HW acceleration from Toasts on low-end devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enhance PRESUBMIT message Created 5 years, 4 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: chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java b/chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java
index 0bf5896eb78dd707b7c50828a7bd8b9b39031d4a..b8789b7a2448b0c01d42d828179aa0b9c58881a0 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/hardware_acceleration/Utils.java
@@ -13,6 +13,7 @@ import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.ui.widget.Toast;
import java.util.HashSet;
import java.util.Set;
@@ -28,6 +29,19 @@ public class Utils {
* I.e. on low-end devices hardware acceleration must be off.
*/
public static void assertHardwareAcceleration(final ChromeActivity activity) throws Exception {
+ assertActivityAcceleration(activity);
+ assertToastAcceleration(activity);
+ }
+
+ /**
+ * Asserts that there is no thread named 'RenderThread' (which is essential
+ * for hardware acceleration).
+ */
+ public static void assertNoRenderThread() {
+ Assert.assertFalse(collectThreadNames().contains("RenderThread"));
+ }
+
+ private static void assertActivityAcceleration(final ChromeActivity activity) throws Exception {
final AtomicBoolean accelerated = new AtomicBoolean();
final CallbackHelper listenerCalled = new CallbackHelper();
@@ -49,7 +63,34 @@ public class Utils {
});
listenerCalled.waitForCallback(0);
+ assertAcceleration(accelerated);
+ }
+
+ private static void assertToastAcceleration(final ChromeActivity activity)
+ throws Exception {
+ final AtomicBoolean accelerated = new AtomicBoolean();
+ final CallbackHelper listenerCalled = new CallbackHelper();
+
+ ThreadUtils.postOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast toast = new Toast(activity);
+ toast.setView(new View(activity) {
+ @Override
+ public void onAttachedToWindow() {
+ accelerated.set(isHardwareAccelerated());
+ listenerCalled.notifyCalled();
+ }
+ });
+ toast.show();
+ }
+ });
+
+ listenerCalled.waitForCallback(0);
+ assertAcceleration(accelerated);
+ }
+ private static void assertAcceleration(AtomicBoolean accelerated) {
if (SysUtils.isLowEndDevice()) {
Assert.assertFalse(accelerated.get());
} else {
@@ -57,14 +98,6 @@ public class Utils {
}
}
- /**
- * Asserts that there is no thread named 'RenderThread' (which is essential
- * for hardware acceleration).
- */
- public static void assertNoRenderThread() {
- Assert.assertFalse(collectThreadNames().contains("RenderThread"));
- }
-
private static Set<String> collectThreadNames() {
Set<String> names = new HashSet<String>();
for (Thread thread : Thread.getAllStackTraces().keySet()) {

Powered by Google App Engine
This is Rietveld 408576698