Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MathML: Add tests for margin-collapsing. #18170

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mathml/relations/css-styling/padding-border-margin/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ function measureSpaceAround(id) {
return spaceBetween(childBox, parentBox);
}

function compareSpaceWithAndWithoutStyle(tag, style) {
function compareSpaceWithAndWithoutStyle(tag, style, parentStyle) {
if (!FragmentHelper.isValidChildOfMrow(tag) ||
FragmentHelper.isEmpty(tag))
throw `Invalid argument: ${tag}`;

document.body.insertAdjacentHTML("beforeend", `<div>\
<math>${MathMLFragments[tag]}</math>\
<math>${MathMLFragments[tag]}</math>\
<math><mrow>${MathMLFragments[tag]}</mrow></math>\
<math><mrow>${MathMLFragments[tag]}</mrow></math>\
</div>`);
var div = document.body.lastElementChild;

var styleMath = div.firstElementChild;
var styleParent = styleMath.firstElementChild;
if (parentStyle)
styleParent.setAttribute("style", parentStyle);
var styleElement = FragmentHelper.element(styleMath);
styleElement.setAttribute("style", style);
var styleChild = FragmentHelper.forceNonEmptyElement(styleElement);
Expand Down
12 changes: 12 additions & 0 deletions mathml/relations/css-styling/padding-border-margin/margin-002.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
assert_approx_equals(s.element_width_delta, 0, epsilon, "element width");
assert_approx_equals(s.element_height_delta, 0, epsilon, "element height");
}, `Margin properties on ${tag} (rtl)`);

test(function() {
// Apply the same margin style on the parent mrow.
// The margins are not collapsed so they should be added twice.
var s = compareSpaceWithAndWithoutStyle(tag, style, style);
assert_approx_equals(s.left_delta, 30 * 2, epsilon, "left margin");
assert_approx_equals(s.right_delta, 40 * 2, epsilon, "right margin");
assert_approx_equals(s.top_delta, 50 * 2, epsilon, "top margin");
assert_approx_equals(s.bottom_delta, 60 * 2, epsilon, "bottom margin");
assert_approx_equals(s.element_width_delta, 0, epsilon, "element width");
assert_approx_equals(s.element_height_delta, 0, epsilon, "element height");
}, `Margin properties on ${tag} (no margin-collapsing)`);
}

done();
Expand Down