Bug 1194224 - fixing a bug and adding more tests. draft
authorYura Zenevich <yzenevich@mozilla.com>
Wed, 26 Aug 2015 15:53:02 -0400
changeset 288072 de5f020249e23b573baed38abda5af3881e4c7d2
parent 288071 7ee77248182d4d43ebc1a899ad32041beb8a59a2
child 508725 607745c359176d2ff74a01bdc75a7d6857f9e8b5
push id4792
push useryura.zenevich@gmail.com
push dateWed, 26 Aug 2015 20:00:52 +0000
bugs1194224
milestone43.0a1
Bug 1194224 - fixing a bug and adding more tests. --- .../marionette/client/marionette/tests/unit/test_shadow_dom.py | 9 ++++++++- testing/marionette/client/marionette/www/test_shadow_dom.html | 1 + testing/marionette/listener.js | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-)
testing/marionette/client/marionette/tests/unit/test_shadow_dom.py
testing/marionette/client/marionette/www/test_shadow_dom.html
testing/marionette/listener.js
--- a/testing/marionette/client/marionette/tests/unit/test_shadow_dom.py
+++ b/testing/marionette/client/marionette/tests/unit/test_shadow_dom.py
@@ -1,14 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
-from marionette_driver.errors import StaleElementException
+from marionette_driver.errors import (NoSuchElementException, StaleElementException)
 
 
 class TestShadowDom(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.enforce_gecko_prefs({"dom.webcomponents.enabled": True})
         self.marionette.navigate(self.marionette.absolute_url("test_shadow_dom.html"))
@@ -34,16 +34,23 @@ class TestShadowDom(MarionetteTestCase):
         # After removing button from shadow DOM, button should be stale
         self.assertRaises(StaleElementException, self.button.click)
 
     def test_shadow_dom_raises_stale_element_exception_when_host_removed(self):
         self.marionette.execute_script('document.getElementById("host").remove();')
         # After removing shadow DOM host element, button should be stale
         self.assertRaises(StaleElementException, self.button.click)
 
+    def test_non_existent_shadow_dom(self):
+        # 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("id", "empty-host"))
+
     def test_inner_shadow_dom(self):
         # Button in shadow root should be actionable
         self.button.click()
         self.inner_host = self.marionette.find_element("id", "inner-host")
         self.marionette.switch_to_shadow_root(self.inner_host)
         self.inner_button = self.marionette.find_element("id", "inner-button")
         # Nested nutton in nested shadow root should be actionable
         self.inner_button.click()
--- a/testing/marionette/client/marionette/www/test_shadow_dom.html
+++ b/testing/marionette/client/marionette/www/test_shadow_dom.html
@@ -6,16 +6,17 @@
 
 <html>
 <meta charset="UTF-8">
 <head>
 <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();
     root.innerHTML = '<button id="button">Foo</button>' +
       '<div id="inner-host"></div>';
     var innerHost = host.shadowRoot.getElementById('inner-host');
     var innerRoot = innerHost.createShadowRoot();
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -1684,17 +1684,17 @@ function switchToShadowRoot(id) {
     }
     return;
   }
 
   let foundShadowRoot;
   let hostEl = elementManager.getKnownElement(id, curContainer);
   foundShadowRoot = hostEl.shadowRoot;
   if (!foundShadowRoot) {
-    throw new NoSuchElementError('Unable to locate shadow root: ' + msg.json.element);
+    throw new NoSuchElementError('Unable to locate shadow root: ' + id);
   }
   curContainer.shadowRoot = foundShadowRoot;
 }
 
 /**
  * Switch to frame given either the server-assigned element id,
  * its index in window.frames, or the iframe's name or id.
  */