Bug 1705141 - Update imperative slotting API tests r=smaug
authorSean Feng <sefeng@mozilla.com>
Tue, 20 Jul 2021 18:06:24 +0000
changeset 586208 f3f3f0a6ac0c4e8259fa3ca25cf5fcfbb494d941
parent 586207 880b743252983a47de62ef87d89013222595a2db
child 586209 1f8746b344c1bb7b88c4f61a893ee46e976c89a1
push id146587
push usersefeng@mozilla.com
push dateTue, 20 Jul 2021 18:09:18 +0000
treeherderautoland@0a87a26cc1b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1705141
milestone92.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 1705141 - Update imperative slotting API tests r=smaug - Added a new test to ensure the assign slottables step is done in tree order - Added a new assertion to a test Differential Revision: https://phabricator.services.mozilla.com/D119442
testing/web-platform/tests/shadow-dom/imperative-slot-api-slotchange.html
testing/web-platform/tests/shadow-dom/imperative-slot-api.html
--- a/testing/web-platform/tests/shadow-dom/imperative-slot-api-slotchange.html
+++ b/testing/web-platform/tests/shadow-dom/imperative-slot-api-slotchange.html
@@ -6,16 +6,19 @@
 <link rel="help" href="https://dom.spec.whatwg.org/#signaling-slot-change">
 <script src="resources/shadow-dom.js"></script>
 
 <div id="test_slotchange">
   <div id="host">
     <template id="shadow_root" data-mode="open" data-slot-assignment="manual">
       <slot id="s1"><div id="fb">fallback</div></slot>
       <slot id="s2"></slot>
+      <div>
+        <slot id="s2.5"></slot>
+      </div>
       <slot id="s3"></slot>
     </template>
     <div id="c1"></div>
     <div id="c2"></div>
   </div>
   <div id="c4"></div>
 </div>
 
@@ -350,9 +353,42 @@ async_test((test) => {
     tTree.s1.assign(tTree.c1);
 
     Promise.all([s1Promise, s3Promise]).then(test.step_func_done(() => {
       assert_equals(data.s1EventCount, 1);
       assert_equals(data.s3EventCount, 2);
     }));
   }));
 }, "Fire slotchange event when assign node to nested slot, ensure event bubbles ups.");
+
+promise_test(async t => {
+  async function mutationObserversRun() {
+    return new Promise(r => {
+      t.step_timeout(r, 0);
+    });
+  }
+  let tTree = createTestTree(test_slotchange);
+
+  tTree.s1.assign(tTree.c1);
+  tTree["s2.5"].assign(tTree.c2);
+
+  let slotChangedOrder = [];
+
+  // Clears out pending mutation observers
+  await mutationObserversRun();
+
+  tTree.s1.addEventListener("slotchange", function() {
+    slotChangedOrder.push("s1");
+  });
+
+  tTree.s3.addEventListener("slotchange", function() {
+    slotChangedOrder.push("s3");
+  });
+
+  tTree["s2.5"].addEventListener("slotchange", function() {
+    slotChangedOrder.push("s2.5");
+  });
+
+  tTree.s3.assign(tTree.c2, tTree.c1);
+  await mutationObserversRun();
+  assert_array_equals(slotChangedOrder, ["s1", "s2.5", "s3"]);
+}, 'Signal a slot change should be done in tree order.');
 </script>
--- a/testing/web-platform/tests/shadow-dom/imperative-slot-api.html
+++ b/testing/web-platform/tests/shadow-dom/imperative-slot-api.html
@@ -191,16 +191,17 @@ test(() => {
   let tTree = createTestTree(test_assign);
 
   tTree.s1.assign(tTree.c1, tTree.c2, tTree.c3);
   assert_array_equals(tTree.s1.assignedNodes(), [tTree.c1, tTree.c2, tTree.c3]);
 
   tTree.host4.append(tTree.c1);
   assert_array_equals(tTree.s1.assignedNodes(), [tTree.c2, tTree.c3]);
   assert_array_equals(tTree.s4.assignedNodes(), []);
+  assert_equals(tTree.c1.assignedSlot, null);
 
   tTree.s4.assign(tTree.c1);
   assert_array_equals(tTree.s4.assignedNodes(), [tTree.c1]);
   assert_equals(tTree.c1.assignedSlot, tTree.s4);
 }, 'Appending slottable to different host, it loses slot assignment. It can be re-assigned within a new host.');
 
 test(() => {
   let tTree = createTestTree(test_assign);