Bug 1363805 - Part 5: Add testcase for restyle generation. r?heycam
Make sure we restyle only if we have to.
MozReview-Commit-ID: 6yuyxH4GInJ
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -171,16 +171,18 @@ skip-if = !stylo # This is a stylo test;
[test_clip-path_polygon.html]
[test_color_rounding.html]
[test_compute_data_with_start_struct.html]
skip-if = toolkit == 'android'
[test_computed_style.html]
[test_computed_style_bfcache_display_none.html]
[test_computed_style_in_created_document.html]
[test_computed_style_min_size_auto.html]
+[test_computed_style_no_flush.html]
+skip-if = !stylo # gecko will fail without some hack, see bug 1401857
[test_computed_style_no_pseudo.html]
[test_computed_style_prefs.html]
[test_condition_text.html]
[test_condition_text_assignment.html]
[test_contain_formatting_context.html]
[test_counter_descriptor_storage.html]
[test_counter_style.html]
[test_crash_with_content_policy.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_computed_style_no_flush.html
@@ -0,0 +1,63 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>
+ Test for bug 1363805: We only restyle as little as needed
+</title>
+<link rel="author" href="mailto:wpan@mozilla.com" title="Wei-Cheng Pan">
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<style>
+.black {
+ background-color: black;
+}
+.black + div {
+ background-color: gray;
+}
+</style>
+<div id="container">
+ <div>
+ <div id="foo">
+ </div>
+ <div id="bar">
+ </div>
+ </div>
+</div>
+<script>
+function flushStyle () {
+ getComputedStyle(document.body).width;
+}
+
+SimpleTest.waitForExplicitFinish();
+const utils = SpecialPowers.getDOMWindowUtils(window);
+const container = document.querySelector('#container');
+const foo = document.querySelector('#foo');
+const bar = document.querySelector('#bar');
+
+flushStyle();
+let currentRestyleGeneration = utils.restyleGeneration;
+
+// No style changed, so we should not restyle.
+getComputedStyle(foo).backgroundColor;
+is(utils.restyleGeneration, currentRestyleGeneration,
+ "Shouldn't restyle anything if no style changed");
+
+// foo's parent has changed, must restyle.
+container.classList.toggle('black');
+getComputedStyle(foo).backgroundColor;
+isnot(utils.restyleGeneration, currentRestyleGeneration,
+ "Should have restyled something");
+
+currentRestyleGeneration = utils.restyleGeneration;
+
+// The change of foo should not affect its parent.
+foo.classList.toggle('black');
+getComputedStyle(container).backgroundColor;
+is(utils.restyleGeneration, currentRestyleGeneration,
+ "Shouldn't restyle anything if no style changed");
+
+// It should restyle for foo's later sibling.
+getComputedStyle(bar).backgroundColor;
+isnot(utils.restyleGeneration, currentRestyleGeneration,
+ "Should have restyled something");
+
+SimpleTest.finish();
+</script>