File: test_revert.html

package info (click to toggle)
firefox 147.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,320 kB
  • sloc: cpp: 7,607,359; javascript: 6,533,295; ansic: 3,775,223; python: 1,415,500; xml: 634,561; asm: 438,949; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (103 lines) | stat: -rw-r--r-- 4,107 bytes parent folder | download | duplicates (27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE HTML>
<title>Test for computation of CSS 'revert' on all properties</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="property_database.js"></script>
<style id="stylesheet"></style>
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
<div id="inheritanceParent">
  <div id="inherited"></div>
</div>
<div id="nonInherited"></div>
<div id="noAuthorStyleApplied"></div>
<pre id="test">
<script class="testbody">

const kSheet = document.getElementById("stylesheet").sheet;
const kAllDifferentFromInitialRule = kSheet.cssRules[kSheet.insertRule("#inheritanceParent {}", kSheet.cssRules.length)];
const kPrerequisites = kSheet.cssRules[kSheet.insertRule("#inherited, #inheritanceParent, #nonInherited, #noAuthorStyleApplied {}", kSheet.cssRules.length)];
const kResetPropRule = kSheet.cssRules[kSheet.insertRule("#nonInherited {}", kSheet.cssRules.length)];

const kInheritedDiv = document.getElementById("inherited");
const kResetDiv = document.getElementById("nonInherited");
const kNoAuthorStylesDiv = document.getElementById("noAuthorStyleApplied");

function computedValue(node, property) {
  return get_computed_value(getComputedStyle(node), property);
}

function getInitialValue(node, property) {
  node.style.setProperty(property, "initial");
  const initial = computedValue(node, property);
  node.style.removeProperty(property);
  return initial;
}

function testResetProperty(property, info) {
  kResetPropRule.style.setProperty(property, info.other_values[0]);

  const div = kResetDiv;
  const initial = getInitialValue(div, property);
  const computed = computedValue(div, property);

  isnot(computed, initial, `${property}: Should get something non-initial to begin with`);

  const defaultValue = computedValue(kNoAuthorStylesDiv, property);

  div.style.setProperty(property, "revert");
  const reverted = computedValue(div, property);
  is(reverted, defaultValue, `${property}: Should behave as if there was no author style`);
  div.style.removeProperty(property);
  kResetPropRule.style.removeProperty(property);
}

function testInheritedProperty(property, info) {
  // Given how line-height works, and that it always returns the used value, we
  // cannot test it. The prerequisites for line-height makes getComputedStyle
  // and getDefaultComputedStyle return the same, even though the computed value
  // is different (normal vs. 19px).
  if (property == "line-height")
    return;

  const div = kInheritedDiv;
  const initial = getInitialValue(div, property);
  const parentValue = computedValue(div.parentNode, property);

  isnot(parentValue, initial, `${property}: Should inherit something non-initial to begin with`);

  const inheritedValue = computedValue(div, property);
  const hasUARule = inheritedValue != parentValue;

  const defaultValue = computedValue(kNoAuthorStylesDiv, property);
  (hasUARule ? is : isnot)(defaultValue, inheritedValue, `${property}: Should get the non-inherited value from somewhere (expected ${hasUARule ? "UA Rule" : "inheritance"} - inherited: ${inheritedValue} - parent: ${parentValue} - default: ${defaultValue})`);

  div.style.setProperty(property, "revert");
  const reverted = computedValue(div, property);
  if (hasUARule)
    is(reverted, defaultValue, `${property}: Should behave as if there was no author style`);
  else
    is(reverted, inheritedValue, `${property}: Should behave as if there was no author style`);
  div.style.removeProperty(property);
}

function testProperty(property, info) {
  if (info.prerequisites)
    for (const prereq in info.prerequisites)
      kPrerequisites.style.setProperty(prereq, info.prerequisites[prereq]);
  if (info.inherited)
    testInheritedProperty(property, info);
  else
    testResetProperty(property, info);
  kPrerequisites.style = "";
}

for (const prop in gCSSProperties) {
  const info = gCSSProperties[prop];
  if (info.type != CSS_TYPE_LONGHAND)
    continue;
  kAllDifferentFromInitialRule.style.setProperty(prop, info.other_values[0]);
}

for (const prop in gCSSProperties)
  testProperty(prop, gCSSProperties[prop]);
</script>
</pre>