-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathToolTilMeasureTest.java
More file actions
72 lines (64 loc) · 2.72 KB
/
ToolTilMeasureTest.java
File metadata and controls
72 lines (64 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package tourguide.tourguidedemo;
import android.app.Activity;
import android.graphics.Point;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.Display;
import android.view.View;
import tourguide.instrumentation.test.ToolTipMeasureTestActivity;
/**
* Created by tanjunrong on 8/6/15.
*/
public class ToolTilMeasureTest extends ActivityInstrumentationTestCase2<ToolTipMeasureTestActivity> {
public static final String TOURGUIDE_TEST = "tourguide_test";
ToolTipMeasureTestActivity mActivity;
View mToolTip;
public ToolTilMeasureTest() {
super(ToolTipMeasureTestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Starts the activity under test using the default Intent with:
// action = {@link Intent#ACTION_MAIN}
// flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
// All other fields are null or empty.
mActivity = getActivity();
mToolTip = mActivity.mTutorialHandler.getToolTip();
}
public void testNoCrash(){
// mToolTip.performClick();
Log.d(TOURGUIDE_TEST,"height:" + mToolTip.getHeight());
Log.d(TOURGUIDE_TEST,"width:" + mToolTip.getWidth());
Log.d(TOURGUIDE_TEST,"getX:" + mToolTip.getX());
Log.d(TOURGUIDE_TEST, "screen width:" + getScreenWidth(mActivity));
// mToolTip.getViewTreeObserver().addOnGlobalLayoutListener(
// new ViewTreeObserver.OnGlobalLayoutListener() {
//
// @Override
// public void onGlobalLayout() {
// mToolTip.getViewTreeObserver().removeGlobalOnLayoutListener(this);
// }
// });
boolean isOutOfLeftBound = mToolTip.getX() < 0;
boolean isOutOfRightBound = (mToolTip.getX()+mToolTip.getWidth()) > getScreenWidth(mActivity);
assertFalse("x of ToolTip is out of screen boundary", isOutOfLeftBound || isOutOfRightBound);
boolean isOutOfTopBound = mToolTip.getY() < 0;
boolean isOutOfBottomBound = (mToolTip.getY()+mToolTip.getHeight()) > getScreenHeight(mActivity);
assertFalse("y of ToolTip is out of screen boundary", isOutOfTopBound || isOutOfBottomBound);
}
public int getScreenWidth(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
return width;
}
public int getScreenHeight(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
return height;
}
}