Bug 1363805 - Part 5: Add testcase for restyle generation. r?heycam draft
authorWei-Cheng Pan <wpan@mozilla.com>
Tue, 12 Sep 2017 18:17:18 +0800
changeset 669670 c6926790898a0ce8bfc9f25f0987bbc356cdd3fe
parent 669669 9a61280ff3243ecd3dfc2625c95df7e4301db9e6
child 733016 47cd65add2a1fac565282539a9c9fe92d772bf12
push id81392
push userbmo:wpan@mozilla.com
push dateMon, 25 Sep 2017 07:20:33 +0000
reviewersheycam
bugs1363805
milestone58.0a1
Bug 1363805 - Part 5: Add testcase for restyle generation. r?heycam Make sure we restyle only if we have to. MozReview-Commit-ID: 6yuyxH4GInJ
layout/style/test/mochitest.ini
layout/style/test/test_computed_style_no_flush.html
--- 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>