blob: 345dcb7aecd75996e210f2b5200232dcfe88edcc [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>orientation_test</title>
<link rel="stylesheet" href="/filez/_main/third_party/js/qunit/qunit.css">
<script src="/filez/_main/third_party/js/qunit/qunit.js"></script>
<script src="/filez/_main/third_party/js/qunit/qunit_test_runner.js"></script>
<script src="test_bootstrap.js"></script>
<script type="text/javascript">
goog.require('bot.dom');
goog.require('bot.window');
goog.require('goog.dom');
goog.require('goog.events');
</script>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script type="text/javascript">
var iframe;
(function() {
if (goog.userAgent.product.CHROME) {
goog.userAgent.MOBILE = true;
}
})();
QUnit.testStart(function() {
if (orientationSupported()) {
iframe = document.createElement('iframe');
iframe.src = 'testdata/blank_page.html';
iframe.style.backgroundColor = 'blue';
iframe.width = '300px';
iframe.height = '480px';
document.body.appendChild(iframe);
bot.setWindow(goog.dom.getFrameContentWindow(iframe));
}
});
QUnit.testDone(function() {
if (iframe) {
document.body.removeChild(iframe);
iframe = null;
}
});
function orientationSupported() {
return goog.userAgent.MOBILE || goog.userAgent.product.ANDROID;
}
function isPortrait() {
var height = bot.getWindow().frameElement.offsetHeight;
var width = bot.getWindow().frameElement.offsetWidth;
return height > width;
}
function assertOrientationChange(assert, shouldOrientationChangeFire, orientation) {
var orientationChangeFired = false;
goog.events.listenOnce(bot.getWindow(), 'orientationchange', function() {
orientationChangeFired = true;
});
bot.window.changeOrientation(orientation);
assert.strictEqual(orientationChangeFired, shouldOrientationChangeFire);
}
QUnit.test('changingOrientation', function(assert) {
if (!orientationSupported()) {
assert.ok(true, 'Skipping: orientation not supported');
return;
}
assert.ok(isPortrait());
assertOrientationChange(assert, true, bot.window.Orientation.LANDSCAPE);
assert.notOk(isPortrait());
if (!bot.userAgent.ANDROID_PRE_GINGERBREAD) {
assertOrientationChange(assert, true, bot.window.Orientation.PORTRAIT);
assert.ok(isPortrait());
assertOrientationChange(assert, true, bot.window.Orientation.LANDSCAPE_SECONDARY);
assert.notOk(isPortrait());
}
});
QUnit.test('noChangeWhenOrientationDoesNotChange', function(assert) {
if (!orientationSupported()) {
assert.ok(true, 'Skipping: orientation not supported');
return;
}
assert.ok(isPortrait());
assertOrientationChange(assert, false, bot.window.Orientation.PORTRAIT);
});
QUnit.test('maybeChangeForPortraitSecondary', function(assert) {
if (!orientationSupported()) {
assert.ok(true, 'Skipping: orientation not supported');
return;
}
assert.ok(isPortrait());
assertOrientationChange(assert, goog.userAgent.MOBILE ? false : true,
bot.window.Orientation.PORTRAIT_SECONDARY);
});
</script>
</body>
</html>