Commit a9ca2310 authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Screen Orientation: use OrientationLockType enum for lockOrientation().

BUG=162827

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

git-svn-id: svn://svn.chromium.org/blink/trunk@169972 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ecae96bd
......@@ -4,17 +4,17 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation('invalid-orientation') is false
PASS screen.lockOrientation('invalid-orientation') threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('invalid-orientation') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(null) is false
PASS screen.lockOrientation(null) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('null') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(undefined) is false
PASS screen.lockOrientation(undefined) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('undefined') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(123) is false
PASS screen.lockOrientation(123) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('123') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(window) is false
PASS screen.lockOrientation(window) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('[object Window]') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(['portrait-primary', 'landscape-primary']) is false
PASS screen.lockOrientation(['portrait-primary', 'landscape-primary']) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,landscape-primary') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation() threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': 1 argument required, but only 0 present..
PASS screen.orientation is "portrait-primary"
......
......@@ -18,18 +18,22 @@ function completeTest() {
screen.addEventListener("orientationchange", onOrientationChangeEvent);
function typeErrorEnum(argStr) {
return "TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('" + argStr + "') is not a valid enum value.";
}
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation('invalid-orientation')");
shouldThrow("screen.lockOrientation('invalid-orientation')", "typeErrorEnum('invalid-orientation')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation(null)");
shouldThrow("screen.lockOrientation(null)", "typeErrorEnum('null')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation(undefined)");
shouldThrow("screen.lockOrientation(undefined)", "typeErrorEnum('undefined')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation(123)");
shouldThrow("screen.lockOrientation(123)", "typeErrorEnum('123')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation(window)");
shouldThrow("screen.lockOrientation(window)", "typeErrorEnum('[object Window]')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldBeFalse("screen.lockOrientation(['portrait-primary', 'landscape-primary'])");
shouldThrow("screen.lockOrientation(['portrait-primary', 'landscape-primary'])", "typeErrorEnum('portrait-primary,landscape-primary')");
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldThrow("screen.lockOrientation()", '"TypeError: Failed to execute \'lockOrientation\' on \'Screen\': 1 argument required, but only 0 present."');
......
......@@ -4,11 +4,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation(['portrait-primary', 'invalid-orientation']) is false
PASS screen.lockOrientation(['portrait-primary', null]) is false
PASS screen.lockOrientation(['portrait-primary', undefined]) is false
PASS screen.lockOrientation(['portrait-primary', 123]) is false
PASS screen.lockOrientation(['portrait-primary', window]) is false
PASS screen.lockOrientation(['portrait-primary', 'invalid-orientation']) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,invalid-orientation') is not a valid enum value..
PASS screen.lockOrientation(['portrait-primary', null]) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,') is not a valid enum value..
PASS screen.lockOrientation(['portrait-primary', undefined]) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,') is not a valid enum value..
PASS screen.lockOrientation(['portrait-primary', 123]) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,123') is not a valid enum value..
PASS screen.lockOrientation(['portrait-primary', window]) threw exception TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('portrait-primary,[object Window]') is not a valid enum value..
PASS screen.orientation is "portrait-primary"
PASS successfullyParsed is true
......
......@@ -9,7 +9,7 @@ window.jsTestIsAsync = true;
function onOrientationChangeEvent(ev) {
testFailed("Unexpected 'orientationchange' event");
}
function completeTest() {
shouldBeEqualToString("screen.orientation", "portrait-primary");
screen.unlockOrientation();
......@@ -18,13 +18,17 @@ function completeTest() {
screen.addEventListener("orientationchange", onOrientationChangeEvent);
function typeErrorEnum(argStr) {
return "TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter 1 ('" + argStr + "') is not a valid enum value.";
}
shouldBeEqualToString("screen.orientation", "portrait-primary");
// Bad argument to lockOrientation(), we should not get locked.
shouldBeFalse("screen.lockOrientation(['portrait-primary', 'invalid-orientation'])");
shouldBeFalse("screen.lockOrientation(['portrait-primary', null])");
shouldBeFalse("screen.lockOrientation(['portrait-primary', undefined])");
shouldBeFalse("screen.lockOrientation(['portrait-primary', 123])");
shouldBeFalse("screen.lockOrientation(['portrait-primary', window])");
shouldThrow("screen.lockOrientation(['portrait-primary', 'invalid-orientation'])", "typeErrorEnum('portrait-primary,invalid-orientation')");
shouldThrow("screen.lockOrientation(['portrait-primary', null])", "typeErrorEnum('portrait-primary,')");
shouldThrow("screen.lockOrientation(['portrait-primary', undefined])", "typeErrorEnum('portrait-primary,')");
shouldThrow("screen.lockOrientation(['portrait-primary', 123])", "typeErrorEnum('portrait-primary,123')");
shouldThrow("screen.lockOrientation(['portrait-primary', window])", "typeErrorEnum('portrait-primary,[object Window]')");
// Finish asynchronously to give events a chance to fire.
setTimeout(completeTest, 0);
......
......@@ -5,9 +5,14 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS screen.orientation is "portrait-primary"
PASS screen.unlockOrientation() did not throw exception.
PASS screen.lockOrientation('any') is true
PASS screen.lockOrientation('portrait') is true
PASS screen.lockOrientation('landscape') is true
PASS screen.lockOrientation('portrait-primary') is true
PASS screen.lockOrientation('portrait-secondary') is true
PASS screen.lockOrientation('landscape-primary') is true
PASS screen.orientation is "portrait-primary"
PASS screen.lockOrientation('landscape-secondary') is true
PASS screen.orientation is "portrait-primary"
PASS screen.unlockOrientation() did not throw exception.
PASS successfullyParsed is true
......
......@@ -7,9 +7,14 @@ description("Basic screen.lockOrientation() / screen.unlockOrientation() testing
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldNotThrow("screen.unlockOrientation()");
shouldBeTrue("screen.lockOrientation('landscape-primary')");
shouldBeEqualToString("screen.orientation", "portrait-primary"); // Should update asynchronously.
shouldBeTrue("screen.lockOrientation('landscape-secondary')"); // Consecutive locking.
[ 'any', 'portrait', 'landscape', 'portrait-primary', 'portrait-secondary',
'landscape-primary', 'landscape-secondary' ].forEach(function(orientation) {
shouldBeTrue("screen.lockOrientation('" + orientation + "')");
});
// Update is made asynchronously so that shouldn't change.
shouldBeEqualToString("screen.orientation", "portrait-primary");
shouldNotThrow("screen.unlockOrientation()");
</script>
</body>
......
......@@ -53,9 +53,14 @@ static const AtomicString& orientationToString(blink::WebScreenOrientation orien
static blink::WebScreenOrientations stringToOrientations(const AtomicString& orientationString)
{
DEFINE_STATIC_LOCAL(const AtomicString, any, ("any", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, portrait, ("portrait", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, landscape, ("landscape", AtomicString::ConstructFromLiteral));
if (orientationString == any) {
return blink::WebScreenOrientationPortraitPrimary | blink::WebScreenOrientationPortraitSecondary |
blink::WebScreenOrientationLandscapePrimary | blink::WebScreenOrientationLandscapeSecondary;
}
if (orientationString == portrait)
return blink::WebScreenOrientationPortraitPrimary | blink::WebScreenOrientationPortraitSecondary;
if (orientationString == landscape)
......
......@@ -9,12 +9,22 @@ enum OrientationType {
"landscape-secondary"
};
enum OrientationLockType {
"any",
"landscape",
"portrait",
"portrait-primary",
"portrait-secondary",
"landscape-primary",
"landscape-secondary"
};
[
RuntimeEnabled=ScreenOrientation
] partial interface Screen {
readonly attribute OrientationType orientation;
boolean lockOrientation(DOMString orientation);
boolean lockOrientation(OrientationLockType orientation);
void unlockOrientation();
attribute EventHandler onorientationchange;
......
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