blob: 38f2d42009e93c4a939323d720396d91d65e6d44 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description("Tests that trying to set an event listener for deviceorientation and deviceorientation logs an error in non-secure contexts.");
jsTestIsAsync = true;
// localhost is secure by default.
internals.markContextAsInsecure();
let lastConsoleMessage = null;
internals.setConsoleMessageListener((message) => {
lastConsoleMessage = message;
});
function runDeviceMotionTest()
{
if (!window.DeviceMotionEvent) {
console.log("Device Motion API is not supported");
finishJSTest();
return;
}
lastConsoleMessage = null;
debug("");
debug("* Registering device motion listener");
addEventListener("devicemotion", function() { });
internals.postTask(() => {
shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.");
finishJSTest();
});
}
function runDeviceOrientationTest()
{
if (!window.DeviceOrientationEvent) {
console.log("Device Orientation API is not supported");
runDeviceMotionTest();
return;
}
lastConsoleMessage = null;
debug("* Registering device orientation listener");
addEventListener("deviceorientation", function() { });
internals.postTask(() => {
shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.");
runDeviceMotionTest();
});
}
onload = runDeviceOrientationTest;
</script>
</body>
</html>