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

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/util/GraphicsTestUtils.java

Issue 2691073003: Add javatests for the WebView SafeBrowsing feature (Closed)
Patch Set: Move getPixelColorAtCenterOfView to GraphicsTestUtils Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview.test.util; 5 package org.chromium.android_webview.test.util;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.graphics.Canvas; 8 import android.graphics.Canvas;
9 import android.view.View; 9 import android.view.View;
10 10
11 import org.chromium.android_webview.AwContents; 11 import org.chromium.android_webview.AwContents;
12 import org.chromium.android_webview.test.AwTestBase; 12 import org.chromium.android_webview.test.AwTestBase;
13 import org.chromium.android_webview.test.AwTestContainerView;
13 import org.chromium.base.ThreadUtils; 14 import org.chromium.base.ThreadUtils;
14 15
15 import java.util.concurrent.Callable; 16 import java.util.concurrent.Callable;
16 17
17 /** 18 /**
18 * Graphics-related test utils. 19 * Graphics-related test utils.
19 */ 20 */
20 public class GraphicsTestUtils { 21 public class GraphicsTestUtils {
21 /** 22 /**
22 * Draws the supplied {@link AwContents} into the returned {@link Bitmap}. 23 * Draws the supplied {@link AwContents} into the returned {@link Bitmap}.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 public static int sampleBackgroundColorOnUiThread(final AwContents awContent s) 72 public static int sampleBackgroundColorOnUiThread(final AwContents awContent s)
72 throws Exception { 73 throws Exception {
73 return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() { 74 return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() {
74 @Override 75 @Override
75 public Integer call() throws Exception { 76 public Integer call() throws Exception {
76 return drawAwContents(awContents, 10, 10, 0, 0).getPixel(0, 0); 77 return drawAwContents(awContents, 10, 10, 0, 0).getPixel(0, 0);
77 } 78 }
78 }); 79 });
79 } 80 }
80 81
82 // Gets the pixel color at the center of AwContents.
83 public static int getPixelColorAtCenterOfView(
84 final AwContents awContents, final AwTestContainerView testContainer View) {
85 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer >() {
86 @Override
87 public Integer call() {
88 return drawAwContents(awContents, 2, 2, -(float) testContainerVi ew.getWidth() / 2,
89 -(float) testContainerView.getHeight() / 2)
90 .getPixel(0, 0);
91 }
92 });
93 }
94
81 public static void pollForBackgroundColor(final AwContents awContents, final int c) 95 public static void pollForBackgroundColor(final AwContents awContents, final int c)
82 throws Throwable { 96 throws Throwable {
83 AwTestBase.pollInstrumentationThread(new Callable<Boolean>() { 97 AwTestBase.pollInstrumentationThread(new Callable<Boolean>() {
84 @Override 98 @Override
85 public Boolean call() throws Exception { 99 public Boolean call() throws Exception {
86 return sampleBackgroundColorOnUiThread(awContents) == c; 100 return sampleBackgroundColorOnUiThread(awContents) == c;
87 } 101 }
88 }); 102 });
89 } 103 }
90 104
91 private static Bitmap doDrawAwContents( 105 private static Bitmap doDrawAwContents(
92 AwContents awContents, int width, int height, Float dx, Float dy) { 106 AwContents awContents, int width, int height, Float dx, Float dy) {
93 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_88 88); 107 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_88 88);
94 Canvas canvas = new Canvas(bitmap); 108 Canvas canvas = new Canvas(bitmap);
95 if (dx != null && dy != null) { 109 if (dx != null && dy != null) {
96 canvas.translate(dx, dy); 110 canvas.translate(dx, dy);
97 } 111 }
98 awContents.onDraw(canvas); 112 awContents.onDraw(canvas);
99 return bitmap; 113 return bitmap;
100 } 114 }
101 } 115 }
OLDNEW
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java ('k') | android_webview/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698