This source file includes following definitions.
- getWindowOrientation
- getWindowOrientationChangeCount
- updateScreenOrientationForContent
- setUp
- Feature
- testNoOp
- Feature
- testExpectedValues
- Feature
- testNoChange
package org.chromium.content.browser;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellTestBase;
import java.util.concurrent.TimeoutException;
public class ScreenOrientationIntegrationTest extends ContentShellTestBase {
private static final String DEFAULT_URL = UrlUtils.encodeHtmlDataUri(
"<html><script>var changes=0;</script>" +
"<body onorientationchange='changes++;'>foo</body>" +
"</html>");
private ContentView mContentView;
private int getWindowOrientation()
throws InterruptedException, TimeoutException {
return Integer.parseInt(
JavaScriptUtils.executeJavaScriptAndWaitForResult(
mContentView,
new TestCallbackHelperContainer(mContentView),
"window.orientation"));
}
private int getWindowOrientationChangeCount()
throws InterruptedException, TimeoutException {
return Integer.parseInt(
JavaScriptUtils.executeJavaScriptAndWaitForResult(
mContentView,
new TestCallbackHelperContainer(mContentView),
"changes"));
}
private void updateScreenOrientationForContent(int orientation) {
mContentView.getContentViewCore().sendOrientationChangeEvent(orientation);
}
@Override
public void setUp() throws Exception {
super.setUp();
ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
waitForActiveShellToBeDoneLoading();
mContentView = activity.getActiveContentView();
}
@SmallTest
@Feature({"ScreenOrientation"})
public void testNoOp() throws Throwable {
assertEquals(0, getWindowOrientationChangeCount());
}
@SmallTest
@Feature({"ScreenOrientation"})
public void testExpectedValues() throws Throwable {
int[] values = { 90, -90, 180, 0, 90 };
values[0] = getWindowOrientation() == 0 ? 90 : 0;
for (int i = 0; i < values.length; ++i) {
updateScreenOrientationForContent(values[i]);
assertEquals(values[i], getWindowOrientation());
assertEquals(i + 1, getWindowOrientationChangeCount());
}
}
@SmallTest
@Feature({"ScreenOrientation"})
public void testNoChange() throws Throwable {
int angle = getWindowOrientation() == 0 ? 90 : 0;
updateScreenOrientationForContent(angle);
assertEquals(angle, getWindowOrientation());
assertEquals(1, getWindowOrientationChangeCount());
updateScreenOrientationForContent(angle);
assertEquals(angle, getWindowOrientation());
assertEquals(1, getWindowOrientationChangeCount());
updateScreenOrientationForContent(angle);
assertEquals(angle, getWindowOrientation());
assertEquals(1, getWindowOrientationChangeCount());
}
}