Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / input / InsertionHandleTest.java
index 7c35962..e6d07b9 100644 (file)
@@ -12,21 +12,23 @@ import android.test.suitebuilder.annotation.MediumTest;
 import android.text.Editable;
 import android.text.Selection;
 import android.view.KeyEvent;
+import android.view.View;
 
 import org.chromium.base.test.util.DisabledTest;
 import org.chromium.base.test.util.Feature;
 import org.chromium.base.test.util.UrlUtils;
-import org.chromium.content.browser.ContentView;
 import org.chromium.content.browser.RenderCoordinates;
 import org.chromium.content.browser.test.util.Criteria;
 import org.chromium.content.browser.test.util.CriteriaHelper;
 import org.chromium.content.browser.test.util.DOMUtils;
-import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
 import org.chromium.content.browser.test.util.TestTouchUtils;
 import org.chromium.content.browser.test.util.TouchCommon;
 import org.chromium.content_shell_apk.ContentShellTestBase;
 
+/**
+ * Tests the insertion handle that allows users to paste text.
+ */
 public class InsertionHandleTest extends ContentShellTestBase {
     private static final String META_DISABLE_ZOOM =
         "<meta name=\"viewport\" content=\"" +
@@ -71,7 +73,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
 
         // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never
         // brought up.
-        getImeAdapter().setInputMethodManagerWrapper(
+        getContentViewCore().getImeAdapterForTest().setInputMethodManagerWrapper(
                 new TestInputMethodManagerWrapper(getContentViewCore()));
     }
 
@@ -82,7 +84,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
         clickNodeToShowInsertionHandle(TEXTAREA_ID);
 
         // Unselecting should cause the handle to disappear.
-        getImeAdapter().unselect();
+        unselectOnMainSync();
         assertTrue(waitForHandleShowingEquals(false));
     }
 
@@ -201,7 +203,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
 
         // The input box does not go to the edge of the screen, and neither should the insertion
         // handle.
-        dragToX = getContentView().getWidth();
+        dragToX = getContentViewCore().getContainerView().getWidth();
         dragHandleTo(dragToX, dragToY);
         assertTrue(handle.getPositionX() < dragToX - 100);
     }
@@ -218,19 +220,18 @@ public class InsertionHandleTest extends ContentShellTestBase {
         // click (only if it changes the selection), the insertion handle is displayed. So that the
         // second click changes the selection, the two clicks should be in sufficiently different
         // locations.
-        Rect nodeBounds = DOMUtils.getNodeBounds(getContentView(),
-                new TestCallbackHelperContainer(getContentView()), nodeId);
+        Rect nodeBounds = DOMUtils.getNodeBounds(getContentViewCore(), nodeId);
 
-        RenderCoordinates renderCoordinates = getContentView().getRenderCoordinates();
-        int offsetX = getContentView().getContentViewCore().getViewportSizeOffsetWidthPix();
-        int offsetY = getContentView().getContentViewCore().getViewportSizeOffsetHeightPix();
+        RenderCoordinates renderCoordinates = getContentViewCore().getRenderCoordinates();
+        int offsetX = getContentViewCore().getViewportSizeOffsetWidthPix();
+        int offsetY = getContentViewCore().getViewportSizeOffsetHeightPix();
         float left = renderCoordinates.fromLocalCssToPix(nodeBounds.left) + offsetX;
         float right = renderCoordinates.fromLocalCssToPix(nodeBounds.right) + offsetX;
         float top = renderCoordinates.fromLocalCssToPix(nodeBounds.top) + offsetY;
         float bottom = renderCoordinates.fromLocalCssToPix(nodeBounds.bottom) + offsetY;
 
         TouchCommon touchCommon = new TouchCommon(this);
-        touchCommon.singleClickView(getContentView(),
+        touchCommon.singleClickView(getContentViewCore().getContainerView(),
                 (int)(left + 3 * (right - left) / 4), (int)(top + (bottom - top) / 2));
 
 
@@ -238,7 +239,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
         assertTrue(waitForHasSelectionPosition());
 
         // TODO(cjhopman): Wait for keyboard display finished?
-        touchCommon.singleClickView(getContentView(),
+        touchCommon.singleClickView(getContentViewCore().getContainerView(),
                 (int)(left + (right - left) / 4), (int)(top + (bottom - top) / 2));
         assertTrue(waitForHandleShowingEquals(true));
         assertTrue(waitForHandleViewStopped());
@@ -292,7 +293,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
         HandleView handle = ihc.getHandleViewForTest();
         int initialX = handle.getPositionX();
         int initialY = handle.getPositionY();
-        ContentView view = getContentView();
+        View view = getContentViewCore().getContainerView();
 
         int fromLocation[] = TestTouchUtils.getAbsoluteLocationFromRelative(view, initialX,
                 initialY + VERTICAL_OFFSET);
@@ -362,6 +363,15 @@ public class InsertionHandleTest extends ContentShellTestBase {
         });
     }
 
+    private void unselectOnMainSync() {
+        getInstrumentation().runOnMainSync(new Runnable() {
+            @Override
+            public void run() {
+                getContentViewCore().getImeAdapterForTest().unselect();
+            }
+        });
+    }
+
     private int getSelectionStart() {
         return Selection.getSelectionStart(getEditable());
     }
@@ -383,8 +393,4 @@ public class InsertionHandleTest extends ContentShellTestBase {
                 (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
         clipMgr.setPrimaryClip(ClipData.newPlainText(null, text));
     }
-
-    private ImeAdapter getImeAdapter() {
-        return getContentViewCore().getImeAdapterForTest();
-    }
 }