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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/RenderUtils.java

Issue 2114963002: Create Java infrastructure for UI Render Tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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: chrome/test/android/javatests/src/org/chromium/chrome/test/util/RenderUtils.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/RenderUtils.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/RenderUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..13d6641fb3f3a303904c1d3e8af7c95412bebe30
--- /dev/null
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/RenderUtils.java
@@ -0,0 +1,71 @@
+// 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.chrome.test.util;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.Point;
+import android.os.Build;
+import android.os.Environment;
+import android.view.View;
+
+import org.chromium.ui.UiUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * A collection of methods to aid in creating Render Tests - tests that render UI components.
+ */
+public class RenderUtils {
jbudorick 2016/07/01 15:34:22 @RenderTest and any supporting java code should be
PEConn 2016/07/01 16:46:13 So the main reason I put RenderUtils in here inste
jbudorick 2016/07/01 16:49:22 I'm not sure. I could certainly see the case for h
+
+ /**
+ * A class to contain all the TestClass level information associated with rendering views.
+ */
+ public static class ViewRenderer {
+ private final Activity mActivity;
+ private final String mTestClass;
+
+ public ViewRenderer(Activity activity, String testClass) {
+ mActivity = activity;
+ mTestClass = testClass;
+ }
+
+ public void save(View view, String desc) throws IOException {
+ renderViewToFile(mActivity, mTestClass, view, desc);
+ }
+ }
+
+ private static String imageName(Activity activity, String testClass, String desc) {
+ Point outSize = new Point();
+ activity.getWindowManager().getDefaultDisplay().getSize(outSize);
+ String orientation = outSize.x > outSize.y ? "land" : "port";
+ return String.format("%s.%s.%s.%s.png",
+ testClass, desc, Build.MODEL.replace(' ', '_'), orientation);
+ }
+
+ private static void renderViewToFile(Activity activity, String testClass, View view,
+ String desc) throws IOException {
+ renderViewToFile(view, imageName(activity, testClass, desc));
+ }
+
+ private static void renderViewToFile(View view, String filename) throws IOException {
+ Bitmap bm = UiUtils.generateScaledScreenshot(view, 0, Bitmap.Config.ARGB_8888);
+ saveBmp(bm, filename);
+ }
+
+ private static void saveBmp(Bitmap bmp, String filename) throws IOException {
+ File folder = new File(Environment.getExternalStorageDirectory() + "/render_tests");
+ if (!folder.exists()) {
+ folder.mkdir();
+ }
+
+ File file = new File(folder + "/" + filename);
+ FileOutputStream out = new FileOutputStream(file);
+ bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
+ out.close();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698