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(-)
--- 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.
*/