summaryrefslogtreecommitdiffstats
path: root/toolkit/components/tooltiptext/tests
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/tooltiptext/tests')
-rw-r--r--toolkit/components/tooltiptext/tests/browser.toml16
-rw-r--r--toolkit/components/tooltiptext/tests/browser_bug329212.js48
-rw-r--r--toolkit/components/tooltiptext/tests/browser_bug331772_xul_tooltiptext_in_html.js30
-rw-r--r--toolkit/components/tooltiptext/tests/browser_bug561623.js33
-rw-r--r--toolkit/components/tooltiptext/tests/browser_bug581947.js107
-rw-r--r--toolkit/components/tooltiptext/tests/browser_input_file_tooltips.js131
-rw-r--r--toolkit/components/tooltiptext/tests/browser_shadow_dom_tooltip.js166
-rw-r--r--toolkit/components/tooltiptext/tests/title_test.svg59
-rw-r--r--toolkit/components/tooltiptext/tests/xul_tooltiptext.xhtml12
9 files changed, 602 insertions, 0 deletions
diff --git a/toolkit/components/tooltiptext/tests/browser.toml b/toolkit/components/tooltiptext/tests/browser.toml
new file mode 100644
index 0000000000..189f880be2
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser.toml
@@ -0,0 +1,16 @@
+[DEFAULT]
+
+["browser_bug329212.js"]
+support-files = ["title_test.svg"]
+
+["browser_bug331772_xul_tooltiptext_in_html.js"]
+support-files = ["xul_tooltiptext.xhtml"]
+
+["browser_bug561623.js"]
+
+["browser_bug581947.js"]
+
+["browser_input_file_tooltips.js"]
+skip-if = ["os == 'win' && os_version == '10.0'"] # Permafail on Win 10 (bug 1400368)
+
+["browser_shadow_dom_tooltip.js"]
diff --git a/toolkit/components/tooltiptext/tests/browser_bug329212.js b/toolkit/components/tooltiptext/tests/browser_bug329212.js
new file mode 100644
index 0000000000..d669e60c26
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_bug329212.js
@@ -0,0 +1,48 @@
+"use strict";
+
+add_task(async function () {
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: "http://mochi.test:8888/browser/toolkit/components/tooltiptext/tests/title_test.svg",
+ },
+ async function (browser) {
+ await SpecialPowers.spawn(browser, [""], function () {
+ let tttp = Cc[
+ "@mozilla.org/embedcomp/default-tooltiptextprovider;1"
+ ].getService(Ci.nsITooltipTextProvider);
+ function checkElement(id, expectedTooltipText) {
+ let el = content.document.getElementById(id);
+ let textObj = {};
+ let shouldHaveTooltip = expectedTooltipText !== null;
+ is(
+ tttp.getNodeText(el, textObj, {}),
+ shouldHaveTooltip,
+ "element " +
+ id +
+ " should " +
+ (shouldHaveTooltip ? "" : "not ") +
+ "have a tooltip"
+ );
+ if (shouldHaveTooltip) {
+ is(
+ textObj.value,
+ expectedTooltipText,
+ "element " + id + " should have the right tooltip text"
+ );
+ }
+ }
+ checkElement("svg1", "This is a non-root SVG element title");
+ checkElement("text1", "\n\n\n This is a title\n\n ");
+ checkElement("text2", null);
+ checkElement("text3", null);
+ checkElement("link1", "\n This is a title\n ");
+ checkElement("text4", "\n This is a title\n ");
+ checkElement("link2", null);
+ checkElement("link3", "This is an xlink:title attribute");
+ checkElement("link4", "This is an xlink:title attribute");
+ checkElement("text5", null);
+ });
+ }
+ );
+});
diff --git a/toolkit/components/tooltiptext/tests/browser_bug331772_xul_tooltiptext_in_html.js b/toolkit/components/tooltiptext/tests/browser_bug331772_xul_tooltiptext_in_html.js
new file mode 100644
index 0000000000..61c50e5422
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_bug331772_xul_tooltiptext_in_html.js
@@ -0,0 +1,30 @@
+/**
+ * Tests that the tooltiptext attribute is used for XUL elements in an HTML doc.
+ */
+add_task(async function () {
+ await SpecialPowers.pushPermissions([
+ { type: "allowXULXBL", allow: true, context: "http://mochi.test:8888" },
+ ]);
+
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: "http://mochi.test:8888/browser/toolkit/components/tooltiptext/tests/xul_tooltiptext.xhtml",
+ },
+ async function (browser) {
+ await SpecialPowers.spawn(browser, [""], function () {
+ let textObj = {};
+ let tttp = Cc[
+ "@mozilla.org/embedcomp/default-tooltiptextprovider;1"
+ ].getService(Ci.nsITooltipTextProvider);
+ let xulToolbarButton =
+ content.document.getElementById("xulToolbarButton");
+ ok(
+ tttp.getNodeText(xulToolbarButton, textObj, {}),
+ "should get tooltiptext"
+ );
+ is(textObj.value, "XUL tooltiptext");
+ });
+ }
+ );
+});
diff --git a/toolkit/components/tooltiptext/tests/browser_bug561623.js b/toolkit/components/tooltiptext/tests/browser_bug561623.js
new file mode 100644
index 0000000000..93f68d307f
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_bug561623.js
@@ -0,0 +1,33 @@
+add_task(async function () {
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: "data:text/html,<!DOCTYPE html><html><body><input id='i'></body></html>",
+ },
+ async function (browser) {
+ await SpecialPowers.spawn(browser, [""], function () {
+ let tttp = Cc[
+ "@mozilla.org/embedcomp/default-tooltiptextprovider;1"
+ ].getService(Ci.nsITooltipTextProvider);
+ let i = content.document.getElementById("i");
+
+ ok(
+ !tttp.getNodeText(i, {}, {}),
+ "No tooltip should be shown when @title is null"
+ );
+
+ i.title = "foo";
+ ok(
+ tttp.getNodeText(i, {}, {}),
+ "A tooltip should be shown when @title is not the empty string"
+ );
+
+ i.pattern = "bar";
+ ok(
+ tttp.getNodeText(i, {}, {}),
+ "A tooltip should be shown when @title is not the empty string"
+ );
+ });
+ }
+ );
+});
diff --git a/toolkit/components/tooltiptext/tests/browser_bug581947.js b/toolkit/components/tooltiptext/tests/browser_bug581947.js
new file mode 100644
index 0000000000..6e5eb9ea14
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_bug581947.js
@@ -0,0 +1,107 @@
+function check(aBrowser, aElementName, aBarred, aType) {
+ return SpecialPowers.spawn(
+ aBrowser,
+ [[aElementName, aBarred, aType]],
+ async function ([aElementName, aBarred, aType]) {
+ let e = content.document.createElement(aElementName);
+ let contentElement = content.document.getElementById("content");
+ contentElement.appendChild(e);
+
+ if (aType) {
+ e.type = aType;
+ }
+
+ let tttp = Cc[
+ "@mozilla.org/embedcomp/default-tooltiptextprovider;1"
+ ].getService(Ci.nsITooltipTextProvider);
+ ok(
+ !tttp.getNodeText(e, {}, {}),
+ "No tooltip should be shown when the element is valid"
+ );
+
+ e.setCustomValidity("foo");
+ if (aBarred) {
+ ok(
+ !tttp.getNodeText(e, {}, {}),
+ "No tooltip should be shown when the element is barred from constraint validation"
+ );
+ } else {
+ ok(
+ tttp.getNodeText(e, {}, {}),
+ e.tagName + " A tooltip should be shown when the element isn't valid"
+ );
+ }
+
+ e.setAttribute("title", "");
+ ok(
+ !tttp.getNodeText(e, {}, {}),
+ "No tooltip should be shown if the title attribute is set"
+ );
+
+ e.removeAttribute("title");
+ contentElement.setAttribute("novalidate", "");
+ ok(
+ !tttp.getNodeText(e, {}, {}),
+ "No tooltip should be shown if the novalidate attribute is set on the form owner"
+ );
+ contentElement.removeAttribute("novalidate");
+
+ e.remove();
+ }
+ );
+}
+
+function todo_check(aBrowser, aElementName, aBarred) {
+ return SpecialPowers.spawn(
+ aBrowser,
+ [[aElementName, aBarred]],
+ async function ([aElementName, aBarred]) {
+ let e = content.document.createElement(aElementName);
+ let contentElement = content.document.getElementById("content");
+ contentElement.appendChild(e);
+
+ let caught = false;
+ try {
+ e.setCustomValidity("foo");
+ } catch (e) {
+ caught = true;
+ }
+
+ todo(!caught, "setCustomValidity should exist for " + aElementName);
+
+ e.remove();
+ }
+ );
+}
+
+add_task(async function () {
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: "data:text/html,<!DOCTYPE html><html><body><form id='content'></form></body></html>",
+ },
+ async function (browser) {
+ let testData = [
+ /* element name, barred */
+ ["input", false, null],
+ ["textarea", false, null],
+ ["button", true, "button"],
+ ["button", false, "submit"],
+ ["select", false, null],
+ ["output", true, null],
+ ["fieldset", true, null],
+ ["object", true, null],
+ ];
+
+ for (let data of testData) {
+ await check(browser, data[0], data[1], data[2]);
+ }
+
+ let todo_testData = [["keygen", "false"]];
+
+ for (let data of todo_testData) {
+ await todo_check(browser, data[0], data[1]);
+ }
+ }
+ );
+});
diff --git a/toolkit/components/tooltiptext/tests/browser_input_file_tooltips.js b/toolkit/components/tooltiptext/tests/browser_input_file_tooltips.js
new file mode 100644
index 0000000000..7d6c5043c4
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_input_file_tooltips.js
@@ -0,0 +1,131 @@
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+let tempFile;
+add_setup(async function () {
+ await SpecialPowers.pushPrefEnv({ set: [["ui.tooltipDelay", 0]] });
+ tempFile = createTempFile();
+ registerCleanupFunction(function () {
+ tempFile.remove(true);
+ });
+});
+
+add_task(async function test_singlefile_selected() {
+ await do_test({ value: true, result: "testfile_bug1251809" });
+});
+
+add_task(async function test_title_set() {
+ await do_test({ title: "foo", result: "foo" });
+});
+
+add_task(async function test_nofile_selected() {
+ await do_test({ result: "No file selected." });
+});
+
+add_task(async function test_multipleset_nofile_selected() {
+ await do_test({ multiple: true, result: "No files selected." });
+});
+
+add_task(async function test_requiredset() {
+ await do_test({ required: true, result: "Please select a file." });
+});
+
+async function do_test(test) {
+ info(`starting test ${JSON.stringify(test)}`);
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+ info("Moving mouse out of the way.");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(
+ tab.linkedBrowser,
+ 300,
+ 300
+ );
+
+ info("creating input field");
+ await SpecialPowers.spawn(tab.linkedBrowser, [test], async function (test) {
+ let doc = content.document;
+ let input = doc.createElement("input");
+ doc.body.appendChild(input);
+ input.id = "test_input";
+ input.setAttribute("style", "position: absolute; top: 0; left: 0;");
+ input.type = "file";
+ if (test.title) {
+ input.setAttribute("title", test.title);
+ }
+ if (test.multiple) {
+ input.multiple = true;
+ }
+ if (test.required) {
+ input.required = true;
+ }
+ });
+
+ if (test.value) {
+ info("Creating mock filepicker to select files");
+ let MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window);
+ MockFilePicker.returnValue = MockFilePicker.returnOK;
+ MockFilePicker.displayDirectory = FileUtils.getDir("TmpD", []);
+ MockFilePicker.setFiles([tempFile]);
+ MockFilePicker.afterOpenCallback = MockFilePicker.cleanup;
+
+ try {
+ // Open the File Picker dialog (MockFilePicker) to select
+ // the files for the test.
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "#test_input",
+ {},
+ tab.linkedBrowser
+ );
+ info("Waiting for the input to have the requisite files");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
+ let input = content.document.querySelector("#test_input");
+ await ContentTaskUtils.waitForCondition(
+ () => input.files.length,
+ "The input should have at least one file selected"
+ );
+ info(`The input has ${input.files.length} file(s) selected.`);
+ });
+ } catch (e) {}
+ } else {
+ info("No real file selection required.");
+ }
+
+ let awaitTooltipOpen = new Promise(resolve => {
+ let tooltipId = Services.appinfo.browserTabsRemoteAutostart
+ ? "remoteBrowserTooltip"
+ : "aHTMLTooltip";
+ let tooltip = document.getElementById(tooltipId);
+ tooltip.addEventListener(
+ "popupshown",
+ function (event) {
+ resolve(event.target);
+ },
+ { once: true }
+ );
+ });
+ info("Initial mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
+ info("Waiting");
+ await new Promise(resolve => setTimeout(resolve, 400));
+ info("Second mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
+ info("Waiting for tooltip to open");
+ let tooltip = await awaitTooltipOpen;
+
+ is(
+ tooltip.getAttribute("label"),
+ test.result,
+ "tooltip label should match expectation"
+ );
+
+ info("Closing tab");
+ BrowserTestUtils.removeTab(tab);
+}
+
+function createTempFile() {
+ let file = FileUtils.getDir("TmpD", []);
+ file.append("testfile_bug1251809");
+ file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
+ return file;
+}
diff --git a/toolkit/components/tooltiptext/tests/browser_shadow_dom_tooltip.js b/toolkit/components/tooltiptext/tests/browser_shadow_dom_tooltip.js
new file mode 100644
index 0000000000..50386e07e2
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/browser_shadow_dom_tooltip.js
@@ -0,0 +1,166 @@
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+add_setup(async function () {
+ await SpecialPowers.pushPrefEnv({ set: [["ui.tooltipDelay", 0]] });
+});
+
+add_task(async function test_title_in_shadow_dom() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+ info("Moving mouse out of the way.");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(
+ tab.linkedBrowser,
+ 300,
+ 300
+ );
+
+ info("creating host");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
+ let doc = content.document;
+ let host = doc.createElement("div");
+ doc.body.appendChild(host);
+ host.setAttribute("style", "position: absolute; top: 0; left: 0;");
+ var sr = host.attachShadow({ mode: "closed" });
+ sr.innerHTML =
+ "<div title='shadow' style='width: 200px; height: 200px;'>shadow</div>";
+ });
+
+ let awaitTooltipOpen = new Promise(resolve => {
+ let tooltipId = Services.appinfo.browserTabsRemoteAutostart
+ ? "remoteBrowserTooltip"
+ : "aHTMLTooltip";
+ let tooltip = document.getElementById(tooltipId);
+ tooltip.addEventListener(
+ "popupshown",
+ function (event) {
+ resolve(event.target);
+ },
+ { once: true }
+ );
+ });
+ info("Initial mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
+ info("Waiting");
+ await new Promise(resolve => setTimeout(resolve, 400));
+ info("Second mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
+ info("Waiting for tooltip to open");
+ let tooltip = await awaitTooltipOpen;
+
+ is(
+ tooltip.getAttribute("label"),
+ "shadow",
+ "tooltip label should match expectation"
+ );
+
+ info("Closing tab");
+ BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_title_in_light_dom() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+ info("Moving mouse out of the way.");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(
+ tab.linkedBrowser,
+ 300,
+ 300
+ );
+
+ info("creating host");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
+ let doc = content.document;
+ let host = doc.createElement("div");
+ host.title = "light";
+ doc.body.appendChild(host);
+ host.setAttribute("style", "position: absolute; top: 0; left: 0;");
+ var sr = host.attachShadow({ mode: "closed" });
+ sr.innerHTML = "<div style='width: 200px; height: 200px;'>shadow</div>";
+ });
+
+ let awaitTooltipOpen = new Promise(resolve => {
+ let tooltipId = Services.appinfo.browserTabsRemoteAutostart
+ ? "remoteBrowserTooltip"
+ : "aHTMLTooltip";
+ let tooltip = document.getElementById(tooltipId);
+ tooltip.addEventListener(
+ "popupshown",
+ function (event) {
+ resolve(event.target);
+ },
+ { once: true }
+ );
+ });
+ info("Initial mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
+ info("Waiting");
+ await new Promise(resolve => setTimeout(resolve, 400));
+ info("Second mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
+ info("Waiting for tooltip to open");
+ let tooltip = await awaitTooltipOpen;
+
+ is(
+ tooltip.getAttribute("label"),
+ "light",
+ "tooltip label should match expectation"
+ );
+
+ info("Closing tab");
+ BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_title_through_slot() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+ info("Moving mouse out of the way.");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(
+ tab.linkedBrowser,
+ 300,
+ 300
+ );
+
+ info("creating host");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
+ let doc = content.document;
+ let host = doc.createElement("div");
+ host.title = "light";
+ host.innerHTML = "<div style='width: 200px; height: 200px;'>light</div>";
+ doc.body.appendChild(host);
+ host.setAttribute("style", "position: absolute; top: 0; left: 0;");
+ var sr = host.attachShadow({ mode: "closed" });
+ sr.innerHTML =
+ "<div title='shadow' style='width: 200px; height: 200px;'><slot></slot></div>";
+ });
+
+ let awaitTooltipOpen = new Promise(resolve => {
+ let tooltipId = Services.appinfo.browserTabsRemoteAutostart
+ ? "remoteBrowserTooltip"
+ : "aHTMLTooltip";
+ let tooltip = document.getElementById(tooltipId);
+ tooltip.addEventListener(
+ "popupshown",
+ function (event) {
+ resolve(event.target);
+ },
+ { once: true }
+ );
+ });
+ info("Initial mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 50, 5);
+ info("Waiting");
+ await new Promise(resolve => setTimeout(resolve, 400));
+ info("Second mouse move");
+ await EventUtils.synthesizeAndWaitNativeMouseMove(tab.linkedBrowser, 70, 5);
+ info("Waiting for tooltip to open");
+ let tooltip = await awaitTooltipOpen;
+
+ is(
+ tooltip.getAttribute("label"),
+ "shadow",
+ "tooltip label should match expectation"
+ );
+
+ info("Closing tab");
+ BrowserTestUtils.removeTab(tab);
+});
diff --git a/toolkit/components/tooltiptext/tests/title_test.svg b/toolkit/components/tooltiptext/tests/title_test.svg
new file mode 100644
index 0000000000..80390a3cca
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/title_test.svg
@@ -0,0 +1,59 @@
+<svg width="640px" height="480px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <title>This is a root SVG element's title</title>
+ <foreignObject>
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <body>
+ <svg xmlns="http://www.w3.org/2000/svg" id="svg1">
+ <title>This is a non-root SVG element title</title>
+ </svg>
+ </body>
+ </html>
+ </foreignObject>
+ <text id="text1" x="10px" y="32px" font-size="24px">
+ This contains only &lt;title&gt;
+ <title>
+
+
+ This is a title
+
+ </title>
+ </text>
+ <text id="text2" x="10px" y="96px" font-size="24px">
+ This contains only &lt;desc&gt;
+ <desc>This is a desc</desc>
+ </text>
+ <text id="text3" x="10px" y="128px" font-size="24px" title="ignored for SVG">
+ This contains nothing.
+ </text>
+ <a id="link1" href="#">
+ This link contains &lt;title&gt;
+ <title>
+ This is a title
+ </title>
+ <text id="text4" x="10px" y="192px" font-size="24px">
+ </text>
+ </a>
+ <a id="link2" href="#">
+ <text x="10px" y="192px" font-size="24px">
+ This text contains &lt;title&gt;
+ <title>
+ This is a title
+ </title>
+ </text>
+ </a>
+ <a id="link3" href="#" xlink:title="This is an xlink:title attribute">
+ <text x="10px" y="224px" font-size="24px">
+ This link contains &lt;title&gt; &amp; xlink:title attr.
+ <title>This is a title</title>
+ </text>
+ </a>
+ <a id="link4" href="#" xlink:title="This is an xlink:title attribute">
+ <text x="10px" y="256px" font-size="24px">
+ This link contains xlink:title attr.
+ </text>
+ </a>
+ <text id="text5" x="10px" y="160px" font-size="24px"
+ xlink:title="This is an xlink:title attribute but it isn't on a link" >
+ This contains nothing.
+ </text>
+</svg>
diff --git a/toolkit/components/tooltiptext/tests/xul_tooltiptext.xhtml b/toolkit/components/tooltiptext/tests/xul_tooltiptext.xhtml
new file mode 100644
index 0000000000..8288ffc5fc
--- /dev/null
+++ b/toolkit/components/tooltiptext/tests/xul_tooltiptext.xhtml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <xul:toolbox xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <toolbar>
+ <toolbarbutton id="xulToolbarButton"
+ tooltiptext="XUL tooltiptext"
+ title="XUL title"/>
+ </toolbar>
+ </xul:toolbox>
+</html>