/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test for Bug 306937 - "Bookmark This Link..." context menu should not
* add spurious whitespace characters to bookmark names when links contain
* inline HTML formatting elements.
*/
add_task(async function test_bookmark_link_text_with_inline_formatting() {
const TEST_PAGE = `data:text/html,
Plain text link
Component
@username
Multiple Spans
Text bold more
Text
Normal text here
Text with multiple spaces
`;
await BrowserTestUtils.withNewTab(TEST_PAGE, async browser => {
const tests = [
{ selector: "#link1", expected: "Plain text link" },
{ selector: "#link2", expected: "Component" },
{ selector: "#link3", expected: "@username" },
{ selector: "#link4", expected: "Multiple Spans" },
{ selector: "#link5", expected: "Text bold more" },
{ selector: "#link6", expected: "Icon Text" },
{ selector: "#link7", expected: "Normal text here" },
{ selector: "#link8", expected: "Text with multiple spaces" },
];
for (const test of tests) {
let contextMenu = document.getElementById("contentAreaContextMenu");
let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
BrowserTestUtils.synthesizeMouseAtCenter(
test.selector,
{ type: "contextmenu", button: 2 },
browser
);
await popupShown;
// Get the linkText from the context menu's context
let linkText = gContextMenu.linkTextStr;
is(
linkText,
test.expected,
`Link text for ${test.selector} should be "${test.expected}" without spurious spaces`
);
let popupHidden = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
contextMenu.hidePopup();
await popupHidden;
}
});
});