5 function assert_initial(property, initial) {
7 const target = document.getElementById('target');
8 if (!getComputedStyle(target)[property])
10 target.style[property] = 'initial';
11 assert_equals(getComputedStyle(target)[property], initial);
12 target.style[property] = '';
13 }, 'Property ' + property + ' has initial value ' + initial);
17 * Create tests that a CSS property inherits and has the given initial value.
19 * The current document must have an element #target within element #container.
21 * @param {string} property The name of the CSS property being tested.
22 * @param {string} initial The computed value for 'initial'.
23 * @param {string} other An arbitrary value for the property that round
24 * trips and is distinct from the initial value.
26 function assert_inherited(property, initial, other) {
27 assert_initial(property, initial);
30 const container = document.getElementById('container');
31 const target = document.getElementById('target');
32 if (!getComputedStyle(target)[property])
34 container.style[property] = 'initial';
35 target.style[property] = 'unset';
36 assert_not_equals(getComputedStyle(container)[property], other);
37 assert_not_equals(getComputedStyle(target)[property], other);
38 container.style[property] = other;
39 assert_equals(getComputedStyle(container)[property], other);
40 assert_equals(getComputedStyle(target)[property], other);
41 target.style[property] = 'initial';
42 assert_equals(getComputedStyle(container)[property], other);
43 assert_not_equals(getComputedStyle(target)[property], other);
44 target.style[property] = 'inherit';
45 assert_equals(getComputedStyle(target)[property], other);
46 container.style[property] = '';
47 target.style[property] = '';
48 }, 'Property ' + property + ' inherits');
52 * Create tests that a CSS property does not inherit, and that it has the
53 * given initial value.
55 * The current document must have an element #target within element #container.
57 * @param {string} property The name of the CSS property being tested.
58 * @param {string} initial The computed value for 'initial'.
59 * @param {string} other An arbitrary value for the property that round
60 * trips and is distinct from the initial value.
62 function assert_not_inherited(property, initial, other) {
63 assert_initial(property, initial);
66 const container = document.getElementById('container');
67 const target = document.getElementById('target');
68 if (!getComputedStyle(target)[property])
70 container.style[property] = 'initial';
71 target.style[property] = 'unset';
72 assert_not_equals(getComputedStyle(container)[property], other);
73 assert_not_equals(getComputedStyle(target)[property], other);
74 container.style[property] = other;
75 assert_equals(getComputedStyle(container)[property], other);
76 assert_not_equals(getComputedStyle(target)[property], other);
77 target.style[property] = 'inherit';
78 assert_equals(getComputedStyle(target)[property], other);
79 container.style[property] = '';
80 target.style[property] = '';
81 }, 'Property ' + property + ' does not inherit');
84 window.assert_inherited = assert_inherited;
85 window.assert_not_inherited = assert_not_inherited;