DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>Test for computation of values in property database</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="property_database.js"></script>
  <style type="text/css" id="stylesheet"></style>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript">
  SimpleTest.waitForExplicitFinish();

  var load_count = 0;
  function load_done() {
    if (++load_count == 3)
      run_tests();
  }
  </script>
</head>
<body>
<p id="display"><span><span id="elementf"></span></span>
<iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe>
<iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe>
</p>
<div id="content" style="display: none">

<div><span id="elementn"></span></div>

  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for computation of values in property database **/

var gNotAccepted = {
  "-moz-column-width": [ "50%" ],
  "-moz-user-select": [ "auto" ],
  "list-style": [ "none disc outside" ],
};

var gBadComputed = {
  // NS_STYLE_COLUMN_COUNT_AUTO is 0
  "-moz-column-count": [ "0" ],

  "clip": [ "rect(auto,auto,auto,auto)" ],

  // No idea what's happening for these two either
  "border-top": [ "thin" ],
  "border-right": [ "thin" ],
  "border-bottom": [ "thin" ],
  "border-left": [ "thin" ],
  "-moz-border-start": [ "thin" ],
  "-moz-border-end": [ "thin" ],
  "outline-width": [ "3px" ],

  // 'normal' should compute to 0
  "word-spacing": [ "0", "0px", "-0em" ],

  // These values are treated as auto.
  "page-break-after": [ "avoid" ],
  "page-break-before": [ "avoid" ],

  // These are probably bogus tests...
  "-moz-outline-radius": [ "0%" ],
  "-moz-outline-radius-bottomleft": [ "0%" ],
  "-moz-outline-radius-bottomright": [ "0%" ],
  "-moz-outline-radius-topleft": [ "0%" ],
  "-moz-outline-radius-topright": [ "0%" ],
  // These are probably bogus tests... (why not just when no frame?)
  "-moz-margin-end": [ "0%" ],
  "-moz-margin-start": [ "0%" ],
  "-moz-padding-end": [ "0%" ],
  "-moz-padding-start": [ "0%" ],
};

var gBadComputedNoFrame = {
  // These are probably bogus tests...
  "margin": [ "0% 0px 0em 0pt" ],
  "margin-bottom": [ "0%" ],
  "margin-left": [ "0%" ],
  "margin-right": [ "0%" ],
  "margin-top": [ "0%" ],
  "padding": [ "0% 0px 0em 0pt" ],
  "padding-bottom": [ "0%" ],
  "padding-left": [ "0%" ],
  "padding-right": [ "0%" ],
  "padding-top": [ "0%" ],
};

function xfail_value(property, value, is_initial, has_frame) {
  if ((property in gNotAccepted) &&
      gNotAccepted[property].indexOf(value) != -1)
    return true;

  if ((property in gBadComputed) &&
      gBadComputed[property].indexOf(value) != -1)
    return true;

  if (!has_frame && (property in gBadComputedNoFrame) &&
      gBadComputedNoFrame[property].indexOf(value) != -1)
    return true;

  return false;
}

var gElementN = document.getElementById("elementn");
var gElementF = document.getElementById("elementf");
var gStyleSheet = document.getElementById("stylesheet").sheet;
var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];

var gInitialValuesN;
var gInitialValuesF;
var gInitialPrereqsRuleN;
var gInitialPrereqsRuleF;

function setup_initial_values(id, ivalprop, prereqprop) {
  var iframe = document.getElementById(id);
  window[ivalprop] = iframe.contentWindow.getComputedStyle(
                       iframe.contentDocument.documentElement.firstChild, "");
  var sheet = iframe.contentDocument.styleSheets[0];
  window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
}

