gecko-dev/dom/html/test/file_fullscreen-ancestor-st...

141 строка
5.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1056203
-->
<head>
<title>Test for Bug 1056203</title>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1056203">Mozilla Bug 1056203</a>
<p id="display">
<div id="grandparent">
<div id="parent">
<div id="fullscreenElem">
<div id="child"></div>
</div>
</div>
</div>
</p>
<pre id="test">
<script type="application/javascript;version=1.7">
/** Test for Bug 1056203 **/
/* This test ensures that the ancestors of a full-screened element cannot be
restyled to create a stacking context, even with !important. */
/* NOTE: The following hash should include each of the properties from
layout/style/full-screen-override.css (except that this list uses the DOM
versions of the property names -- e.g. "zIndex" instead of "z-index").
Both lists should include every property that is able to induce an element
to form a stacking context. */
const gPropertyTestDecls = {
//"domPropName": "prop-name: some-non-initial-value",
"zIndex": "z-index: 5",
"opacity": "opacity: 0.8",
"mask": "mask: url(#mymask)",
"clip": "clip: rect(0 0 0 0)",
"clipPath": "clip-path: url(#mypath)",
"filter": "filter: url(#myfilter)",
"transform": "transform: translate(0)",
// XXXdholbert The "will-change" line in full-screen-override.css is only
// parsed and honored if "layout.css.will-change.enabled" is turned on
// *at startup time* (so, flipping it here with SpecialPowers wouldn't be
// sufficient). So, we won't get the right behavior for 'will-change' here
// until it's enabled by default (bug 961871). This line can be uncommented
// when that happens:
// "willChange": "will-change: transform"
};
// populated in populateInitialVals
let gPropertyInitialVals = {};
function begin() {
populateInitialVals();
// FIRST: Assert that the properties in gPropertyTestDecls can be set
// on each of our tested elements, before we enter full-screen mode.
var timeDescrip = "not yet fullscreen";
testPropertiesOnElem("grandparent", true);
testPropertiesOnElem("parent", true);
testPropertiesOnElem("fullscreenElem", true);
testPropertiesOnElem("child", true);
document.addEventListener("mozfullscreenchange", handleFullscreen, false);
fullscreenElem.mozRequestFullScreen();
}
function handleFullscreen(e) {
opener.ok(document.mozFullScreen, "should've entered full-screen mode");
// SECOND: Assert that the properties in gPropertyTestDecls can *NOT* be
// set (their decls have no effect) on ancestors of the full-screen elem.
testPropertiesOnElem("parent", false);
testPropertiesOnElem("grandparent", false);
testPropertiesOnElem("fullscreenElem", true);
testPropertiesOnElem("child", true);
// Un-register listener, so we aren't re-triggered when document is torn
// down & taken out of full-screen mode:
document.removeEventListener("mozfullscreenchange", handleFullscreen);
// We're done! On to the next test:
opener.nextTest();
};
// Populates gPropertyTestDecls with the initial values of each property
// in gPropertyTestDecls (based on document.documentElement's computed style)
function populateInitialVals() {
// We'll read the initial values off of document.documentElement.
let cs = window.getComputedStyle(document.documentElement, "");
for (propName in gPropertyTestDecls) {
opener.ok(propName in cs,
"property '" + propName + "' used in this test should " +
"exist in computed style");
gPropertyInitialVals[propName] = cs[propName];
}
}
// For the element with id |elemId|, this method asserts that the property
// decls in gPropertyTestDecls either *do* or *do not* have an effect on the
// element's computed style, depending on the argument |isPropertyModifyable|.
// The decls are tested both with & without "!important".
function testPropertiesOnElem(elemId, isPropertyModifyable) {
const elem = document.getElementById(elemId);
opener.ok(elem, "expecting to find element with ID '" + elemId + "'");
const testFunc = isPropertyModifyable ? opener.isnot : opener.is;
for (propName in gPropertyTestDecls) {
let msg = elemId + ".style." + propName +" should ";
if (!isPropertyModifyable) {
msg += "NOT ";
}
msg += "be allowed to change away from initial value, ";
msg += document.mozFullScreen ? "after" : "before";
msg += " entering full-screen mode";
let decl = gPropertyTestDecls[propName];
// See if the test decl has any effect on computed style:
elem.setAttribute("style", decl);
testFunc(window.getComputedStyle(elem, "")[propName],
gPropertyInitialVals[propName],
msg);
// See if the test decl has any effect on computed style, w/ "!important":
elem.setAttribute("style", decl + " !important");
testFunc(window.getComputedStyle(elem, "")[propName],
gPropertyInitialVals[propName],
msg + " (with !important)");
elem.removeAttribute("style"); // clean up
}
}
</script>
</pre>
</body>
</html>