Bug 1576229 - Account for user stylesheets for Shadow DOM invalidation. r=jwatt
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 30 Aug 2019 14:35:34 +0000
changeset 551381 19e21bdb79cbfdc5b3a9c2323d3fcb6e28f159cc
parent 551380 a07e1432deaab8acf7a4a090f2365cfcd86c5d22
child 551382 4ea7cebd11a3738600b4d4356984db4e5f4fe234
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1576229
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1576229 - Account for user stylesheets for Shadow DOM invalidation. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D43992
layout/style/test/mochitest.ini
layout/style/test/test_user_sheet_shadow_dom.html
servo/components/style/invalidation/element/state_and_attributes.rs
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -48,16 +48,17 @@ support-files =
   visited_image_loading.sjs
   visited-lying-inner.html
   visited-pref-iframe.html
   xbl_bindings.xml
 
 [test_acid3_test46.html]
 [test_addSheet.html]
 support-files = additional_sheets_helper.html
+[test_user_sheet_shadow_dom.html]
 [test_additional_sheets.html]
 support-files = additional_sheets_helper.html
 [test_align_justify_computed_values.html]
 [test_all_shorthand.html]
 [test_animations.html]
 skip-if = (toolkit == 'android')
 [test_animations_async_tests.html]
 support-files = Ahem.ttf file_animations_async_tests.html
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_user_sheet_shadow_dom.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<title>Test for bug 1576229 - Nodes in Shadow DOM react properly to dynamic changes in user sheets</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<div></div>
+<span id="host" style="display: block"></span>
+<script>
+const gIOService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
+  .getService(SpecialPowers.Ci.nsIIOService)
+
+const gSSService = SpecialPowers.Cc["@mozilla.org/content/style-sheet-service;1"]
+  .getService(SpecialPowers.Ci.nsIStyleSheetService);
+
+const windowUtils = SpecialPowers.getDOMWindowUtils(window);
+
+function loadUserSheet(style) {
+  const uri = gIOService.newURI("data:text/css," + style);
+  windowUtils.loadSheet(uri, windowUtils.USER_SHEET);
+}
+
+SimpleTest.waitForExplicitFinish();
+
+onload = function() {
+  loadUserSheet(`
+    div {
+      width: 100px;
+      height: 100px;
+      background-color: red;
+    }
+    .foo {
+      background-color: green;
+    }
+  `);
+  let host = document.querySelector("#host");
+  host.attachShadow({ mode: "open" }).innerHTML = `
+    <div></div>
+  `;
+  let light = document.querySelector('div');
+  let shadow = host.shadowRoot.querySelector('div');
+  is(getComputedStyle(light).backgroundColor, "rgb(255, 0, 0)", "User sheet works in light DOM");
+  is(getComputedStyle(shadow).backgroundColor, "rgb(255, 0, 0)", "User sheet works in shadow DOM");
+  light.classList.add("foo");
+  shadow.classList.add("foo");
+  is(getComputedStyle(light).backgroundColor, "rgb(0, 128, 0)", "Dynamic change for user sheet works in light DOM");
+  is(getComputedStyle(shadow).backgroundColor, "rgb(0, 128, 0)", "Dynamic change for user sheet works in shadow DOM");
+  SimpleTest.finish();
+}
+</script>
--- a/servo/components/style/invalidation/element/state_and_attributes.rs
+++ b/servo/components/style/invalidation/element/state_and_attributes.rs
@@ -11,17 +11,17 @@ use crate::dom::TElement;
 use crate::element_state::ElementState;
 use crate::invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper};
 use crate::invalidation::element::invalidation_map::*;
 use crate::invalidation::element::invalidator::{DescendantInvalidationLists, InvalidationVector};
 use crate::invalidation::element::invalidator::{Invalidation, InvalidationProcessor};
 use crate::invalidation::element::restyle_hints::RestyleHint;
 use crate::selector_map::SelectorMap;
 use crate::selector_parser::Snapshot;
-use crate::stylesheets::origin::{Origin, OriginSet};
+use crate::stylesheets::origin::OriginSet;
 use crate::{Atom, WeakAtom};
 use selectors::attr::CaseSensitivity;
 use selectors::matching::matches_selector;
 use selectors::matching::{MatchingContext, MatchingMode, VisitedHandlingMode};
 use selectors::NthIndexCache;
 use smallvec::SmallVec;
 
 /// The collector implementation.
@@ -241,17 +241,17 @@ where
                 classes_removed: &classes_removed,
                 classes_added: &classes_added,
                 descendant_invalidations,
                 sibling_invalidations,
                 invalidates_self: false,
             };
 
             let document_origins = if !matches_document_author_rules {
-                Origin::UserAgent.into()
+                OriginSet::ORIGIN_USER_AGENT | OriginSet::ORIGIN_USER
             } else {
                 OriginSet::all()
             };
 
             for (cascade_data, origin) in self.shared_context.stylist.iter_origins() {
                 if document_origins.contains(origin.into()) {
                     collector
                         .collect_dependencies_in_invalidation_map(cascade_data.invalidation_map());