Bug 1131470 - Part 6: ScreenOrientation tests. r=baku

--HG--
extra : rebase_source : bce22b7614a58208b8706632661b7bebed813c87
This commit is contained in:
William Chen 2015-08-18 15:28:01 -07:00
Родитель 0625e989b4
Коммит 2318fd1af8
8 изменённых файлов: 208 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<body>
<script src="orientationcommon.js"></script>
<script>
window.addEventListener("message", function(event) {
var p = specialPowersLock(event.data);
p.then(function() {
event.source.postMessage("success", "*");
}).catch(function(err) {
event.source.postMessage("error", "*");
});
}, false);
</script>

Просмотреть файл

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body>
<script>
var recordedOrientations = [];
screen.orientation.onchange = function() {
recordedOrientations.push(screen.orientation.type);
};
window.addEventListener("message", function(event) {
if (event.data == "report") {
event.source.postMessage(recordedOrientations, "*");
}
}, false);
</script>

Просмотреть файл

@ -179,11 +179,13 @@ support-files =
file_htmlserializer_2_latin1.html
file_htmlserializer_ipv6.html
file_htmlserializer_ipv6_out.html
file_lock_orientation.html
file_mozfiledataurl_audio.ogg
file_mozfiledataurl_doc.html
file_mozfiledataurl_img.jpg
file_mozfiledataurl_inner.html
file_mozfiledataurl_text.txt
file_record_orientation.html
file_restrictedEventSource.sjs
file_simplecontentpolicy.js
file_websocket_basic_wsh.py
@ -222,6 +224,7 @@ support-files =
invalid_accesscontrol.resource
invalid_accesscontrol.resource^headers^
mutationobserver_dialog.html
orientationcommon.js
progressserver.sjs
responseIdentical.sjs
script-1_bug597345.sjs
@ -314,6 +317,14 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Fails on b2g-desktop, track
[test_pluginAudioNotification.html]
skip-if = (buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android') # Plugins don't work on Android and/or B2G/Mulet
[test_screen_orientation.html]
[test_orientation_alternate.html]
skip-if = toolkit != 'gonk'
[test_orientation_frame.html]
skip-if = toolkit != 'gonk'
[test_orientation_frame_lock.html]
skip-if = toolkit != 'gonk'
[test_orientation_sandbox_no_lock.html]
skip-if = toolkit != 'gonk'
[test_settimeout_extra_arguments.html]
[test_settimeout_inner.html]
[test_setting_opener.html]

Просмотреть файл

@ -0,0 +1,21 @@
function specialPowersLock(orientation) {
return new Promise(function(resolve, reject) {
SpecialPowers.pushPrefEnv({
'set': [ ["dom.screenorientation.testing.non_fullscreen_lock_allow", true] ]
}, function() {
var p = screen.orientation.lock(orientation);
resolve(p);
});
});
}
function specialPowersUnlock() {
return new Promise(function(resolve, reject) {
SpecialPowers.pushPrefEnv({
'set': [ ["dom.screenorientation.testing.non_fullscreen_lock_allow", true] ]
}, function() {
screen.orientation.unlock();
resolve();
});
});
}

Просмотреть файл

@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for ScreenOrientation API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="orientationcommon.js"></script>
<div id="log"></div>
<script>
async_test(function(t) {
var originalOrientation = screen.orientation.type;
var alternateOrientation = originalOrientation == "portrait-primary" ?
"landscape-primary" : "portrait-primary";
var p = specialPowersLock(alternateOrientation);
p.then(function() {
t.step(function() { assert_equals(screen.orientation.type, alternateOrientation); });
return specialPowersLock(originalOrientation);
}).then(function() {
t.step(function() { assert_equals(screen.orientation.type, originalOrientation); });
return specialPowersUnlock();
}).then(function() {
t.done();
}).catch(t.step_func(function(err) {
assert_unreached("Error setting orientation: " + err);
t.done();
}));
}, "Test locking and unlocking orientation.");
</script>

Просмотреть файл

@ -0,0 +1,37 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for ScreenOrientation API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="orientationcommon.js"></script>
<div id="log"></div>
<iframe id="frame"></iframe>
<script>
async_test(function(t) {
var originalOrientation = screen.orientation.type;
var alternateOrientation = originalOrientation == "portrait-primary" ?
"landscape-primary" : "portrait-primary";
window.addEventListener("message", function(event) {
t.step(function() { assert_array_equals(event.data, [alternateOrientation, originalOrientation]); });
t.done();
}, false);
var frame = document.getElementById("frame");
frame.src = "file_record_orientation.html";
frame.onload = function() {
var p = specialPowersLock(alternateOrientation);
p.then(function() {
return specialPowersLock(originalOrientation);
}).then(function() {
return specialPowersUnlock();
}).then(function() {
frame.contentWindow.postMessage("report", "*");
}).catch(t.step_func(function(err) {
assert_unreached("Error setting orientation: " + err);
t.done();
}));
};
}, "Test orientation change event in frame.");
</script>

Просмотреть файл

@ -0,0 +1,46 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for ScreenOrientation API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="orientationcommon.js"></script>
<div id="log"></div>
<iframe sandbox="allow-scripts allow-orientation-lock" id="frame"></iframe>
<script>
async_test(function(t) {
var originalOrientation = screen.orientation.type;
var alternateOrientation = originalOrientation == "portrait-primary" ?
"landscape-primary" : "portrait-primary";
var orientationChanges = [];
window.screen.orientation.onchange = function() {
orientationChanges.push(screen.orientation.type);
};
window.addEventListener("message", function(event) {
t.step(function() {
assert_equals(event.data, "success");
assert_array_equals(orientationChanges, [ alternateOrientation ]);
});
// Return the orientation to its original settings.
var p = specialPowersLock(originalOrientation);
p.then(function() {
return specialPowersUnlock();
}).then(function() {
t.done();
}).catch(t.step_func(function(err) {
assert_unreached("Error setting orientation: " + err);
t.done();
}));
}, false);
var frame = document.getElementById("frame");
frame.src = "http://example.com/tests/dom/base/test/file_lock_orientation.html";
frame.onload = function() {
assert_array_equals(orientationChanges, []);
frame.contentWindow.postMessage(alternateOrientation, "*");
};
}, "Test orientation lock from within a frame with sandbox permission.");
</script>

Просмотреть файл

@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for ScreenOrientation API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="orientationcommon.js"></script>
<div id="log"></div>
<iframe sandbox="allow-scripts" id="frame"></iframe>
<script>
async_test(function(t) {
var originalOrientation = screen.orientation.type;
var alternateOrientation = originalOrientation == "portrait-primary" ?
"landscape-primary" : "portrait-primary";
var orientationChanges = [];
window.screen.orientation.onchange = function() {
orientationChanges.push(screen.orientation.type);
};
window.addEventListener("message", function(event) {
t.step(function() {
assert_equals(event.data, "error");
assert_array_equals(orientationChanges, []);
t.done();
});
}, false);
var frame = document.getElementById("frame");
frame.src = "http://example.com/tests/dom/base/test/file_lock_orientation.html";
frame.onload = function() {
assert_array_equals(orientationChanges, []);
frame.contentWindow.postMessage(alternateOrientation, "*");
};
}, "Test orientation lock from within a frame without sandbox permission.");
</script>