# 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 types import urllib from marionette_driver.by import By from marionette_harness import MarionetteTestCase boolean_attributes = { "audio": ["autoplay", "controls", "loop", "muted"], "button": ["autofocus", "disabled", "formnovalidate"], "details": ["open"], "dialog": ["open"], "fieldset": ["disabled"], "form": ["novalidate"], "iframe": ["allowfullscreen"], "img": ["ismap"], "input": ["autofocus", "checked", "disabled", "formnovalidate", "multiple", "readonly", "required"], "menuitem": ["checked", "default", "disabled"], "object": ["typemustmatch"], "ol": ["reversed"], "optgroup": ["disabled"], "option": ["disabled", "selected"], "script": ["async", "defer"], "select": ["autofocus", "disabled", "multiple", "required"], "textarea": ["autofocus", "disabled", "readonly", "required"], "track": ["default"], "video": ["autoplay", "controls", "loop", "muted"], } def inline(doc, doctype="html"): if doctype == "html": return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc)) elif doctype == "xhtml": return "data:application/xhtml+xml,{}".format(urllib.quote( r"""
")) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("style") self.assertIsInstance(attr, types.StringTypes) self.assertEqual("foo", attr) def test_boolean_attributes(self): for tag, attrs in boolean_attributes.iteritems(): for attr in attrs: print("testing boolean attribute <{0} {1}>".format(tag, attr)) doc = inline("<{0} {1}>".format(tag, attr)) self.marionette.navigate(doc) el = self.marionette.find_element(By.TAG_NAME, tag) res = el.get_attribute(attr) self.assertIsInstance(res, types.StringTypes) self.assertEqual("true", res) def test_global_boolean_attributes(self): self.marionette.navigate(inline("
foo")) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("hidden") self.assertIsInstance(attr, types.StringTypes) self.assertEqual("true", attr) self.marionette.navigate(inline("
foo")) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("hidden") self.assertIsNone(attr) self.marionette.navigate(inline("
foo")) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("itemscope") self.assertIsInstance(attr, types.StringTypes) self.assertEqual("true", attr) self.marionette.navigate(inline("
foo")) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("itemscope") self.assertIsNone(attr) # TODO(ato): Test for custom elements def test_xhtml(self): doc = inline("
foo
", doctype="xhtml") self.marionette.navigate(doc) el = self.marionette.find_element(By.TAG_NAME, "p") attr = el.get_attribute("hidden") self.assertIsInstance(attr, types.StringTypes) self.assertEqual("true", attr) class TestGetElementProperty(MarionetteTestCase): def test_get(self): self.marionette.navigate(disabled) el = self.marionette.find_element(By.TAG_NAME, "input") prop = el.get_property("disabled") self.assertIsInstance(prop, bool) self.assertTrue(prop) def test_missing_property_returns_default(self): self.marionette.navigate(input) el = self.marionette.find_element(By.TAG_NAME, "input") prop = el.get_property("checked") self.assertIsInstance(prop, bool) self.assertFalse(prop) def test_attribute_not_returned(self): self.marionette.navigate(attribute) el = self.marionette.find_element(By.TAG_NAME, "input") self.assertEqual(el.get_property("foo"), None) def test_manipulated_element(self): self.marionette.navigate(check) el = self.marionette.find_element(By.TAG_NAME, "input") self.assertEqual(el.get_property("checked"), False) el.click() self.assertEqual(el.get_property("checked"), True) el.click() self.assertEqual(el.get_property("checked"), False)