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

Unified Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java

Issue 572013002: Removing ContentViewCore dependencies from direct WebContents functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch and addressed review comments. Created 6 years, 2 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: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java
index 84d84b66e473045dce2d27b8c1d2ca79620865da..46874fd4d2cb6a588400409d55a9ab1b52ccccfe 100644
--- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java
@@ -11,6 +11,7 @@ import android.util.JsonReader;
import junit.framework.Assert;
import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content_public.browser.WebContents;
import java.io.IOException;
import java.io.StringReader;
@@ -24,22 +25,22 @@ public class DOMUtils {
/**
* Returns whether the video with given {@code nodeId} has ended.
*/
- public static boolean hasVideoEnded(final ContentViewCore viewCore, final String nodeId)
+ public static boolean hasVideoEnded(final WebContents webContents, final String nodeId)
throws InterruptedException, TimeoutException {
- return getNodeField("ended", viewCore, nodeId, Boolean.class);
+ return getNodeField("ended", webContents, nodeId, Boolean.class);
}
/**
* Wait until the end of the video with given {@code nodeId}.
* @return Whether the video has ended.
*/
- public static boolean waitForEndOfVideo(final ContentViewCore viewCore, final String nodeId)
+ public static boolean waitForEndOfVideo(final WebContents webContents, final String nodeId)
throws InterruptedException {
return CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
try {
- return DOMUtils.hasVideoEnded(viewCore, nodeId);
+ return DOMUtils.hasVideoEnded(webContents, nodeId);
} catch (InterruptedException e) {
// Intentionally do nothing
return false;
@@ -54,19 +55,19 @@ public class DOMUtils {
/**
* Makes the document exit fullscreen.
*/
- public static void exitFullscreen(final ContentViewCore viewCore) {
+ public static void exitFullscreen(final WebContents webContents) {
StringBuilder sb = new StringBuilder();
sb.append("(function() {");
sb.append(" if (document.webkitExitFullscreen) document.webkitExitFullscreen();");
sb.append("})();");
- JavaScriptUtils.executeJavaScript(viewCore, sb.toString());
+ JavaScriptUtils.executeJavaScript(webContents, sb.toString());
}
/**
* Returns the rect boundaries for a node by its id.
*/
- public static Rect getNodeBounds(final ContentViewCore viewCore, String nodeId)
+ public static Rect getNodeBounds(final WebContents webContents, String nodeId)
throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder();
sb.append("(function() {");
@@ -84,7 +85,7 @@ public class DOMUtils {
sb.append("})();");
String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
- viewCore, sb.toString());
+ webContents, sb.toString());
Assert.assertFalse("Failed to retrieve bounds for " + nodeId,
jsonText.trim().equalsIgnoreCase("null"));
@@ -111,7 +112,7 @@ public class DOMUtils {
/**
* Focus a DOM node by its id.
*/
- public static void focusNode(final ContentViewCore viewCore, String nodeId)
+ public static void focusNode(final WebContents webContents, String nodeId)
throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder();
sb.append("(function() {");
@@ -119,7 +120,7 @@ public class DOMUtils {
sb.append(" if (node) node.focus();");
sb.append("})();");
- JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore, sb.toString());
+ JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents, sb.toString());
}
/**
@@ -147,38 +148,38 @@ public class DOMUtils {
/**
* Scrolls the view to ensure that the required DOM node is visible.
*/
- public static void scrollNodeIntoView(ContentViewCore viewCore, String nodeId)
+ public static void scrollNodeIntoView(WebContents webContents, String nodeId)
throws InterruptedException, TimeoutException {
- JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore,
+ JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents,
"document.getElementById('" + nodeId + "').scrollIntoView()");
}
/**
* Returns the contents of the node by its id.
*/
- public static String getNodeContents(ContentViewCore viewCore, String nodeId)
+ public static String getNodeContents(WebContents webContents, String nodeId)
throws InterruptedException, TimeoutException {
- return getNodeField("textContent", viewCore, nodeId, String.class);
+ return getNodeField("textContent", webContents, nodeId, String.class);
}
/**
* Returns the value of the node by its id.
*/
- public static String getNodeValue(final ContentViewCore viewCore, String nodeId)
+ public static String getNodeValue(final WebContents webContents, String nodeId)
throws InterruptedException, TimeoutException {
- return getNodeField("value", viewCore, nodeId, String.class);
+ return getNodeField("value", webContents, nodeId, String.class);
}
/**
* Returns the string value of a field of the node by its id.
*/
- public static String getNodeField(String fieldName, final ContentViewCore viewCore,
+ public static String getNodeField(String fieldName, final WebContents webContents,
String nodeId)
throws InterruptedException, TimeoutException {
- return getNodeField(fieldName, viewCore, nodeId, String.class);
+ return getNodeField(fieldName, webContents, nodeId, String.class);
}
- private static <T> T getNodeField(String fieldName, final ContentViewCore viewCore,
+ private static <T> T getNodeField(String fieldName, final WebContents webContents,
String nodeId, Class<T> valueType)
throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder();
@@ -189,7 +190,7 @@ public class DOMUtils {
sb.append("})();");
String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
- viewCore, sb.toString());
+ webContents, sb.toString());
Assert.assertFalse("Failed to retrieve contents for " + nodeId,
jsonText.trim().equalsIgnoreCase("null"));
@@ -224,14 +225,14 @@ public class DOMUtils {
* Wait until a given node has non-zero bounds.
* @return Whether the node started having non-zero bounds.
*/
- public static boolean waitForNonZeroNodeBounds(final ContentViewCore viewCore,
+ public static boolean waitForNonZeroNodeBounds(final WebContents webContents,
final String nodeName)
throws InterruptedException {
return CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
try {
- return !DOMUtils.getNodeBounds(viewCore, nodeName).isEmpty();
+ return !DOMUtils.getNodeBounds(webContents, nodeName).isEmpty();
} catch (InterruptedException e) {
// Intentionally do nothing
return false;
@@ -248,7 +249,7 @@ public class DOMUtils {
*/
private static int[] getClickTargetForNode(ContentViewCore viewCore, String nodeName)
throws InterruptedException, TimeoutException {
- Rect bounds = getNodeBounds(viewCore, nodeName);
+ Rect bounds = getNodeBounds(viewCore.getWebContents(), nodeName);
Assert.assertNotNull("Failed to get DOM element bounds of '" + nodeName + "'.", bounds);
int clickX = (int) viewCore.getRenderCoordinates().fromLocalCssToPix(bounds.exactCenterX());

Powered by Google App Engine
This is Rietveld 408576698