2013-12-12 06:09:47 +04:00
|
|
|
<!DOCTYPE type>
|
|
|
|
<title>Assorted CSS variable tests</title>
|
|
|
|
<script src="/MochiKit/MochiKit.js"></script>
|
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" href="/tests/SimpleTest/test.css" type="text/css">
|
|
|
|
|
|
|
|
<style id="test1">
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style id="test2">
|
|
|
|
</style>
|
|
|
|
|
2014-01-02 09:33:57 +04:00
|
|
|
<style id="test3">
|
|
|
|
</style>
|
|
|
|
|
2014-03-05 05:29:44 +04:00
|
|
|
<style id="test4">
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div id="t4"></div>
|
|
|
|
|
2014-07-25 10:14:33 +04:00
|
|
|
<style id="test5">
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div id="t5"></div>
|
|
|
|
|
2015-02-24 21:35:30 +03:00
|
|
|
<style id="test6">
|
|
|
|
</style>
|
|
|
|
|
2015-04-24 20:15:00 +03:00
|
|
|
<style id="test7">
|
|
|
|
</style>
|
|
|
|
|
2013-12-12 06:09:47 +04:00
|
|
|
<script>
|
|
|
|
var tests = [
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=773296#c121
|
2014-02-10 04:56:35 +04:00
|
|
|
var test1 = document.getElementById("test1");
|
2014-04-02 07:32:16 +04:00
|
|
|
test1.textContent = "p { --a:123!important; }";
|
2014-02-10 04:56:35 +04:00
|
|
|
var declaration = test1.sheet.cssRules[0].style;
|
2013-12-12 06:09:47 +04:00
|
|
|
declaration.cssText;
|
|
|
|
declaration.setProperty("color", "black");
|
2014-04-02 07:32:16 +04:00
|
|
|
is(declaration.getPropertyValue("--a"), "123");
|
2013-12-12 06:09:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=773296#c121
|
2014-02-10 04:56:35 +04:00
|
|
|
var test2 = document.getElementById("test2");
|
2014-04-02 07:32:16 +04:00
|
|
|
test2.textContent = "p { --a: a !important; }";
|
2014-02-10 04:56:35 +04:00
|
|
|
var declaration = test2.sheet.cssRules[0].style;
|
2014-04-02 07:32:16 +04:00
|
|
|
is(declaration.getPropertyPriority("--a"), "important");
|
2013-12-12 06:09:47 +04:00
|
|
|
},
|
2014-01-02 09:33:57 +04:00
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=955913
|
2014-02-10 04:56:35 +04:00
|
|
|
var test3 = document.getElementById("test3");
|
2014-04-02 07:32:16 +04:00
|
|
|
test3.textContent = "p { border-left-style: inset; padding: 1px; --decoration: line-through; }";
|
2014-02-10 04:56:35 +04:00
|
|
|
var declaration = test3.sheet.cssRules[0].style;
|
2014-04-02 07:32:16 +04:00
|
|
|
is(declaration[declaration.length - 1], "--decoration");
|
2014-01-02 09:33:57 +04:00
|
|
|
},
|
2014-03-05 05:29:44 +04:00
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=959973
|
|
|
|
var test4 = document.getElementById("test4");
|
2014-04-02 07:32:16 +04:00
|
|
|
test4.textContent = "#t4 { background-image: var(--a); }";
|
2014-03-05 05:29:44 +04:00
|
|
|
|
|
|
|
var element = document.getElementById("t4");
|
|
|
|
var path = window.location.pathname;
|
|
|
|
var currentDir = path.substring(0, path.lastIndexOf('/'));
|
|
|
|
var imageURL = "http://mochi.test:8888" + currentDir + "/image.png";
|
|
|
|
|
|
|
|
is(window.getComputedStyle(element).getPropertyValue("background-image"), "url(\"" + imageURL +"\")");
|
|
|
|
},
|
2014-07-25 10:14:33 +04:00
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1043713
|
|
|
|
var test5 = document.getElementById("test5");
|
|
|
|
test5.textContent = "#t5 { --SomeVariableName: a; }";
|
|
|
|
|
|
|
|
var declaration = test5.sheet.cssRules[0].style;
|
|
|
|
is(declaration.item(0), "--SomeVariableName", "custom property name returned by item() on style declaration");
|
|
|
|
is(declaration[0], "--SomeVariableName", "custom property name returned by indexed getter on style declaration");
|
|
|
|
|
|
|
|
var element = document.getElementById("t5");
|
|
|
|
var cs = window.getComputedStyle(element);
|
|
|
|
|
|
|
|
is(cs.item(cs.length - 1), "--SomeVariableName", "custom property name returned by item() on computed style");
|
|
|
|
is(cs[cs.length - 1], "--SomeVariableName", "custom property name returned by indexed getter on style declaration");
|
|
|
|
},
|
2015-02-24 21:35:30 +03:00
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=969756
|
|
|
|
var test6 = document.getElementById("test6");
|
|
|
|
test6.textContent = "p { font: var(--var6) hangul mongolian; font-size-adjust: none; }";
|
|
|
|
var declaration = test6.sheet.cssRules[0].style;
|
|
|
|
test6.style.color = "white";
|
|
|
|
is(declaration.getPropertyValue("-x-system-font"), " var(--var6) hangul mongolian");
|
|
|
|
},
|
2015-04-24 20:15:00 +03:00
|
|
|
|
|
|
|
function() {
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1154356
|
|
|
|
var test7 = document.getElementById("test7");
|
|
|
|
test7.textContent = "p { --weird\\;name: green; }";
|
|
|
|
is(test7.sheet.cssRules[0].style.cssText, "--weird\\;name: green;");
|
|
|
|
test7.textContent = "p { --0: green; }";
|
|
|
|
is(test7.sheet.cssRules[0].style.cssText, "--0: green;");
|
|
|
|
},
|
2013-12-12 06:09:47 +04:00
|
|
|
];
|
|
|
|
|
2014-03-05 05:29:44 +04:00
|
|
|
function prepareTest() {
|
|
|
|
// Load an external style sheet for test 4.
|
|
|
|
var e = document.createElement("link");
|
|
|
|
e.addEventListener("load", runTest);
|
|
|
|
e.setAttribute("rel", "stylesheet");
|
|
|
|
e.setAttribute("href", "support/external-variable-url.css");
|
|
|
|
document.head.appendChild(e);
|
|
|
|
}
|
|
|
|
|
2014-02-10 04:56:35 +04:00
|
|
|
function runTest() {
|
|
|
|
tests.forEach(function(fn) { fn(); });
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPrefEnv({ set: [["layout.css.variables.enabled", true ]] },
|
2014-03-05 05:29:44 +04:00
|
|
|
prepareTest);
|
2013-12-12 06:09:47 +04:00
|
|
|
</script>
|