Bug 1283999 - Run element retrieval tests on XHTML documents; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Sat, 02 Jul 2016 21:38:01 +0100
changeset 383347 f9ebc8f6a99a824a1ba9517a1d3d818cd8f6b5d6
parent 383346 045017f43adaca258899b1fdf83daf9239da0934
child 383348 655926aecb7350bcd6763420bd77a01ce514ca51
push id21992
push userbmo:ato@mozilla.com
push dateSat, 02 Jul 2016 21:01:45 +0000
reviewersautomatedtester
bugs1283999
milestone50.0a1
Bug 1283999 - Run element retrieval tests on XHTML documents; r?automatedtester MozReview-Commit-ID: 5dhnqsZhysn
testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
--- a/testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
@@ -1,16 +1,16 @@
 # 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/.
 
 import re
 import urllib
 
-from marionette import MarionetteTestCase
+from marionette import MarionetteTestCase, skip
 from marionette_driver.marionette import HTMLElement
 from marionette_driver.by import By
 from marionette_driver.errors import NoSuchElementException, InvalidSelectorException
 
 
 def inline(doc, doctype="html"):
     if doctype == "html":
         return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
@@ -25,24 +25,30 @@ r"""<!DOCTYPE html PUBLIC "-//W3C//DTD X
 
   <body>
     %s
   </body>
 </html>""" % doc)
 
 
 id_html = inline("<p id=foo></p>", doctype="html")
+id_xhtml = inline('<p id="foo"></p>', doctype="xhtml")
 parent_child_html = inline("<div id=parent><p id=child></p></div>", doctype="html")
+parent_child_xhtml = inline('<div id="parent"><p id="child"></p></div>', doctype="xhtml")
 children_html = inline("<div><p>foo <p>bar</div>", doctype="html")
+children_xhtml = inline("<div><p>foo</p> <p>bar</p></div>", doctype="xhtml")
 class_html = inline("<p class='foo bar'>", doctype="html")
+class_xhtml = inline('<p class="foo bar"></p>', doctype="xhtml")
 name_html = inline("<p name=foo>", doctype="html")
+name_xhtml = inline('<p name="foo"></p>', doctype="xhtml")
 link_html = inline("<p><a href=#>foo bar</a>", doctype="html")
+link_xhtml = inline('<p><a href="#">foo bar</a></p>', doctype="xhtml")
 
 
-class TestFindElement(MarionetteTestCase):
+class TestFindElementHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_search_timeout(0)
 
     def test_id(self):
         self.marionette.navigate(id_html)
         expected = self.marionette.execute_script("return document.querySelector('p')")
         found = self.marionette.find_element(By.ID, "foo")