function test_value(property, val, is_initial)
{
  var info = gCSSProperties[property];
  if (info.backend_only)
    return;

  if ("prerequisites" in info) {
    var prereqs = info.prerequisites;
    for (var prereq in prereqs) {
      gRule1.style.setProperty(prereq, prereqs[prereq], "");
      gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], "");
      gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], "");
    }
  }
  if (info.inherited && is_initial) {
    gElementN.parentNode.style.setProperty(property, info.other_values[0], "");
    gElementF.parentNode.style.setProperty(property, info.other_values[0], "");
  }

  var initial_computed_n = get_computed_value(gInitialValuesN, property);
  var initial_computed_f = get_computed_value(gInitialValuesF, property);
  if (is_initial) {
    gRule1.style.setProperty(property, info.other_values[0], "");
    var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
    var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
    isnot(other_computed_n, initial_computed_n,
          "should be testing with values that compute to different things " +
          "for '" + property + "'");
    isnot(other_computed_f, initial_computed_f,
          "should be testing with values that compute to different things " +
          "for '" + property + "'");
  }
  // It's important for values that are supposed to compute to the
  // initial value (given the current design of nsRuleNode) that we're
  // modifying the most specific rule that matches the element, and that
  // we've already requested style while that rule was empty.  This
  // means we'll have a cached aStartStruct from the parent in the rule
  // tree (caching the "other" value), so we'll make sure we don't get
  // the initial value from the luck of default-initialization.
  // This means that it's important that we set the prereqs on
  // gRule1.style rather than on gElement.style.
  gRule2.style.setProperty(property, val, "");
  var val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
  var val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
  isnot(val_computed_n, "",
        "should not get empty value for '" + property + ":" + val + "'");
  isnot(val_computed_f, "",
        "should not get empty value for '" + property + ":" + val + "'");
  if (is_initial) {
    (xfail_value(property, val, is_initial, false) ? todo_is : is)(
       val_computed_n, initial_computed_n,
       "should get initial value for '" + property + ":" + val + "'");
    (xfail_value(property, val, is_initial, true) ? todo_is : is)(
       val_computed_f, initial_computed_f,
       "should get initial value for '" + property + ":" + val + "'");
  } else {
    (xfail_value(property, val, is_initial, false) ? todo_isnot : isnot)(
       val_computed_n, initial_computed_n,
       "should not get initial value for '" + property + ":" + val + "' on elementn.");
    (xfail_value(property, val, is_initial, true) ? todo_isnot : isnot)(
       val_computed_f, initial_computed_f,
       "should not get initial value for '" + property + ":" + val + "' on elementf.");
  }
  if (is_initial)
    gRule1.style.removeProperty(property);
  gRule2.style.removeProperty(property);

  if ("prerequisites" in info) {
    var prereqs = info.prerequisites;
    for (var prereq in prereqs) {
      gRule1.style.removeProperty(prereq);
      gInitialPrereqsRuleN.style.removeProperty(prereq);
      gInitialPrereqsRuleF.style.removeProperty(prereq);
    }
  }
  if (info.inherited && is_initial) {
    gElementN.parentNode.style.removeProperty(property);
    gElementF.parentNode.style.removeProperty(property);
  }
}

function test_property(prop) {
  var info = gCSSProperties[prop];
  for (var idx in info.initial_values)
    test_value(prop, info.initial_values[idx], true);
  for (var idx in info.other_values)
    test_value(prop, info.other_values[idx], false);
}

function run_tests() {
  setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN");
  setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF");
  var props = [];
  for (var prop in gCSSProperties)
    props.push(prop);
  props = props.reverse();
  function do_one(l) {
    if (l.length == 0) {
      // SimpleTest.finish() is really slow, so we have to disable the
      // slow script dialog for this part
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
      var prefService = Components.classes["@mozilla.org/preferences-service;1"].
                          getService(Components.interfaces.nsIPrefService);
      var domBranch = prefService.getBranch("dom.");
      var oldVal = domBranch.getIntPref("max_script_run_time");
      domBranch.setIntPref("max_script_run_time", 0);

      SimpleTest.finish();

      domBranch.setIntPref("max_script_run_time", oldVal);

      return;
    }
    test_property(l.pop());
    setTimeout(do_one, 0, l);
  }
  setTimeout(do_one, 0, props);
}

load_done();

</script>
</pre>
</body>
</html>