Bug 1396951 - 5. Remove getLayerView usage from Robocop code; r?gbrown
Find the Fennec LayerView through `Solo.getView()` and the View id
instead of going through `GeckoAppShell.getLayerView()`.
MozReview-Commit-ID: FVcPM0fYorf
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecNativeActions.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecNativeActions.java
@@ -351,17 +351,17 @@ public class FennecNativeActions impleme
private boolean mPaintDone;
private boolean mListening;
private final LayerView mLayerView;
private final DrawListener mDrawListener;
PaintExpecter() {
final PaintExpecter expecter = this;
- mLayerView = GeckoAppShell.getLayerView();
+ mLayerView = (LayerView) mSolo.getView(R.id.layer_view);
mDrawListener = new DrawListener() {
@Override
public void drawFinished() {
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
"Received drawFinished notification");
expecter.notifyOfEvent();
}
};
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/BaseTest.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/BaseTest.java
@@ -351,17 +351,18 @@ abstract class BaseTest extends BaseRobo
if (!foundText) {
if ((mScreenMidWidth == 0) || (mScreenMidHeight == 0)) {
mScreenMidWidth = mDriver.getGeckoWidth()/2;
mScreenMidHeight = mDriver.getGeckoHeight()/2;
}
// If we don't see the item, scroll down once in case it's off-screen.
// Hacky way to scroll down. solo.scroll* does not work in dialogs.
- MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+ MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mSolo,
+ mDriver.getGeckoLeft(), mDriver.getGeckoTop());
meh.dragSync(mScreenMidWidth, mScreenMidHeight+100, mScreenMidWidth, mScreenMidHeight-100);
foundText = mSolo.waitForText(txt);
}
return foundText;
}
/**
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/MotionEventHelper.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/MotionEventHelper.java
@@ -1,17 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tests;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.PrefsHelper;
+import org.mozilla.gecko.R;
import org.mozilla.gecko.gfx.LayerView;
-import org.mozilla.gecko.PrefsHelper;
+
+import com.robotium.solo.Solo;
import android.app.Instrumentation;
import android.os.SystemClock;
import android.util.Log;
import android.view.MotionEvent;
class MotionEventHelper {
private static final String LOGTAG = "RobocopMotionEventHelper";
@@ -21,21 +24,22 @@ class MotionEventHelper {
private final Instrumentation mInstrumentation;
private final int mSurfaceOffsetX;
private final int mSurfaceOffsetY;
private final LayerView layerView;
private boolean mApzEnabled;
private float mTouchStartTolerance;
private final int mDpi;
- public MotionEventHelper(Instrumentation inst, int surfaceOffsetX, int surfaceOffsetY) {
+ public MotionEventHelper(Instrumentation inst, Solo solo,
+ int surfaceOffsetX, int surfaceOffsetY) {
mInstrumentation = inst;
mSurfaceOffsetX = surfaceOffsetX;
mSurfaceOffsetY = surfaceOffsetY;
- layerView = GeckoAppShell.getLayerView();
+ layerView = (LayerView) solo.getCurrentActivity().findViewById(R.id.layer_view);
mApzEnabled = false;
mTouchStartTolerance = 0.0f;
mDpi = GeckoAppShell.getDpi();
Log.i(LOGTAG, "Initialized using offset (" + mSurfaceOffsetX + "," + mSurfaceOffsetY + ")");
PrefsHelper.getPref("layers.async-pan-zoom.enabled", new PrefsHelper.PrefHandlerBase() {
@Override public void prefValue(String pref, boolean value) {
mApzEnabled = value;
}
@@ -113,17 +117,19 @@ class MotionEventHelper {
}
return downTime;
}
public Thread dragAsync(final float startX, final float startY, final float endX, final float endY, final long durationMillis) {
Thread t = new Thread() {
@Override
public void run() {
- layerView.setIsLongpressEnabled(false);
+ if (layerView != null) {
+ layerView.setIsLongpressEnabled(false);
+ }
int numEvents = (int)(durationMillis * DRAG_EVENTS_PER_SECOND / 1000);
float eventDx = (endX - startX) / numEvents;
float eventDy = (endY - startY) / numEvents;
long downTime = movePastTouchStartTolerance(startX, startY, endX, endY);
for (int i = 0; i < numEvents - 1; i++) {
downTime = move(downTime, startX + (eventDx * i), startY + (eventDy * i));
try {
@@ -138,17 +144,19 @@ class MotionEventHelper {
Thread.sleep(1000L);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
// do the last one using endX/endY directly to avoid rounding errors
downTime = move(downTime, endX, endY);
downTime = up(downTime, endX, endY);
- layerView.setIsLongpressEnabled(true);
+ if (layerView != null) {
+ layerView.setIsLongpressEnabled(true);
+ }
}
};
t.start();
return t;
}
public void dragSync(float startX, float startY, float endX, float endY, long durationMillis) {
try {
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testAxisLocking.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testAxisLocking.java
@@ -14,17 +14,18 @@ import org.mozilla.gecko.PaintedSurface;
* - Verify that the 5-degree angle was thrown out and it dragged vertically
* - Drag page upwards at a 45-degree angle
* - Verify that the 45-degree angle was not thrown out and it dragged diagonally
*/
public class testAxisLocking extends PixelTest {
public void testAxisLocking() {
String url = getAbsoluteUrl(mStringHelper.ROBOCOP_BOXES_URL);
- MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+ MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mSolo,
+ mDriver.getGeckoLeft(), mDriver.getGeckoTop());
blockForGeckoReady();
// load page and check we're at 0,0
loadAndVerifyBoxes(url);
// drag page upwards by 100 pixels with a slight angle. verify that
// axis locking prevents any horizontal scrolling
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testFlingCorrectness.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testFlingCorrectness.java
@@ -12,17 +12,18 @@ import org.mozilla.gecko.PaintedSurface;
* - Loads a page and verifies it draws
* - Drags page upwards by 200 pixels to get ready for a fling
* - Fling the page downwards so we get back to the top and verify.
*/
public class testFlingCorrectness extends PixelTest {
public void testFlingCorrectness() {
String url = getAbsoluteUrl(mStringHelper.ROBOCOP_BOXES_URL);
- MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+ MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mSolo,
+ mDriver.getGeckoLeft(), mDriver.getGeckoTop());
blockForGeckoReady();
// load page and check we're at 0,0
loadAndVerifyBoxes(url);
// drag page upwards by 200 pixels (use two drags instead of one in case
// the screen size is small)
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testPanCorrectness.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testPanCorrectness.java
@@ -12,17 +12,18 @@ import org.mozilla.gecko.PaintedSurface;
* - Loads a page and verifies it draws
* - drags page upwards by 100 pixels and verifies it draws
* - drags page leftwards by 100 pixels and verifies it draws
*/
public class testPanCorrectness extends PixelTest {
public void testPanCorrectness() {
String url = getAbsoluteUrl(mStringHelper.ROBOCOP_BOXES_URL);
- MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+ MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mSolo,
+ mDriver.getGeckoLeft(), mDriver.getGeckoTop());
blockForGeckoReady();
// load page and check we're at 0,0
loadAndVerifyBoxes(url);
// drag page upwards by 100 pixels
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testVkbOverlap.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testVkbOverlap.java
@@ -24,17 +24,18 @@ public class testVkbOverlap extends Pixe
testSetup("", "phone".equals(mDevice.type));
}
private void testSetup(String viewport, boolean shouldZoom) {
loadAndPaint(getAbsoluteUrl("/robocop/test_viewport.sjs?metadata=" + Uri.encode(viewport)));
// scroll to the bottom of the page and let it settle
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
- MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
+ MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mSolo,
+ mDriver.getGeckoLeft(), mDriver.getGeckoTop());
meh.dragSync(10, 150, 10, 50);
// the input field has a green background, so let's count the number of green pixels
int greenPixelCount = 0;
PaintedSurface painted = waitForPaint(paintExpecter);
paintExpecter.unregisterListener();
try {