Bug 1387678 - Reenable Shadow DOM tests draft
authorDavid Burns <dburns@mozilla.com>
Tue, 13 Mar 2018 13:48:34 +0000
changeset 776875 e270ca9aacafd45da6de7f7f0030ede4a64de3fe
parent 776583 4a3275936ddf871103b53e00608e2b8d5aee7e69
push id105023
push userbmo:dburns@mozilla.com
push dateTue, 03 Apr 2018 21:07:50 +0000
bugs1387678
milestone61.0a1
Bug 1387678 - Reenable Shadow DOM tests This corrects a number of issues with the way we calculate the painted tree, especially around shadow DOM MozReview-Commit-ID: 73Aji2XbbSu
testing/marionette/driver.js
testing/marionette/element.js
testing/marionette/harness/marionette_harness/tests/unit/test_shadow_dom.py
testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
testing/marionette/harness/marionette_harness/www/test_shadow_dom.html
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2602,18 +2602,18 @@ GeckoDriver.prototype.clearElement = asy
  *     If <var>id</var> is not a string.
  * @throws {NoSuchElementError}
  *     If element represented by reference <var>id</var> is unknown.
  */
 GeckoDriver.prototype.switchToShadowRoot = async function(cmd) {
   assert.content(this.context);
   assert.open(this.getCurrentWindow());
 
-  let id = assert.string(cmd.parameters.id);
-  let webEl = WebElement.fromUUID(id, this.context);
+  let id = cmd.parameters.id;
+  let webEl = id ? WebElement.fromUUID(id, this.context) : null;
   await this.listener.switchToShadowRoot(webEl);
 };
 
 /**
  * Add a single cookie to the cookie store associated with the active
  * document's address.
  *
  * @param {Map.<string, (string|number|boolean)> cookie
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -1187,38 +1187,35 @@ element.getInViewCentrePoint = function(
  *     Sequence of elements in paint order.
  */
 element.getPointerInteractablePaintTree = function(el) {
   const doc = el.ownerDocument;
   const win = doc.defaultView;
   const container = {frame: win};
   const rootNode = el.getRootNode();
 
-  // Include shadow DOM host only if the element's root node is not the
-  // owner document.
-  if (rootNode !== doc) {
-    container.shadowRoot = rootNode;
-  }
-
   // pointer-interactable elements tree, step 1
   if (!el.isConnected) {
     return [];
   }
 
   // steps 2-3
   let rects = el.getClientRects();
   if (rects.length == 0) {
     return [];
   }
 
   // step 4
   let centre = element.getInViewCentrePoint(rects[0], win);
 
   // step 5
-  return doc.elementsFromPoint(centre.x, centre.y);
+  if (rootNode == doc) {
+    return doc.elementsFromPoint(centre.x, centre.y);
+  }
+  return rootNode.elementsFromPoint(centre.x, centre.y);
 };
 
 // TODO(ato): Not implemented.
 // In fact, it's not defined in the spec.
 element.isKeyboardInteractable = () => true;
 
 /**
  * Attempts to scroll into view |el|.
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_shadow_dom.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_shadow_dom.py
@@ -60,16 +60,17 @@ class TestShadowDom(MarionetteTestCase):
         # Jump back to top level content
         self.marionette.switch_to_shadow_root()
         # When no ShadowRoot is found, switch_to_shadow_root throws NoSuchElementException
         self.assertRaises(NoSuchElementException, self.marionette.switch_to_shadow_root,
                           self.marionette.find_element(By.ID, "empty-host"))
 
     def test_inner_shadow_dom(self):
         # Button in shadow root should be actionable
+        import pdb; pdb.set_trace()
         self.button.click()
         self.inner_host = self.marionette.find_element(By.ID, "inner-host")
         self.marionette.switch_to_shadow_root(self.inner_host)
         self.inner_button = self.marionette.find_element(By.ID, "inner-button")
         # Nested nutton in nested shadow root should be actionable
         self.inner_button.click()
         self.marionette.switch_to_shadow_root()
         # After jumping back to parent shadow root, button should again be actionable but inner
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -109,17 +109,16 @@ skip-if = appname == 'fennec'
 skip-if = appname == 'fennec' || os == "win" # http://bugs.python.org/issue14574
 
 [test_execute_sandboxes.py]
 [test_prefs.py]
 [test_prefs_enforce.py]
 skip-if = manage_instance == false || appname == 'fennec' # Bug 1298921
 
 [test_shadow_dom.py]
-skip-if = true # Bug 1293844, bug 1387678
 
 [test_chrome.py]
 skip-if = appname == 'fennec'
 
 [test_addons.py]
 skip-if = appname == 'fennec' # Bug 1330598
 
 [test_select.py]
--- a/testing/marionette/harness/marionette_harness/www/test_shadow_dom.html
+++ b/testing/marionette/harness/marionette_harness/www/test_shadow_dom.html
@@ -10,17 +10,17 @@
 <title>Marionette Test</title>
 </head>
 <body>
   <div id="host"></div>
   <div id="empty-host"></div>
   <script>
     'use strict';
     var host = document.getElementById('host');
-    var root = host.createShadowRoot();
+    var root = host.attachShadow({mode: 'open'});
     root.innerHTML = '<button id="button">Foo</button>' +
       '<div id="inner-host"></div>';
     var innerHost = host.shadowRoot.getElementById('inner-host');
-    var innerRoot = innerHost.createShadowRoot();
+    var innerRoot = innerHost.attachShadow({mode: 'open'});
     innerRoot.innerHTML = '<button id="inner-button">Bar</button>';
   </script>
 </body>
 </html>