Commit 80bfc66f authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Re-enable ScreenOrientationListenerTest.java and run locking on UI thread.

BUG=356483,354553

Review URL: https://codereview.chromium.org/434693002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287112 0039d316-1c4b-4281-b951-d872f2087c98
parent e160b44f
...@@ -9,6 +9,7 @@ import android.os.Build; ...@@ -9,6 +9,7 @@ import android.os.Build;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
...@@ -50,6 +51,11 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -50,6 +51,11 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
} }
} }
private void runOnUiThreadAndWait(Runnable runnable) {
ThreadUtils.runOnUiThreadBlocking(runnable);
getInstrumentation().waitForIdleSync();
}
/** /**
* Locks the screen orientation to the predefined orientation type. * Locks the screen orientation to the predefined orientation type.
*/ */
...@@ -61,14 +67,20 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -61,14 +67,20 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
* Locks the screen orientation to the predefined orientation type then wait * Locks the screen orientation to the predefined orientation type then wait
* for the orientation change to happen. * for the orientation change to happen.
*/ */
private boolean lockOrientationAndWait(int orientation) private void lockOrientationAndWait(final int orientation) throws InterruptedException {
throws InterruptedException { runOnUiThreadAndWait(new Runnable() {
OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria( @Override
mObserver, orientationTypeToAngle(orientation)); public void run() {
try {
lockOrientation(orientation); lockOrientation(orientation);
} catch (Exception e) {
return CriteriaHelper.pollForCriteria(criteria); fail("Should not be there!");
}
}
});
CriteriaHelper.pollForCriteria(
new OrientationChangeObserverCriteria(mObserver, orientationTypeToAngle(orientation)));
} }
/** /**
...@@ -95,13 +107,22 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -95,13 +107,22 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
} }
private void setUpForConfigurationListener() throws InterruptedException { private void setUpForConfigurationListener() throws InterruptedException {
ScreenOrientationListener.getInstance().injectConfigurationListenerBackendForTest(); ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL); public void run() {
ScreenOrientationListener.getInstance().injectConfigurationListenerBackendForTest();
}
});
final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
waitForActiveShellToBeDoneLoading(); waitForActiveShellToBeDoneLoading();
ScreenOrientationListener.getInstance().addObserver( ThreadUtils.runOnUiThreadBlocking(new Runnable() {
mObserver, getInstrumentation().getTargetContext()); @Override
public void run() {
ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
}
});
} }
private boolean setUpForDisplayListener() throws InterruptedException { private boolean setUpForDisplayListener() throws InterruptedException {
...@@ -109,40 +130,18 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -109,40 +130,18 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
return false; return false;
ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL); final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
waitForActiveShellToBeDoneLoading(); waitForActiveShellToBeDoneLoading();
ScreenOrientationListener.getInstance().addObserver( ThreadUtils.runOnUiThreadBlocking(new Runnable() {
mObserver, getInstrumentation().getTargetContext()); @Override
public void run() {
ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
}
});
return true; return true;
} }
// At least one of these tests flakes 50% on all runs of
// contentshell_instrumentation_tests.
// crbug.com/356483
/*
@SmallTest
@Feature({"ScreenOrientation"})
public void testConfigurationListenerDefault() throws Exception {
setUpForConfigurationListener();
assertFalse(mObserver.mHasChanged);
assertEquals(-1, mObserver.mOrientation);
}
@SmallTest
@Feature({"ScreenOrientation"})
public void testConfigurationListenerAsyncSetup() throws Exception {
setUpForConfigurationListener();
// We should get a onScreenOrientationChange call asynchronously.
CriteriaHelper.pollForCriteria(new OrientationChangeObserverCriteria(
mObserver));
assertTrue(mObserver.mHasChanged);
assertTrue(mObserver.mOrientation != -1);
}
@MediumTest @MediumTest
@Feature({"ScreenOrientation"}) @Feature({"ScreenOrientation"})
public void testConfigurationListenerChanges() throws Exception { public void testConfigurationListenerChanges() throws Exception {
...@@ -186,28 +185,6 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -186,28 +185,6 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
assertEquals(90, mObserver.mOrientation); assertEquals(90, mObserver.mOrientation);
} }
@SmallTest
@Feature({"ScreenOrientation"})
public void testDisplayListenerDefault() throws Exception {
if (!setUpForDisplayListener())
return;
assertEquals(-1, mObserver.mOrientation);
}
@SmallTest
@Feature({"ScreenOrientation"})
public void testDisplayListenerAsyncSetup() throws Exception {
if (!setUpForDisplayListener())
return;
// We should get a onScreenOrientationChange call asynchronously.
CriteriaHelper.pollForCriteria(new OrientationChangeObserverCriteria(
mObserver));
assertTrue(mObserver.mOrientation != -1);
}
@MediumTest @MediumTest
@Feature({"ScreenOrientation"}) @Feature({"ScreenOrientation"})
public void testDisplayListenerChanges() throws Exception { public void testDisplayListenerChanges() throws Exception {
...@@ -254,5 +231,4 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase { ...@@ -254,5 +231,4 @@ public class ScreenOrientationListenerTest extends ContentShellTestBase {
lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); lockOrientationAndWait(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
assertEquals(-90, mObserver.mOrientation); assertEquals(-90, mObserver.mOrientation);
} }
*/
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment