Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake Stylist::set_device check stylesheet media queries #14556
Conversation
highfive
commented
Dec 12, 2016
highfive
commented
Dec 12, 2016
| <title></title> | ||
| <script src="/resources/testharness.js"></script> | ||
| <script src="/resources/testharnessreport.js"></script> | ||
| <iframe id="myframe" src="iframe_for_media_queries.html" height="500px" width="500px" onLoad="func();"> |
This comment has been minimized.
This comment has been minimized.
emilio
Dec 14, 2016
Member
Func may not exist if the iframe loads too fast. It's unlikely, but please move the definition of func above.
| </style> | ||
| </head> | ||
| <body> | ||
| <h1 id="head" >Header</h1> |
This comment has been minimized.
This comment has been minimized.
| var head = document.getElementById("myframe").contentWindow.document.getElementById("head"); | ||
| var before = getComputedStyle(head).getPropertyValue("background-color"); | ||
| document.getElementById("myframe").width = "300"; | ||
| setTimeout(function () { |
This comment has been minimized.
This comment has been minimized.
| @@ -389,6 +389,7 @@ impl Stylist { | |||
| false | |||
| } | |||
| self.is_device_dirty |= stylesheets.iter().any(|stylesheet| { | |||
| stylesheet.media.read().evaluate(&self.device) || | |||
This comment has been minimized.
This comment has been minimized.
emilio
Dec 14, 2016
Member
This check is wrong, we need to check whether the media query changed, not only if it evaluates to true. Otherwise we might mark the device dirty when we shouldn't.
|
r? @SimonSapin |
|
Reviewed 1 of 3 files at r1, 3 of 3 files at r3, 1 of 1 files at r4. tests/wpt/mozilla/tests/css/iframe_for_media_queries.html, line 10 at r3 (raw file):
Please change the colors so that red indicates failure, and green for success. tests/wpt/mozilla/tests/css/stylesheet_media_queries.html, line 16 at r3 (raw file):
Check both values with Comments from Reviewable |
|
Sure. I think we should get rid of setTimeout, and ideally requestAnimationFrame too. @iamrohit7 does the test written this way work? <!doctype html>
<meta charset="utf-8">
<title>CSS Test: Media query correctly forces style invalidation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="myframe" src="iframe_for_media_queries.html" height="500" width="500">
</iframe>
<script>
var test = async_test("Media queries within stylesheets");
window.onload = test.step_func_done(function() {
var frame = document.getElementById("myframe");
var frameDoc = frame.contentWindow.document;
var element = frameDoc.getElementById("testelement");
assert_equals(getComputedStyle(element).backgroundColor, "xxx");
frame.width = "300";
frameDoc.documentElement.offsetWidth; // Force layout
assert_equals(getComputedStyle(element).backgroundColor, "yyy");
})
</script>If it doesn't you may need to replace that requestAnimationFrame(test.step_func_done(function() {
assert_equals(getComputedStyle(element).backgroundColor, "yyy");
}))(Obviously replacing |
|
@emilio I tried forcing layout by accessing the offset as you suggested but it didn't work. The property value isn't being updated to the new value(though it changes visually). I still needed to |
|
@iamrohit7 In that case, I think using requestAnimationFrame should be enough, and is less flaky that setTimeout, have you tried with that? |
|
@emilio Do you mean something like this?
The second assert still fails. |
That sounds like a servo bug. Please let's just fix that instead of adding flakiness to web platform tests for everyone to work around it. |
|
There's one other bug in the test: it's using an element from one document, but a getComputedStyle call on a window from another document. The behavior of that is somewhere between "not specified very well and not very interoperable" and "lol". You really want to use |
|
On Sat, Dec 24, 2016 at 12:14:47PM -0800, Boris Zbarsky wrote:
That sounds like a servo bug. Please let's just fix that instead of adding flakiness to web platform tests for everyone to work around it.
Yes, but it's not even a single bug I think.
I think there are at least two different bugs here, that due to Servo's
architecture aren't easy to fix, and I think they should be fixed in
different PRs.
The first one is, as you noted, that changing the layout in a
same-origin iframe needs to flush all the same-origin parent chain, and
that's something Servo doesn't do (and isn't trivial because in Servo
layout is separated per _document_, not per origin).
I think we should change that and I'll fill a bug about it.
Also, I think there's a bug in our setter for the iframe width, which
doesn't mark the content document as needing layout, which is also
wrong.
I'll dig a bit more (probably tomorrow), and file issues/fix if I have
time.
In any case, I think we should land the proper test for this, and
marking it as failing/intermittent with a link to the proper issues.
|
|
|
|
@bors-servo r=SimonSapin |
|
|
|
|
|
|
|
Tidy is failing, I think the way to update it is
|
|
|
|
@bors-servo retry |
|
Travis seems still unhappy, please run the |
|
|
@emilio Done :) |
|
@bors-servo r=SimonSapin,Emilio Thanks Rohit! Sorry this took so long to get landed. |
|
|
Make Stylist::set_device check stylesheet media queries Fixes Stylist::set_device to check for media queries in stylesheets. <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14279 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14556) <!-- Reviewable:end -->
|
|
ghost commentedDec 12, 2016
•
edited by ghost
Fixes Stylist::set_device to check for media queries in stylesheets.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is