author Emilio Cobos Álvarez <>
Thu, 07 Mar 2019 21:27:23 +0000
changeset 520909 91fcd9232c7e64ec113afd5f9eb183939cd52110
parent 520873 536782d2357f0c83a61f1d7c5c2093c73c071532
permissions -rw-r--r--
Bug 1533392 - Fix initial font-family detection in property-database.js. r=dholbert Calling getComputedStyle on an element outside of the document always returns the empty string since bug 1511138, so we were incorrectly thinking that the initial font-family was serif when it was not. I chose a <meta> element instead of a <div> because they're undisplayed and they don't cause the <body> of the document to start (though I _think_ that only happens from the parser). In any case I'm pretty surprised this didn't cause issues in other tests... Differential Revision:

<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 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) {, "initial");
  const initial = computedValue(node, property);;
  return initial;

function testResetProperty(property, info) {, 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);, "revert");
  const reverted = computedValue(div, property);
  is(reverted, defaultValue, `${property}: Should behave as if there was no author style`);;;

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")

  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})`);, "revert");
  const reverted = computedValue(div, property);
  if (hasUARule)
    is(reverted, defaultValue, `${property}: Should behave as if there was no author style`);
    is(reverted, inheritedValue, `${property}: Should behave as if there was no author style`);;

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

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

for (const prop in gCSSProperties)
  testProperty(prop, gCSSProperties[prop]);