diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index 6117295bdd1d..83afc9b5d8d1 100755
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2967,7 +2967,7 @@ var BrowserOnClick = {
anchorTarget.classList.contains("newtab-link")) {
event.preventDefault();
let where = whereToOpenLink(event, false, false);
- openLinkIn(anchorTarget.href, where, { charset: ownerDoc.characterSet });
+ openLinkIn(anchorTarget.href, where, { charset: ownerDoc.characterSet, referrerURI: ownerDoc.documentURIObject });
}
},
@@ -7248,8 +7248,9 @@ var gIdentityHandler = {
label.textContent = aPermission.label;
let img = document.createElement("image");
+ let isBlocked = (aPermission.state == SitePermissions.BLOCK) ? " blocked" : "";
img.setAttribute("class",
- "identity-popup-permission-icon " + aPermission.id + "-icon");
+ "identity-popup-permission-icon " + aPermission.id + "-icon" + isBlocked);
let container = document.createElement("hbox");
container.setAttribute("align", "center");
diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml
index dfc3b15b6049..560fba5164b5 100644
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1764,12 +1764,10 @@
foo
bar
foo
bar
", doctype="html") +name_xhtml = inline('
', doctype="xhtml") +link_html = inline("foo bar", doctype="html") +link_xhtml = inline('
', doctype="xhtml") + + +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") + self.assertIsInstance(found, HTMLElement) + self.assertEqual(expected, found) + + def test_child_element(self): + self.marionette.navigate(parent_child_html) + 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_html) + 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_html) + 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_html) + 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_html) + 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_invalid_css_selector_should_throw(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_element(By.CSS_SELECTOR, "#") + + def test_link_text(self): + self.marionette.navigate(link_html) + 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_html) + 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_html) + 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_not_found(self): + self.marionette.set_search_timeout(0) + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese") + + def test_not_found_implicit_wait(self): + self.marionette.set_search_timeout(50) + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese") + self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese") + + def test_not_found(self): + self.marionette.set_search_timeout(0) + self.marionette.navigate(id_html) + el = self.marionette.find_element(By.ID, "foo") + self.assertRaises(NoSuchElementException, el.find_element, By.CLASS_NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.CSS_SELECTOR, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.ID, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.PARTIAL_LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.TAG_NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.XPATH, "cheese") + + def test_not_found_implicit_wait(self): + self.marionette.set_search_timeout(50) + self.marionette.navigate(id_html) + el = self.marionette.find_element(By.ID, "foo") + self.assertRaises(NoSuchElementException, el.find_element, By.CLASS_NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.CSS_SELECTOR, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.ID, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.PARTIAL_LINK_TEXT, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.TAG_NAME, "cheese") + self.assertRaises(NoSuchElementException, el.find_element, By.XPATH, "cheese") + + def test_css_selector_scope_doesnt_start_at_rootnode(self): + self.marionette.navigate(parent_child_html) + 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_unknown_selector(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_elements("foo", "bar") + + def test_element_id_is_valid_uuid(self): + self.marionette.navigate(id_html) + el = self.marionette.find_element(By.TAG_NAME, "p") + uuid_regex = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$') + self.assertIsNotNone(re.search(uuid_regex, el.id), + 'UUID for the WebElement is not valid. ID is {}'\ + .format(el.id)) + + def test_invalid_xpath_selector(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_element(By.XPATH, "count(//input)") + with self.assertRaises(InvalidSelectorException): + parent = self.marionette.execute_script("return document.documentElement") + parent.find_element(By.XPATH, "count(//input)") + + def test_invalid_css_selector(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_element(By.CSS_SELECTOR, "") + with self.assertRaises(InvalidSelectorException): + parent = self.marionette.execute_script("return document.documentElement") + 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 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) + + def test_child_elements(self): + self.marionette.navigate(children_html) + 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_html) + 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_html) + 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_html) + 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_html) + 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_invalid_css_selector_should_throw(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_elements(By.CSS_SELECTOR, "#") + + def test_link_text(self): + self.marionette.navigate(link_html) + 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_html) + 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) + + def test_xpath(self): + self.marionette.navigate(children_html) + els = self.marionette.execute_script("return document.querySelectorAll('p')") + found = self.marionette.find_elements(By.XPATH, ".//p") + self.assertItemsIsInstance(found, HTMLElement) + self.assertSequenceEqual(els, found) + + def test_css_selector_scope_doesnt_start_at_rootnode(self): + self.marionette.navigate(parent_child_html) + 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) + + def test_unknown_selector(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_element("foo", "bar") + + def test_element_id_is_valid_uuid(self): + self.marionette.navigate(id_html) + els = self.marionette.find_elements(By.TAG_NAME, "p") + uuid_regex = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$') + self.assertIsNotNone(re.search(uuid_regex, els[0].id), + 'UUID for the WebElement is not valid. ID is {}'\ + .format(els[0].id)) + + def test_invalid_xpath_selector(self): + with self.assertRaises(InvalidSelectorException): + self.marionette.find_elements(By.XPATH, "count(//input)") + with self.assertRaises(InvalidSelectorException): + parent = self.marionette.execute_script("return document.documentElement") + 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) diff --git a/testing/marionette/harness/marionette/tests/unit/test_findelement.py b/testing/marionette/harness/marionette/tests/unit/test_findelement.py deleted file mode 100644 index c5578d169e4e..000000000000 --- a/testing/marionette/harness/marionette/tests/unit/test_findelement.py +++ /dev/null @@ -1,209 +0,0 @@ -# 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 - -from marionette import MarionetteTestCase -from marionette_driver.marionette import HTMLElement -from marionette_driver.by import By -from marionette_driver.errors import NoSuchElementException, InvalidSelectorException - - -class TestElements(MarionetteTestCase): - def setUp(self): - MarionetteTestCase.setUp(self) - self.marionette.set_search_timeout(0) - url = self.marionette.absolute_url("test.html") - self.marionette.navigate(url) - - def test_id(self): - el = self.marionette.execute_script("return window.document.getElementById('mozLink');") - found_el = self.marionette.find_element(By.ID, "mozLink") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_child_element(self): - el = self.marionette.find_element(By.ID, "divLink") - div = self.marionette.find_element(By.ID, "testDiv") - found_el = div.find_element(By.TAG_NAME, "a") - self.assertEqual("a", found_el.tag_name) - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_child_elements(self): - el = self.marionette.find_element(By.ID, "divLink2") - div = self.marionette.find_element(By.ID, "testDiv") - found_els = div.find_elements(By.TAG_NAME, "a") - self.assertTrue(el.id in [found_el.id for found_el in found_els]) - - def test_tag_name(self): - el = self.marionette.execute_script("return window.document.getElementsByTagName('body')[0];") - found_el = self.marionette.find_element(By.TAG_NAME, "body") - self.assertEqual('body', found_el.tag_name) - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.TAG_NAME, "body")[0] - self.assertEqual('body', found_el.tag_name) - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_class_name(self): - el = self.marionette.execute_script("return window.document.getElementsByClassName('linkClass')[0];") - found_el = self.marionette.find_element(By.CLASS_NAME, "linkClass") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.CLASS_NAME, "linkClass")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_by_name(self): - el = self.marionette.execute_script("return window.document.getElementsByName('myInput')[0];") - found_el = self.marionette.find_element(By.NAME, "myInput") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.NAME, "myInput")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_css_selector(self): - el = self.marionette.execute_script("return window.document.getElementById('testh1');") - found_el = self.marionette.find_element(By.CSS_SELECTOR, "h1") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.CSS_SELECTOR, "h1")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_invalid_css_selector_should_throw(self): - with self.assertRaises(InvalidSelectorException): - self.marionette.find_element(By.CSS_SELECTOR, "#") - - def test_link_text(self): - el = self.marionette.execute_script("return window.document.getElementById('mozLink');") - found_el = self.marionette.find_element(By.LINK_TEXT, "Click me!") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.LINK_TEXT, "Click me!")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_partial_link_text(self): - el = self.marionette.execute_script("return window.document.getElementById('mozLink');") - found_el = self.marionette.find_element(By.PARTIAL_LINK_TEXT, "Click m") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.PARTIAL_LINK_TEXT, "Click m")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_xpath(self): - el = self.marionette.execute_script("return window.document.getElementById('mozLink');") - found_el = self.marionette.find_element(By.XPATH, "id('mozLink')") - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - found_el = self.marionette.find_elements(By.XPATH, "id('mozLink')")[0] - self.assertEqual(HTMLElement, type(found_el)) - self.assertEqual(el, found_el) - - def test_not_found(self): - self.marionette.set_search_timeout(0) - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese") - - def test_not_found_implicit_wait(self): - self.marionette.set_search_timeout(50) - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese") - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese") - - def test_timeout_element(self): - button = self.marionette.find_element(By.ID, "createDivButton") - button.click() - self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "newDiv") - self.assertTrue(True, self.marionette.set_search_timeout(8000)) - self.assertEqual(HTMLElement, type(self.marionette.find_element(By.ID, "newDiv"))) - - def test_timeout_elements(self): - button = self.marionette.find_element(By.ID, "createDivButton") - button.click() - self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 0) - self.assertTrue(True, self.marionette.set_search_timeout(8000)) - self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 1) - - def test_css_selector_scope_doesnt_start_at_rootnode(self): - el = self.marionette.find_element(By.ID, "mozLink") - nav_el = self.marionette.find_element(By.ID, "testDiv") - found_els = nav_el.find_elements(By.CSS_SELECTOR, "a") - self.assertFalse(el.id in [found_el.id for found_el in found_els]) - - def test_finding_active_element_returns_element(self): - body = self.marionette.find_element(By.TAG_NAME, "body") - self.assertEqual(body, self.marionette.get_active_element()) - - def test_unknown_selector(self): - with self.assertRaises(InvalidSelectorException): - self.marionette.find_element("foo", "bar") - - def test_element_id_is_valid_uuid(self): - el = self.marionette.find_element(By.TAG_NAME, "body") - uuid_regex = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$') - self.assertIsNotNone(re.search(uuid_regex, el.id), - 'UUID for the WebElement is not valid. ID is {}'\ - .format(el.id)) - - def test_should_find_elements_by_link_text(self): - url = self.marionette.absolute_url("nestedElements.html") - self.marionette.navigate(url) - element = self.marionette.find_element(By.NAME, "div1") - children = element.find_elements(By.LINK_TEXT, "hello world") - self.assertEqual(len(children), 2) - self.assertEqual("link1", children[0].get_attribute("name")) - self.assertEqual("link2", children[1].get_attribute("name")) - - def test_should_throw_invalidselectorexception_when_invalid_xPath_in_driver_find_element(self): - url = self.marionette.absolute_url("formPage.html") - self.marionette.navigate(url) - self.assertRaises(InvalidSelectorException, self.marionette.find_element, By.XPATH, "count(//input)") - - def test_should_throw_invalidselectorexception_when_invalid_xpath_in_driver_find_elements(self): - url = self.marionette.absolute_url("formPage.html") - self.marionette.navigate(url) - self.assertRaises(InvalidSelectorException, self.marionette.find_elements, By.XPATH, "count(//input)") - - def test_should_throw_invalidselectorexception_when_invalid_xpath_in_element_find_element(self): - url = self.marionette.absolute_url("formPage.html") - self.marionette.navigate(url) - body = self.marionette.find_element(By.TAG_NAME, "body") - self.assertRaises(InvalidSelectorException, body.find_element, By.XPATH, "count(//input)") - - def test_should_throw_invalidselectorexception_when_invalid_xpath_in_element_find_elements(self): - url = self.marionette.absolute_url("formPage.html") - self.marionette.navigate(url) - body = self.marionette.find_element(By.TAG_NAME, "body") - self.assertRaises(InvalidSelectorException, body.find_elements, By.XPATH, "count(//input)") - - def test_should_throw_invalidselectorexception_when_css_is_empty_in_driver_find_element(self): - self.assertRaises(InvalidSelectorException, self.marionette.find_element, By.CSS_SELECTOR, "") - - def test_should_throw_invalidselectorexception_when_css_is_empty_in_driver_find_elements(self): - self.assertRaises(InvalidSelectorException, self.marionette.find_elements, By.CSS_SELECTOR, "") - - def test_should_throw_invalidselectorexception_when_css_is_empty_in_element_find_element(self): - body = self.marionette.find_element(By.TAG_NAME, "body") - self.assertRaises(InvalidSelectorException, body.find_element, By.CSS_SELECTOR, "") - - def test_should_throw_invalidselectorexception_when_css_is_empty_in_element_find_elements(self): - body = self.marionette.find_element(By.TAG_NAME, "body") - self.assertRaises(InvalidSelectorException, body.find_elements, By.CSS_SELECTOR, "") diff --git a/testing/marionette/harness/marionette/tests/unit/unit-tests.ini b/testing/marionette/harness/marionette/tests/unit/unit-tests.ini index 24ffa195f09c..4be59268b564 100644 --- a/testing/marionette/harness/marionette/tests/unit/unit-tests.ini +++ b/testing/marionette/harness/marionette/tests/unit/unit-tests.ini @@ -39,7 +39,7 @@ skip-if = buildapp == 'b2g' [test_execute_async_script.py] [test_execute_script.py] [test_simpletest_fail.js] -[test_findelement.py] +[test_element_retrieval.py] [test_findelement_chrome.py] skip-if = buildapp == 'b2g' diff --git a/toolkit/components/telemetry/TelemetrySession.jsm b/toolkit/components/telemetry/TelemetrySession.jsm index f70856f256b2..9d530e844bc1 100644 --- a/toolkit/components/telemetry/TelemetrySession.jsm +++ b/toolkit/components/telemetry/TelemetrySession.jsm @@ -1258,7 +1258,6 @@ var Impl = { simpleMeasurements: simpleMeasurements, histograms: protect(() => this.getHistograms(isSubsession, clearSubsession)), keyedHistograms: protect(() => this.getKeyedHistograms(isSubsession, clearSubsession)), - scalars: protect(() => this.getScalars(isSubsession, clearSubsession)), }; // Add extended set measurements common to chrome & content processes @@ -1273,6 +1272,13 @@ var Impl = { return payloadObj; } + // Set the scalars for the parent process. + payloadObj.processes = { + parent: { + scalars: protect(() => this.getScalars(isSubsession, clearSubsession)), + } + }; + // Additional payload for chrome process. payloadObj.info = info; diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js index 3a7610cb8be0..e8f43b4e68cd 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js @@ -242,13 +242,14 @@ function checkPayloadInfo(data) { Assert.ok(data.timezoneOffset <= 12*60, "The timezone must be in a valid range."); } -function checkScalars(payload) { +function checkScalars(processes) { // Check that the scalars section is available in the ping payload. - Assert.ok("scalars" in payload, "The scalars section must be available in the payload."); - Assert.equal(typeof payload.scalars, "object", "The scalars entry must be an object."); + const parentProcess = processes.parent; + Assert.ok("scalars" in parentProcess, "The scalars section must be available in the parent process."); + Assert.equal(typeof parentProcess.scalars, "object", "The scalars entry must be an object."); // Check that we have valid scalar entries. - const scalars = payload.scalars; + const scalars = parentProcess.scalars; for (let name in scalars) { Assert.equal(typeof name, "string", "Scalar names must be strings."); // Check if the value is of a supported type. @@ -403,7 +404,9 @@ function checkPayload(payload, reason, successfulPings, savedPings) { }; Assert.deepEqual(expected_keyed_count, keyedHistograms[TELEMETRY_TEST_KEYED_COUNT]); - checkScalars(payload); + Assert.ok("processes" in payload, "The payload must have a processes section."); + Assert.ok("parent" in payload.processes, "There must be at least a parent process."); + checkScalars(payload.processes); } function writeStringToFile(file, contents) { @@ -608,25 +611,25 @@ add_task(function* test_checkSubsessionScalars() { const TEST_SCALARS = [ UINT_SCALAR, STRING_SCALAR ]; for (let name of TEST_SCALARS) { // Scalar must be reported in subsession pings (e.g. main). - Assert.ok(name in subsession.scalars, + Assert.ok(name in subsession.processes.parent.scalars, name + " must be reported in a subsession ping."); } // No scalar must be reported in classic pings (e.g. saved-session). - Assert.ok(Object.keys(classic.scalars).length == 0, + Assert.ok(Object.keys(classic.processes.parent.scalars).length == 0, "Scalars must not be reported in a classic ping."); // And make sure that we're getting the right values in the // subsession ping. - Assert.equal(subsession.scalars[UINT_SCALAR], expectedUint, + Assert.equal(subsession.processes.parent.scalars[UINT_SCALAR], expectedUint, UINT_SCALAR + " must contain the expected value."); - Assert.equal(subsession.scalars[STRING_SCALAR], expectedString, + Assert.equal(subsession.processes.parent.scalars[STRING_SCALAR], expectedString, STRING_SCALAR + " must contain the expected value."); // Since we cleared the subsession in the last getPayload(), check that // breaking subsessions clears the scalars. subsession = TelemetrySession.getPayload("environment-change"); for (let name of TEST_SCALARS) { - Assert.ok(!(name in subsession.scalars), + Assert.ok(!(name in subsession.processes.parent.scalars), name + " must be cleared with the new subsession."); } @@ -636,9 +639,9 @@ add_task(function* test_checkSubsessionScalars() { Telemetry.scalarSet(UINT_SCALAR, expectedUint); Telemetry.scalarSet(STRING_SCALAR, expectedString); subsession = TelemetrySession.getPayload("environment-change"); - Assert.equal(subsession.scalars[UINT_SCALAR], expectedUint, + Assert.equal(subsession.processes.parent.scalars[UINT_SCALAR], expectedUint, UINT_SCALAR + " must contain the expected value."); - Assert.equal(subsession.scalars[STRING_SCALAR], expectedString, + Assert.equal(subsession.processes.parent.scalars[STRING_SCALAR], expectedString, STRING_SCALAR + " must contain the expected value."); }); diff --git a/toolkit/content/aboutTelemetry.js b/toolkit/content/aboutTelemetry.js index 1d05f492f80e..8685b037eb5f 100644 --- a/toolkit/content/aboutTelemetry.js +++ b/toolkit/content/aboutTelemetry.js @@ -1559,7 +1559,11 @@ var Scalars = { let scalarsSection = document.getElementById("scalars"); removeAllChildNodes(scalarsSection); - let scalars = aPayload.scalars; + if (!aPayload.processes || !aPayload.processes.parent) { + return; + } + + let scalars = aPayload.processes.parent.scalars; const hasData = scalars && Object.keys(scalars).length > 0; setHasData("scalars-section", hasData); if (!hasData) {