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

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

Issue 141533006: [Android] Move the java content/ package to content_public/ to start the split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small fixes and findbugs line update Created 6 years, 11 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
deleted file mode 100644
index 878e8caf713720b7a33b045b82c6dcc705894f26..0000000000000000000000000000000000000000
--- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright 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.content.browser.test.util;
-
-import android.graphics.Rect;
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.JsonReader;
-
-import junit.framework.Assert;
-
-import org.chromium.content.browser.ContentView;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.concurrent.TimeoutException;
-
-/**
- * Collection of DOM-based utilities.
- */
-public class DOMUtils {
-
- /**
- * Returns the rect boundaries for a node by its id.
- */
- public static Rect getNodeBounds(
- final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- StringBuilder sb = new StringBuilder();
- sb.append("(function() {");
- sb.append(" var node = document.getElementById('" + nodeId + "');");
- sb.append(" if (!node) return null;");
- sb.append(" var width = node.offsetWidth;");
- sb.append(" var height = node.offsetHeight;");
- sb.append(" var x = -window.scrollX;");
- sb.append(" var y = -window.scrollY;");
- sb.append(" do {");
- sb.append(" x += node.offsetLeft;");
- sb.append(" y += node.offsetTop;");
- sb.append(" } while (node = node.offsetParent);");
- sb.append(" return [ x, y, width, height ];");
- sb.append("})();");
-
- String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
- view, viewClient, sb.toString());
-
- Assert.assertFalse("Failed to retrieve bounds for " + nodeId,
- jsonText.trim().equalsIgnoreCase("null"));
-
- JsonReader jsonReader = new JsonReader(new StringReader(jsonText));
- int[] bounds = new int[4];
- try {
- jsonReader.beginArray();
- int i = 0;
- while (jsonReader.hasNext()) {
- bounds[i++] = jsonReader.nextInt();
- }
- jsonReader.endArray();
- Assert.assertEquals("Invalid bounds returned.", 4, i);
-
- jsonReader.close();
- } catch (IOException exception) {
- Assert.fail("Failed to evaluate JavaScript: " + jsonText + "\n" + exception);
- }
-
- return new Rect(bounds[0], bounds[1], bounds[0] + bounds[2], bounds[1] + bounds[3]);
- }
-
- /**
- * Focus a DOM node by its id.
- */
- public static void focusNode(ActivityInstrumentationTestCase2 activityTestCase,
- final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- StringBuilder sb = new StringBuilder();
- sb.append("(function() {");
- sb.append(" var node = document.getElementById('" + nodeId + "');");
- sb.append(" if (node) node.focus();");
- sb.append("})();");
-
- JavaScriptUtils.executeJavaScriptAndWaitForResult(view, viewClient, sb.toString());
- }
-
- /**
- * Click a DOM node by its id.
- */
- public static void clickNode(ActivityInstrumentationTestCase2 activityTestCase,
- final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- int[] clickTarget = getClickTargetForNode(view, viewClient, nodeId);
- TouchCommon touchCommon = new TouchCommon(activityTestCase);
- touchCommon.singleClickView(view, clickTarget[0], clickTarget[1]);
- }
-
- /**
- * Long-press a DOM node by its id.
- */
- public static void longPressNode(ActivityInstrumentationTestCase2 activityTestCase,
- final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- int[] clickTarget = getClickTargetForNode(view, viewClient, nodeId);
- TouchCommon touchCommon = new TouchCommon(activityTestCase);
- touchCommon.longPressView(view, clickTarget[0], clickTarget[1]);
- }
-
- /**
- * Scrolls the view to ensure that the required DOM node is visible.
- */
- public static void scrollNodeIntoView(final ContentView view,
- TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- JavaScriptUtils.executeJavaScriptAndWaitForResult(view, viewClient,
- "document.getElementById('" + nodeId + "').scrollIntoView()");
- }
-
- /**
- * Returns the contents of the node by its id.
- */
- public static String getNodeContents(final ContentView view,
- TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- return getNodeField("textContent", view, viewClient, nodeId);
- }
-
- /**
- * Returns the value of the node by its id.
- */
- public static String getNodeValue(final ContentView view,
- TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- return getNodeField("value", view, viewClient, nodeId);
- }
-
- private static String getNodeField(String fieldName, final ContentView view,
- TestCallbackHelperContainer viewClient, String nodeId)
- throws InterruptedException, TimeoutException {
- StringBuilder sb = new StringBuilder();
- sb.append("(function() {");
- sb.append(" var node = document.getElementById('" + nodeId + "');");
- sb.append(" if (!node) return null;");
- sb.append(" if (!node." + fieldName + ") return null;");
- sb.append(" return [ node." + fieldName + " ];");
- sb.append("})();");
-
- String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
- view, viewClient, sb.toString());
- Assert.assertFalse("Failed to retrieve contents for " + nodeId,
- jsonText.trim().equalsIgnoreCase("null"));
-
- JsonReader jsonReader = new JsonReader(new StringReader(jsonText));
- String value = null;
- try {
- jsonReader.beginArray();
- if (jsonReader.hasNext()) value = jsonReader.nextString();
- jsonReader.endArray();
- Assert.assertNotNull("Invalid contents returned.", value);
-
- jsonReader.close();
- } catch (IOException exception) {
- Assert.fail("Failed to evaluate JavaScript: " + jsonText + "\n" + exception);
- }
- return value;
- }
-
- /**
- * Wait until a given node has non-zero bounds.
- * @return Whether the node started having non-zero bounds.
- */
- public static boolean waitForNonZeroNodeBounds(final ContentView view,
- final TestCallbackHelperContainer viewClient, final String nodeName)
- throws InterruptedException {
- return CriteriaHelper.pollForCriteria(new Criteria() {
- @Override
- public boolean isSatisfied() {
- try {
- return !DOMUtils.getNodeBounds(view, viewClient, nodeName).isEmpty();
- } catch (InterruptedException e) {
- // Intentionally do nothing
- return false;
- } catch (TimeoutException e) {
- // Intentionally do nothing
- return false;
- }
- }
- });
- }
-
- /**
- * Returns click targets for a given DOM node.
- */
- private static int[] getClickTargetForNode(final ContentView view,
- TestCallbackHelperContainer viewClient, String nodeName)
- throws InterruptedException, TimeoutException {
- Rect bounds = getNodeBounds(view, viewClient, nodeName);
- Assert.assertNotNull("Failed to get DOM element bounds of '" + nodeName + "'.", bounds);
-
- int clickX = (int) view.getRenderCoordinates().fromLocalCssToPix(bounds.exactCenterX())
- + view.getContentViewCore().getViewportSizeOffsetWidthPix();
- int clickY = (int) view.getRenderCoordinates().fromLocalCssToPix(bounds.exactCenterY())
- + view.getContentViewCore().getViewportSizeOffsetHeightPix();
- return new int[] { clickX, clickY };
- }
-}

Powered by Google App Engine
This is Rietveld 408576698