@@ -193,17 +199,100 @@ class TestFindElement(MarionetteTestCase
             parent.find_element(By.CSS_SELECTOR, "")
 
     def test_finding_active_element_returns_element(self):
         self.marionette.navigate(id_html)
         active = self.marionette.execute_script("return document.activeElement")
         self.assertEqual(active, self.marionette.get_active_element())
 
 
-class TestFindElements(MarionetteTestCase):
+class TestFindElementXHTML(MarionetteTestCase):
+    def setUp(self):
+        MarionetteTestCase.setUp(self)
+        self.marionette.set_search_timeout(0)
+
+    def test_id(self):
+        self.marionette.navigate(id_xhtml)
+        expected = self.marionette.execute_script("return document.querySelector('p')")
+        found = self.marionette.find_element(By.ID, "foo")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(expected, found)
+
+    def test_child_element(self):
+        self.marionette.navigate(parent_child_xhtml)
+        parent = self.marionette.find_element(By.ID, "parent")
+        child = self.marionette.find_element(By.ID, "child")
+        found = parent.find_element(By.TAG_NAME, "p")
+        self.assertEqual(found.tag_name, "p")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(child, found)
+
+    def test_tag_name(self):
+        self.marionette.navigate(children_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('p')")
+        found = self.marionette.find_element(By.TAG_NAME, "p")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_class_name(self):
+        self.marionette.navigate(class_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('.foo')")
+        found = self.marionette.find_element(By.CLASS_NAME, "foo")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_by_name(self):
+        self.marionette.navigate(name_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('[name=foo]')")
+        found = self.marionette.find_element(By.NAME, "foo")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_css_selector(self):
+        self.marionette.navigate(children_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('p')")
+        found = self.marionette.find_element(By.CSS_SELECTOR, "p")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_link_text(self):
+        self.marionette.navigate(link_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('a')")
+        found = self.marionette.find_element(By.LINK_TEXT, "foo bar")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_partial_link_text(self):
+        self.marionette.navigate(link_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('a')")
+        found = self.marionette.find_element(By.PARTIAL_LINK_TEXT, "foo")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_xpath(self):
+        self.marionette.navigate(id_xhtml)
+        el = self.marionette.execute_script("return document.querySelector('#foo')")
+        found = self.marionette.find_element(By.XPATH, "id('foo')")
+        self.assertIsInstance(found, HTMLElement)
+        self.assertEqual(el, found)
+
+    def test_css_selector_scope_does_not_start_at_rootnode(self):
+        self.marionette.navigate(parent_child_xhtml)
+        el = self.marionette.find_element(By.ID, "child")
+        parent = self.marionette.find_element(By.ID, "parent")
+        found = parent.find_element(By.CSS_SELECTOR, "p")
+        self.assertEqual(el, found)
+
+    def test_active_element(self):
+        self.marionette.navigate(id_xhtml)
+        active = self.marionette.execute_script("return document.activeElement")
+        self.assertEqual(active, self.marionette.get_active_element())
+
+
+class TestFindElementsHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_search_timeout(0)
 
     def assertItemsIsInstance(self, items, typ):
         for item in items:
             self.assertIsInstance(item, typ)
 
@@ -295,8 +384,83 @@ class TestFindElements(MarionetteTestCas
             parent.find_elements(By.XPATH, "count(//input)")
 
     def test_invalid_css_selector(self):
         with self.assertRaises(InvalidSelectorException):
             self.marionette.find_elements(By.CSS_SELECTOR, "")
         with self.assertRaises(InvalidSelectorException):
             parent = self.marionette.execute_script("return document.documentElement")
             parent.find_elements(By.CSS_SELECTOR, "")
+
+
+class TestFindElementsXHTML(MarionetteTestCase):
+    def setUp(self):
+        MarionetteTestCase.setUp(self)
+        self.marionette.set_search_timeout(0)
+
+    def assertItemsIsInstance(self, items, typ):
+        for item in items:
+            self.assertIsInstance(item, typ)
+
+    def test_child_elements(self):
+        self.marionette.navigate(children_xhtml)
+        parent = self.marionette.find_element(By.TAG_NAME, "div")
+        children = self.marionette.find_elements(By.TAG_NAME, "p")
+        found = parent.find_elements(By.TAG_NAME, "p")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(found, children)
+
+    def test_tag_name(self):
+        self.marionette.navigate(children_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('p')")
+        found = self.marionette.find_elements(By.TAG_NAME, "p")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_class_name(self):
+        self.marionette.navigate(class_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('.foo')")
+        found = self.marionette.find_elements(By.CLASS_NAME, "foo")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_by_name(self):
+        self.marionette.navigate(name_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('[name=foo]')")
+        found = self.marionette.find_elements(By.NAME, "foo")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_css_selector(self):
+        self.marionette.navigate(children_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('p')")
+        found = self.marionette.find_elements(By.CSS_SELECTOR, "p")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_link_text(self):
+        self.marionette.navigate(link_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('a')")
+        found = self.marionette.find_elements(By.LINK_TEXT, "foo bar")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_partial_link_text(self):
+        self.marionette.navigate(link_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('a')")
+        found = self.marionette.find_elements(By.PARTIAL_LINK_TEXT, "foo")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    @skip("XHTML namespace not yet supported")
+    def test_xpath(self):
+        self.marionette.navigate(children_xhtml)
+        els = self.marionette.execute_script("return document.querySelectorAll('p')")
+        found = self.marionette.find_elements(By.XPATH, "//xhtml:p")
+        self.assertItemsIsInstance(found, HTMLElement)
+        self.assertSequenceEqual(els, found)
+
+    def test_css_selector_scope_doesnt_start_at_rootnode(self):
+        self.marionette.navigate(parent_child_xhtml)
+        els = self.marionette.find_elements(By.ID, "child")
+        parent = self.marionette.find_element(By.ID, "parent")
+        found = parent.find_elements(By.CSS_SELECTOR, "p")
+        self.assertSequenceEqual(els, found)