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

Make Stylist::set_device check stylesheet media queries #14556

Merged
merged 2 commits into from Jan 29, 2017

Conversation

@ghost
Copy link

ghost commented Dec 12, 2016

Fixes Stylist::set_device to check for media queries in stylesheets.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14279 (github issue number if applicable).
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Dec 12, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/stylist.rs
  • @emilio: components/style/stylist.rs
@highfive
Copy link

highfive commented Dec 12, 2016

warning Warning warning

  • These commits include an empty title element (<title></title>). Consider adding appropriate metadata.
<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.

Copy link
@emilio

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.

Copy link
@emilio

emilio Dec 14, 2016

Member

nit: No space after id="head". also, another id could be better.

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.

Copy link
@emilio

emilio Dec 14, 2016

Member

Use requestAnimationFrame, and iframeTest.step_func.

@@ -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.

Copy link
@emilio

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.

@emilio
Copy link
Member

emilio commented Dec 14, 2016

@highfive highfive assigned SimonSapin and unassigned nox Dec 14, 2016
@SimonSapin SimonSapin changed the title Fix set device Make Stylist::set_device check stylesheet media queries Dec 14, 2016
@SimonSapin
Copy link
Member

SimonSapin commented Dec 23, 2016

Reviewed 1 of 3 files at r1, 3 of 3 files at r3, 1 of 1 files at r4.
Review status: all files reviewed at latest revision, 6 unresolved discussions.


tests/wpt/mozilla/tests/css/iframe_for_media_queries.html, line 10 at r3 (raw file):

    <style media="(max-width: 399px)">
    h1 {
        background: red;

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):

    setTimeout(iframeTest.step_func_done(function () {
        var after = getComputedStyle(testElement).getPropertyValue("background-color");
        assert_true(before != after, "Recomputed values");

Check both values with assert_equals, not just that they’re different.


Comments from Reviewable

@SimonSapin
Copy link
Member

SimonSapin commented Dec 23, 2016

Although github shows it as "outdated", it looks like this comment from @emilio is still relevant:

Use requestAnimationFrame, and iframeTest.step_func.

Though to be honest I’m not sure how to use these. Can you give more details @emilio ?

@emilio
Copy link
Member

emilio commented Dec 23, 2016

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 test.step_func_done for test.step_func, and assert_equals(getComputedStyle(element).backgroundColor, "yyy"); for:

requestAnimationFrame(test.step_func_done(function() {
   assert_equals(getComputedStyle(element).backgroundColor, "yyy");
}))

(Obviously replacing xxx and yyy for the proper values).

@ghost
Copy link
Author

ghost commented Dec 24, 2016

@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 setTimeout before checking for the second value. I should've commented so, sorry.

@emilio
Copy link
Member

emilio commented Dec 24, 2016

@iamrohit7 In that case, I think using requestAnimationFrame should be enough, and is less flaky that setTimeout, have you tried with that?

@ghost
Copy link
Author

ghost commented Dec 24, 2016

@emilio Do you mean something like this?

var test = async_test("Media queries within stylesheets");
window.onload = test.step_func(function() {
  var frame = document.getElementById("myframe");
  var frameDoc = frame.contentWindow.document;
  var element = frameDoc.getElementById("testelement");
  assert_equals(getComputedStyle(element).backgroundColor, "rgb(255, 0, 0)");
  frame.width = "300";
  frameDoc.documentElement.offsetWidth; // Force layout
  window.requestAnimationFrame(test.step_func_done(function () {
	  assert_equals(getComputedStyle(element).backgroundColor, "rgb(0, 255, 0)");
  }));
});

The second assert still fails.

@bzbarsky
Copy link
Contributor

bzbarsky commented Dec 24, 2016

I tried forcing layout by accessing the offset as you suggested but it didn't work.

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.

@bzbarsky
Copy link
Contributor

bzbarsky commented Dec 24, 2016

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 frame.contentWindow.getComputedStyle(element).

@emilio
Copy link
Member

emilio commented Dec 24, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jan 18, 2017

The latest upstream changes (presumably #14839) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio
Copy link
Member

emilio commented Jan 28, 2017

@bors-servo r=SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Jan 28, 2017

📌 Commit cda2995 has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Jan 28, 2017

Testing commit cda2995 with merge d551a36...

@bors-servo
Copy link
Contributor

bors-servo commented Jan 28, 2017

💔 Test failed - linux-dev

@emilio
Copy link
Member

emilio commented Jan 28, 2017

Tidy is failing, I think the way to update it is ./mach update-wpt, but I'm not totally sure:

./tests/wpt/mozilla/meta/MANIFEST.json:6795: tab on line

./tests/wpt/mozilla/meta/MANIFEST.json:6796: tab on line
@jdm
Copy link
Member

jdm commented Jan 28, 2017

./mach manifest-update

@ghost
Copy link
Author

ghost commented Jan 29, 2017

@bors-servo retry

@emilio
Copy link
Member

emilio commented Jan 29, 2017

Travis seems still unhappy, please run the manifest-update command (or ./mach test-wpt --manifest-update --binary= SKIP_TESTS).

@emilio
Copy link
Member

emilio commented Jan 29, 2017

$ bash etc/ci/manifest_changed.sh
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index a6092c071..372a9f46a 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -6788,18 +6788,18 @@
             "url": "/_mozilla/css/offset_properties_inline.html"
	                }
			         ],
				 -        "css/test_font_family_parsing.html": [
				 -          {
				 -            "path": "css/test_font_family_parsing.html",
				 -            "url": "/_mozilla/css/test_font_family_parsing.html"
				 -          }
				 -        ],
				          "css/stylesheet_media_queries.html": [
					             {
						                  "path": "css/stylesheet_media_queries.html",
								               "url": "/_mozilla/css/stylesheet_media_queries.html"
									                  }
											           ],
												   +        "css/test_font_family_parsing.html": [
												   +          {
												   +            "path": "css/test_font_family_parsing.html",
												   +            "url": "/_mozilla/css/test_font_family_parsing.html"
												   +          }
												   +        ],
												            "css/test_variable_legal_values.html": [
													               {
														                    "path": "css/test_variable_legal_values.html",
																    The command "bash etc/ci/manifest_changed.sh" exited with 1.
@ghost
Copy link
Author

ghost commented Jan 29, 2017

@emilio Done :)

@emilio
Copy link
Member

emilio commented Jan 29, 2017

@bors-servo r=SimonSapin,Emilio

Thanks Rohit! Sorry this took so long to get landed.

@bors-servo
Copy link
Contributor

bors-servo commented Jan 29, 2017

📌 Commit 325271e has been approved by SimonSapin,Emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jan 29, 2017

Testing commit 325271e with merge 1c1aaa5...

bors-servo added a commit that referenced this pull request Jan 29, 2017
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 -->
@bors-servo bors-servo merged commit 325271e into servo:master Jan 29, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@ghost ghost deleted the fix-set-device branch Jan 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.