1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_compute_data_with_start_struct.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for correct handling of aStartStruct parameter to nsRuleNode::Compute*Data</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="property_database.js"></script> 1.10 + <style type="text/css" id="stylesheet"></style> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.12 +</head> 1.13 +<body> 1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=216456">Mozilla Bug 216456</a> 1.15 +<p id="display"> 1.16 + <span id="base"></span> 1.17 + <span id="test"></span> 1.18 +</p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +/** 1.26 + * The purpose of this test is to test that nsRuleNode::Compute*Data 1.27 + * functions are written correctly. In particular, in these functions, 1.28 + * when the specified value of a property has unit eCSSUnit_Null, 1.29 + * touching the computed data is forbidden. This is because we 1.30 + * sometimes stop walking up the rule tree when we find computed data 1.31 + * for an initial subsequence of our rules (i.e., an ancestor rule node) 1.32 + * that we can use as a starting point (aStartStruct) for the 1.33 + * computation for the current rule node. 1.34 + * 1.35 + * If one of these tests fails, you should look for a case where the 1.36 + * property's code in nsRuleNode::Compute*Data touches the computed 1.37 + * value when the specified value has eCSSUnit_Null, and fix it. 1.38 + * 1.39 + * The test works by maintaining one style rule that has every CSS 1.40 + * property specified, and a second style rule that has different values 1.41 + * for every property, an element that matches only the first rule (so 1.42 + * that we'll have a cached struct), and *later* an element that matches 1.43 + * both rules (for whose computation we'll find the struct cached from 1.44 + * the first element). (It does this twice, once with the overriding in 1.45 + * each direction, because one of the cases might match the incorrect 1.46 + * overwriting.) Then, in the second style rule, it unsets each 1.47 + * property, one at a time, and checks that the computation works 1.48 + * correctly. (The reason to want every property set is to hit a case 1.49 + * where we can store the data in the rule tree... though this isn't 1.50 + * guaranteed.) 1.51 + */ 1.52 + 1.53 +function xfail_computecheck(prop, roundnum) { 1.54 + return false; 1.55 +} 1.56 + 1.57 +function xfail_test(prop, roundnum) { 1.58 + return false; 1.59 +} 1.60 + 1.61 +var gStyleSheet = document.getElementById("stylesheet").sheet; 1.62 +var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#base, #test {}", gStyleSheet.cssRules.length)]; 1.63 +var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#test {}", gStyleSheet.cssRules.length)]; 1.64 + 1.65 +var gBase = getComputedStyle(document.getElementById("base"), ""); 1.66 +var gTest = getComputedStyle(document.getElementById("test"), ""); 1.67 + 1.68 +function round(lower_set, higher_set, roundnum) { 1.69 + 1.70 + for (var prop in gCSSProperties) { 1.71 + var info = gCSSProperties[prop]; 1.72 + if (info.backend_only || info.subproperties || info.get_computed) 1.73 + continue; 1.74 + gRule1.style.setProperty(prop, info[lower_set][0], ""); 1.75 + gRule2.style.setProperty(prop, info[higher_set][0], ""); 1.76 + } 1.77 + 1.78 + for (var prop in gCSSProperties) { 1.79 + var info = gCSSProperties[prop]; 1.80 + if (info.backend_only || info.subproperties || info.get_computed) 1.81 + continue; 1.82 + 1.83 + if ("prerequisites" in info) { 1.84 + for (var prereq in info.prerequisites) { 1.85 + gRule2.style.setProperty(prereq, info.prerequisites[prereq], ""); 1.86 + } 1.87 + } 1.88 + 1.89 + gBase.getPropertyValue(prop); 1.90 + var higher_set_val = gTest.getPropertyValue(prop); 1.91 + gRule2.style.setProperty(prop, info[lower_set][0], ""); 1.92 + var lower_set_val = gTest.getPropertyValue(prop); 1.93 + (xfail_computecheck(prop, roundnum) ? todo_isnot : isnot)(higher_set_val, lower_set_val, "initial and other values of " + prop + " are different"); 1.94 + gRule2.style.removeProperty(prop); 1.95 + (xfail_test(prop, roundnum) ? todo_is : is)(gTest.getPropertyValue(prop), lower_set_val, prop + " is not touched when its value comes from aStartStruct"); 1.96 + 1.97 + gRule2.style.setProperty(prop, info[higher_set][0], ""); 1.98 + if ("prerequisites" in info) { 1.99 + for (var prereq in info.prerequisites) { 1.100 + gRule2.style.setProperty(prereq, gCSSProperties[prereq][higher_set][0], ""); 1.101 + } 1.102 + } 1.103 + } 1.104 +} 1.105 + 1.106 +round("other_values", "initial_values", 1); 1.107 +round("initial_values", "other_values", 2); 1.108 + 1.109 +</script> 1.110 +</pre> 1.111 +</body> 1.112 +</html>