Bug 232598 - Return null for unset attributes in XUL. r=smaug,devtools-reviewers,omc-reviewers,zombie,nchevobbe,settings-reviewers,application-update-reviewers,credential-management-reviewers,mossop,aminomancer,bytesized,issammani,sessionstore-reviewers,dao

I just got bit by this in bug 1873833, let's just fix it. There isn't
all that much stuff depending on it anymore.

Differential Revision: https://phabricator.services.mozilla.com/D204496
This commit is contained in:
Emilio Cobos Álvarez 2024-03-18 09:15:07 +00:00
parent e7f43ecf6f
commit 0e321f79be
64 changed files with 188 additions and 177 deletions

View file

@ -8658,7 +8658,7 @@ function switchToTabHavingURI(
ignoreQueryString || replaceQueryString,
ignoreFragmentWhenComparing
);
let browserUserContextId = browser.getAttribute("usercontextid");
let browserUserContextId = browser.getAttribute("usercontextid") || "";
if (aUserContextId != null && aUserContextId != browserUserContextId) {
continue;
}

View file

@ -28,7 +28,7 @@ add_task(async () => {
is(browser.mIconURL, null, "Should have blanked the icon.");
is(
gBrowser.getTabForBrowser(browser).getAttribute("image"),
"",
null,
"Should have blanked the tab icon."
);
}

View file

@ -244,12 +244,12 @@ async function assertMixedContentBlockingState(tabbrowser, states = {}) {
);
gIdentityHandler._identityIconBox.click();
await promisePanelOpen;
let popupAttr = doc
.getElementById("identity-popup")
.getAttribute("mixedcontent");
let bodyAttr = doc
let popupAttr =
doc.getElementById("identity-popup").getAttribute("mixedcontent") || "";
let bodyAttr =
doc
.getElementById("identity-popup-securityView-extended-info")
.getAttribute("mixedcontent");
.getAttribute("mixedcontent") || "";
is(
popupAttr.includes("active-loaded"),

View file

@ -772,7 +772,7 @@ function checkSyncNowButtons(syncing, tooltip = null) {
for (const syncButton of syncButtons) {
is(
syncButton.getAttribute("syncstatus"),
syncing ? "active" : "",
syncing ? "active" : null,
"button active has the right value"
);
if (tooltip) {

View file

@ -119,7 +119,7 @@ async function waitForDialog(doConfirmPrompt, crossDomain, prefEnabled) {
} else {
Assert.equal(
dialog._overlay.getAttribute("hideContent"),
"",
null,
"Dialog overlay does not hide the current sites content"
);
Assert.equal(
@ -137,7 +137,7 @@ async function waitForDialog(doConfirmPrompt, crossDomain, prefEnabled) {
} else {
Assert.equal(
dialog._overlay.getAttribute("hideContent"),
"",
null,
"Dialog overlay does not hide the current sites content"
);
Assert.equal(

View file

@ -93,10 +93,10 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() {
mutedTab.toggleMuteAudio();
gBrowser.hideTab(hiddenTab);
is(lazyTab.linkedPanel, "", "lazyTab is lazy");
is(hiddenTab.linkedPanel, "", "hiddenTab is lazy");
is(mutedTab.linkedPanel, "", "mutedTab is lazy");
is(normalTab.linkedPanel, "", "normalTab is lazy");
is(lazyTab.linkedPanel, null, "lazyTab is lazy");
is(hiddenTab.linkedPanel, null, "hiddenTab is lazy");
is(mutedTab.linkedPanel, null, "mutedTab is lazy");
is(normalTab.linkedPanel, null, "normalTab is lazy");
ok(mutedTab.linkedBrowser.audioMuted, "mutedTab is muted");
ok(hiddenTab.hidden, "hiddenTab is hidden");
@ -117,7 +117,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() {
});
gBrowser.swapBrowsersAndCloseOther(lazyTab, mutedTab);
tabEventTracker.checkExpectations();
is(lazyTab.linkedPanel, "", "muted lazyTab is still lazy");
is(lazyTab.linkedPanel, null, "muted lazyTab is still lazy");
ok(lazyTab.linkedBrowser.audioMuted, "muted lazyTab is now muted");
ok(!lazyTab.hidden, "muted lazyTab is not hidden");
@ -133,7 +133,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() {
});
gBrowser.swapBrowsersAndCloseOther(lazyTab, hiddenTab);
tabEventTracker.checkExpectations();
is(lazyTab.linkedPanel, "", "hidden lazyTab is still lazy");
is(lazyTab.linkedPanel, null, "hidden lazyTab is still lazy");
ok(!lazyTab.linkedBrowser.audioMuted, "hidden lazyTab is not muted any more");
ok(lazyTab.hidden, "hidden lazyTab has been hidden");
@ -149,7 +149,7 @@ add_task(async function test_hidden_muted_lazy_tabs_and_swapping() {
});
gBrowser.swapBrowsersAndCloseOther(lazyTab, normalTab);
tabEventTracker.checkExpectations();
is(lazyTab.linkedPanel, "", "normal lazyTab is still lazy");
is(lazyTab.linkedPanel, null, "normal lazyTab is still lazy");
ok(!lazyTab.linkedBrowser.audioMuted, "normal lazyTab is not muted any more");
ok(!lazyTab.hidden, "normal lazyTab is not hidden any more");

View file

@ -61,9 +61,9 @@ add_task(async function testLazyTabs() {
await triggerClickOn(oldTabs[i], { ctrlKey: true });
}
isnot(oldTabs[0].linkedPanel, "", `Old tab 0 shouldn't be lazy`);
isnot(oldTabs[0].linkedPanel, null, `Old tab 0 shouldn't be lazy`);
for (let i = 1; i < numTabs; ++i) {
is(oldTabs[i].linkedPanel, "", `Old tab ${i} should be lazy`);
is(oldTabs[i].linkedPanel, null, `Old tab ${i} should be lazy`);
}
is(gBrowser.multiSelectedTabsCount, numTabs, `${numTabs} multiselected tabs`);
@ -79,11 +79,11 @@ add_task(async function testLazyTabs() {
if (i == 0) {
isnot(
oldTab.linkedPanel,
"",
null,
`Old tab ${i} should continue not being lazy`
);
} else if (i > 0) {
is(oldTab.linkedPanel, "", `Old tab ${i} should continue being lazy`);
is(oldTab.linkedPanel, null, `Old tab ${i} should continue being lazy`);
} else {
return;
}
@ -101,9 +101,13 @@ add_task(async function testLazyTabs() {
await tabsMoved;
let newTabs = newWindow.gBrowser.tabs;
isnot(newTabs[0].linkedPanel, "", `New tab 0 should continue not being lazy`);
isnot(
newTabs[0].linkedPanel,
null,
`New tab 0 should continue not being lazy`
);
for (let i = 1; i < numTabs; ++i) {
is(newTabs[i].linkedPanel, "", `New tab ${i} should continue being lazy`);
is(newTabs[i].linkedPanel, null, `New tab ${i} should continue being lazy`);
}
is(

View file

@ -12,7 +12,7 @@ function test() {
is(
elemAttr("key_close", "disabled"),
"",
null,
"key_closed should always be enabled"
);
is(

View file

@ -57,7 +57,7 @@ add_task(async function () {
);
is(
tooltip.getAttribute("position"),
"",
null,
"tooltip position attribute for tab"
);

View file

@ -87,7 +87,7 @@ async function backgroundUpdateTest(url, id, checkIconFn) {
let addonId = addon.id;
ok(addon, "Addon was installed");
is(getBadgeStatus(), "", "Should not start out with an addon alert badge");
is(getBadgeStatus(), null, "Should not start out with an addon alert badge");
// Trigger an update check and wait for the update for this addon
// to be downloaded.
@ -156,7 +156,7 @@ async function backgroundUpdateTest(url, id, checkIconFn) {
BrowserTestUtils.removeTab(tab);
// Alert badge and hamburger menu items should be gone
is(getBadgeStatus(), "", "Addon alert badge should be gone");
is(getBadgeStatus(), null, "Addon alert badge should be gone");
await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
@ -205,7 +205,7 @@ async function backgroundUpdateTest(url, id, checkIconFn) {
BrowserTestUtils.removeTab(tab);
is(getBadgeStatus(), "", "Addon alert badge should be gone");
is(getBadgeStatus(), null, "Addon alert badge should be gone");
await addon.uninstall();
await SpecialPowers.popPrefEnv();

View file

@ -81,7 +81,7 @@ async function testNoPrompt(origUrl, id) {
await updatePromise;
// There should be no notifications about the update
is(getBadgeStatus(), "", "Should not have addon alert badge");
is(getBadgeStatus(), null, "Should not have addon alert badge");
await gCUITestUtils.openMainMenu();
let addons = PanelUI.addonNotificationContainer;

View file

@ -58,7 +58,7 @@ var gTests = [
);
is(
gBrowser.selectedTab.getAttribute("sharing"),
"",
null,
"the new tab doesn't have the 'sharing' attribute"
);
is(
@ -89,7 +89,7 @@ var gTests = [
await TestUtils.waitForCondition(() => !tab.getAttribute("sharing"));
is(
tab.getAttribute("sharing"),
"",
null,
"the tab no longer has the 'sharing' attribute after closing the stream"
);
}

View file

@ -294,7 +294,7 @@ function closeMenus(node) {
* to check if the close command key was pressed in aEvent.
*/
function eventMatchesKey(aEvent, aKey) {
let keyPressed = aKey.getAttribute("key").toLowerCase();
let keyPressed = (aKey.getAttribute("key") || "").toLowerCase();
let keyModifiers = aKey.getAttribute("modifiers");
let modifiers = ["Alt", "Control", "Meta", "Shift"];
@ -341,7 +341,7 @@ function gatherTextUnder(root) {
} else if (HTMLImageElement.isInstance(node)) {
// If it has an "alt" attribute, add that.
var altText = node.getAttribute("alt");
if (altText && altText != "") {
if (altText) {
text += " " + altText;
}
}

View file

@ -35,7 +35,7 @@ add_task(async function () {
createLazyBrowser: true,
});
Assert.equal(lazyTab.linkedPanel, "", "Tab is lazy");
Assert.equal(lazyTab.linkedPanel, null, "Tab is lazy");
let tabLoaded = new Promise(resolve => {
gBrowser.addTabsProgressListener({
async onLocationChange(aBrowser) {

View file

@ -93,7 +93,7 @@ add_task(async function test() {
openURIFromExternal(HOST_EXAMPLE.spec + "?new");
is(
gBrowser.selectedTab.getAttribute("usercontextid"),
"",
null,
"opener flow with default user context ID forced by pref"
);
});

View file

@ -549,7 +549,7 @@ add_task(async function custom_context_menus() {
await startCustomizing();
is(
widget.getAttribute("context"),
"",
null,
"Should not have own context menu in the toolbar now that we're customizing."
);
is(
@ -562,7 +562,7 @@ add_task(async function custom_context_menus() {
simulateItemDrag(widget, panel);
is(
widget.getAttribute("context"),
"",
null,
"Should not have own context menu when in the panel."
);
is(
@ -577,7 +577,7 @@ add_task(async function custom_context_menus() {
);
is(
widget.getAttribute("context"),
"",
null,
"Should not have own context menu when back in toolbar because we're still customizing."
);
is(

View file

@ -9,7 +9,7 @@ add_task(async function open_customize_mode_in_lazy_tab() {
});
gCustomizeMode.setTab(tab);
is(tab.linkedPanel, "", "Tab should be lazy");
is(tab.linkedPanel, null, "Tab should be lazy");
let title = gNavigatorBundle.getFormattedString("customizeMode.tabTitle", [
document.getElementById("bundle_brand").getString("brandShortName"),

View file

@ -378,7 +378,7 @@ add_task(async function () {
// There is a single node saying there's no tabs for the client.
node = node.nextElementSibling;
is(node.nodeName, "label", "node is a label");
is(node.getAttribute("itemtype"), "", "node is neither a tab nor a client");
is(node.getAttribute("itemtype"), null, "node is neither a tab nor a client");
node = node.nextElementSibling;
is(node, null, "no more siblings");

View file

@ -184,7 +184,11 @@ async function runTests(options) {
is(getListStyleImage(button), details.icon, "icon URL is correct");
is(button.getAttribute("tooltiptext"), title, "image title is correct");
is(button.getAttribute("label"), title, "image label is correct");
is(button.getAttribute("badge"), details.badge, "badge text is correct");
is(
button.getAttribute("badge") || "",
details.badge,
"badge text is correct"
);
is(
button.getAttribute("disabled") == "true",
!details.enabled,

View file

@ -269,7 +269,7 @@ add_task(async function test_manifest_without_icons() {
let items = menu.getElementsByAttribute("label", "first item");
is(items.length, 1, "Found first item");
// manifest.json does not declare icons, so the root menu item shouldn't have an icon either.
is(items[0].getAttribute("image"), "", "Root menu must not have an icon");
is(items[0].getAttribute("image"), null, "Root menu must not have an icon");
await closeExtensionContextMenu(items[0]);
await extension.awaitMessage("added-second-item");
@ -281,7 +281,7 @@ add_task(async function test_manifest_without_icons() {
is(items.length, 1, "Auto-generated root item exists");
is(
items[0].getAttribute("image"),
"",
null,
"Auto-generated menu root must not have an icon"
);
@ -464,7 +464,7 @@ add_task(async function test_child_icon_update() {
contextMenuChild2 = contextMenu.getElementsByAttribute("label", "child2")[0];
is(
contextMenuChild2.getAttribute("image"),
"",
null,
"Second child should not have an icon"
);

View file

@ -1168,7 +1168,7 @@ var ViewMenu = {
menuitem.setAttribute("type", "radio");
menuitem.setAttribute("name", "columns");
// This column is the sort key. Its item is checked.
if (column.getAttribute("sortDirection") != "") {
if (column.hasAttribute("sortDirection")) {
menuitem.setAttribute("checked", "true");
}
} else if (type == "checkbox") {

View file

@ -131,14 +131,14 @@ let checkContextMenu = async (cbfunc, optionItems, doc = document) => {
if (expectedOptionItems.includes("placesContext_open")) {
Assert.equal(
doc.getElementById("placesContext_open").getAttribute("default"),
loadBookmarksInNewTab ? "" : "true",
loadBookmarksInNewTab ? null : "true",
`placesContext_open has the correct "default" attribute when loadBookmarksInTabs = ${loadBookmarksInNewTab}`
);
}
if (expectedOptionItems.includes("placesContext_open:newtab")) {
Assert.equal(
doc.getElementById("placesContext_open:newtab").getAttribute("default"),
loadBookmarksInNewTab ? "true" : "",
loadBookmarksInNewTab ? "true" : null,
`placesContext_open:newtab has the correct "default" attribute when loadBookmarksInTabs = ${loadBookmarksInNewTab}`
);
}

View file

@ -72,7 +72,11 @@ function checkPanelClosed() {
let pocketButton = document.getElementById("save-to-pocket-button");
// Something should have closed the Pocket panel, icon should no longer be red.
is(pocketButton.open, false, "Pocket button is closed");
is(pocketButton.getAttribute("pocketed"), "", "Pocket item is not pocketed");
is(
pocketButton.getAttribute("pocketed"),
null,
"Pocket item is not pocketed"
);
}
test_runner(async function test_pocketButtonState_changeTabs({ sandbox }) {

View file

@ -335,10 +335,12 @@ add_task(async function sortingCheck() {
"Number of items should not change."
);
for (let i = 0; i < siteItems.length - 1; ++i) {
let aType = siteItems[i].getAttribute("actionDescription").toLowerCase();
let bType = siteItems[i + 1]
.getAttribute("actionDescription")
.toLowerCase();
let aType = (
siteItems[i].getAttribute("actionDescription") || ""
).toLowerCase();
let bType = (
siteItems[i + 1].getAttribute("actionDescription") || ""
).toLowerCase();
let result = 0;
if (aType > bType) {
result = 1;
@ -375,10 +377,12 @@ add_task(async function sortingCheck() {
"Number of items should not change."
);
for (let i = 0; i < siteItems.length - 1; ++i) {
let aType = siteItems[i].getAttribute("typeDescription").toLowerCase();
let bType = siteItems[i + 1]
.getAttribute("typeDescription")
.toLowerCase();
let aType = (
siteItems[i].getAttribute("typeDescription") || ""
).toLowerCase();
let bType = (
siteItems[i + 1].getAttribute("typeDescription") || ""
).toLowerCase();
let result = 0;
if (aType > bType) {
result = 1;

View file

@ -1021,7 +1021,7 @@ add_task(async function testDisableTPCheckBoxDisablesEmailTP() {
// Verify the checkbox is unchecked after clicking.
is(
tpCheckbox.getAttribute("checked"),
"",
null,
"Tracking protection checkbox is unchecked"
);

View file

@ -173,7 +173,7 @@ async function close_subdialog_and_test_generic_end_state(
);
Assert.equal(
frame.getAttribute("style"),
"",
null,
"inline styles should be cleared"
);
Assert.equal(

View file

@ -3635,7 +3635,7 @@ var SessionStoreInternal = {
}
// Create a new tab.
let userContextId = aTab.getAttribute("usercontextid");
let userContextId = aTab.getAttribute("usercontextid") || "";
let tabOptions = {
userContextId,

View file

@ -14,7 +14,7 @@ add_task(async function () {
await promiseBrowserLoaded(browser);
let tab2 = gBrowser.duplicateTab(tab);
Assert.equal(tab2.getAttribute("usercontextid"), i);
Assert.equal(tab2.getAttribute("usercontextid") || "", i);
let browser2 = tab2.linkedBrowser;
await promiseTabRestored(tab2);

View file

@ -81,7 +81,7 @@ add_UITour_task(async function test_info_buttons_1() {
);
is(
buttons.children[0].getAttribute("image"),
"",
null,
"Text should have no image"
);
is(buttons.children[0].className, "", "Text should have no class");
@ -94,7 +94,7 @@ add_UITour_task(async function test_info_buttons_1() {
);
is(
buttons.children[1].getAttribute("image"),
"",
null,
"Link should have no image"
);
is(buttons.children[1].className, "button-link", "Check link class");
@ -107,7 +107,7 @@ add_UITour_task(async function test_info_buttons_1() {
);
is(
buttons.children[2].getAttribute("image"),
"",
null,
"First button should have no image"
);
is(buttons.children[2].className, "", "Button 1 should have no class");
@ -173,7 +173,7 @@ add_UITour_task(async function test_info_buttons_2() {
);
is(
buttons.children[1].getAttribute("image"),
"",
null,
"Link should have no image"
);
ok(
@ -188,7 +188,7 @@ add_UITour_task(async function test_info_buttons_2() {
);
is(
buttons.children[2].getAttribute("image"),
"",
null,
"First button should have no image"
);

View file

@ -2,7 +2,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
async function testVal(aExpected, overflowSide = "") {
async function testVal(aExpected, overflowSide = null) {
info(`Testing ${aExpected}`);
try {
gURLBar.setURI(makeURI(aExpected));

View file

@ -276,7 +276,7 @@ async function typeAndCommand(eventType, details = {}) {
async function triggerCommand(eventType, details = {}) {
Assert.equal(
await UrlbarTestUtils.promiseUserContextId(window),
gBrowser.selectedTab.getAttribute("usercontextid"),
gBrowser.selectedTab.getAttribute("usercontextid") || "",
"userContextId must be the same as the originating tab"
);

View file

@ -11,7 +11,7 @@ var gItemsToTest = {
};
function expectedAttributeValueFromPrefs(prefs) {
return prefs.every(pref => Services.prefs.getBoolPref(pref)) ? "" : "true";
return prefs.every(pref => Services.prefs.getBoolPref(pref)) ? null : "true";
}
function checkItem(el, prefs) {

View file

@ -19,7 +19,7 @@ add_task(async function () {
);
is(
tab.linkedBrowser.getAttribute("remote"),
"",
null,
"And running in parent process"
);

View file

@ -88,12 +88,12 @@ add_task(async function () {
cmdCopy = searchContextMenu.querySelector("#editmenu-copy");
cmdPaste = searchContextMenu.querySelector("#editmenu-paste");
is(cmdUndo.getAttribute("disabled"), "", "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), "", "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
is(cmdUndo.getAttribute("disabled"), null, "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), null, "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), null, "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), null, "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), null, "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), null, "cmdPaste is enabled");
onContextMenuClose = toolbox.once("menu-close");
searchContextMenu.hidePopup();

View file

@ -86,12 +86,12 @@ add_task(async function () {
cmdCopy = searchContextMenu.querySelector("#editmenu-copy");
cmdPaste = searchContextMenu.querySelector("#editmenu-paste");
is(cmdUndo.getAttribute("disabled"), "", "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), "", "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
is(cmdUndo.getAttribute("disabled"), null, "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), null, "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), null, "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), null, "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), null, "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), null, "cmdPaste is enabled");
const onContextMenuHidden = toolbox.once("menu-close");
searchContextMenu.hidePopup();

View file

@ -96,12 +96,12 @@ add_task(async function () {
cmdCopy = searchContextMenu.querySelector("#editmenu-copy");
cmdPaste = searchContextMenu.querySelector("#editmenu-paste");
is(cmdUndo.getAttribute("disabled"), "", "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), "", "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
is(cmdUndo.getAttribute("disabled"), null, "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), null, "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), null, "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), null, "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), null, "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), null, "cmdPaste is enabled");
const onContextMenuHidden = toolbox.once("menu-close");
searchContextMenu.hidePopup();

View file

@ -42,7 +42,7 @@ add_task(async function () {
await wait(1000);
is(
readerModeButtonEl.getAttribute("readeractive"),
"",
null,
"reader mode wasn't activated"
);
@ -72,7 +72,7 @@ add_task(async function () {
await wait(1000);
is(
readerModeButtonEl.getAttribute("readeractive"),
"",
null,
"reader mode still wasn't activated"
);

View file

@ -1459,15 +1459,9 @@ void Element::GetAttribute(const nsAString& aName, DOMString& aReturn) {
IsHTMLElement() && IsInHTMLDocument() ? eIgnoreCase : eCaseMatters);
if (val) {
val->ToString(aReturn);
} else {
if (IsXULElement()) {
// XXX should be SetDOMStringToNull(aReturn);
// See bug 232598
// aReturn is already empty
} else {
aReturn.SetNull();
}
}
}
bool Element::ToggleAttribute(const nsAString& aName,

View file

@ -55,11 +55,11 @@ SimpleTest.waitForExplicitFinish();
// not when run as a Mochitest plain.
//is(xul_cs.color, "rgb(0, 0, 0)", "xul color " + test);
attrValue = removed ? null : "";
let attrValue = removed ? null : "";
is(xul.id, "", "xul id " + test);
is(xul.getAttribute("id"), "", "xul getAttribute " + test);
is(xul.getAttribute("id"), attrValue, "xul getAttribute " + test);
is($("xul_id"), null, "xul getElementById " + test);
}
@ -149,7 +149,7 @@ SimpleTest.waitForExplicitFinish();
await new Promise(SimpleTest.executeSoon);
if (mutation) {
is(mutation.target, xul, "target is xul");
is(xul.getAttribute("id"), "", "xul no longer has id attr");
is(xul.getAttribute("id"), null, "xul no longer has id attr");
is(xul.id, "", "xul no longer has id");
xul.id = "other_xul_id";
} else {

View file

@ -144,7 +144,7 @@ declTest("test in-process content events are not processed twice", {
"content",
"Should be a content <browser>"
);
is(browser.getAttribute("remotetype"), "", "Should not be remote");
is(browser.getAttribute("remotetype"), null, "Should not be remote");
await testEventProcessedOnce(browser);
},
});
@ -160,8 +160,12 @@ declTest("test in-process chrome events are processed correctly", {
"chrome://mochitests/content/browser/dom/ipc/tests/JSWindowActor/file_dummyChromePage.html"
);
let chromeBrowser = dialog._frame;
is(chromeBrowser.getAttribute("type"), "", "Should be a chrome <browser>");
is(chromeBrowser.getAttribute("remotetype"), "", "Should not be remote");
is(
chromeBrowser.getAttribute("type"),
null,
"Should be a chrome <browser>"
);
is(chromeBrowser.getAttribute("remotetype"), null, "Should not be remote");
await testEventProcessedOnce(chromeBrowser, "dummyChromePage.html");

View file

@ -150,13 +150,13 @@
function basicElementCreateBuiltIn() {
let element = document.createElementNS(XUL_NS, "axulelement", { is: "test-built-in-element" });
ok(element instanceof TestCustomBuiltInElement, "Should be an instance of TestCustomBuiltInElement");
is(element.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
document.querySelector("#content").appendChild(element);
is(element.textContent, "baz", "Should have set the textContent");
let element2 = element.cloneNode(false);
is(element2.localName, "axulelement", "Should see the right tag");
is(element2.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element2.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
is(element2.textContent, "", "Shouldn't have cloned the textContent");
document.querySelector("#content").appendChild(element2);
is(element2.textContent, "baz", "Should have set the textContent");
@ -188,13 +188,13 @@
function subclassElementCreateBuiltIn() {
let element = document.createElementNS(XUL_NS, "menupopup", { is: "test-popup-extend" });
ok(element instanceof TestPopupExtendElement, "Should be an instance of TestPopupExtendElement");
is(element.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
document.querySelector("#content").appendChild(element);
is(element.textContent, "quuz", "Should have set the textContent");
let element2 = element.cloneNode(false);
is(element2.localName, "menupopup", "Should see the right tag");
is(element2.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element2.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
is(element2.textContent, "", "Shouldn't have cloned the textContent");
document.querySelector("#content").appendChild(element2);
is(element2.textContent, "quuz", "Should have set the textContent");
@ -268,13 +268,13 @@
let element = document.createElementNS(XUL_NS, "testwithoutdash", { is: "testwithoutdash-extended" });
ok(element instanceof TestWithoutDashExtended, "Should be an instance of TestWithoutDashExtended");
ok(element instanceof TestWithoutDash, "Should be an instance of TestWithoutDash");
is(element.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
document.querySelector("#content").appendChild(element);
is(element.textContent, "quux", "Should have set the textContent");
let element2 = element.cloneNode(false);
is(element2.localName, "testwithoutdash", "Should see the right tag");
is(element2.getAttribute("is"), "", "The |is| attribute of the created element should not be the extended type.");
is(element2.getAttribute("is"), null, "The |is| attribute of the created element should not be the extended type.");
is(element2.textContent, "", "Shouldn't have cloned the textContent");
document.querySelector("#content").appendChild(element2);
is(element2.textContent, "quux", "Should have set the textContent");

View file

@ -290,7 +290,7 @@ async function testModuleNameHelper(moduleName, acceptButtonShouldBeDisabled) {
let dialogNode = win.document.querySelector("dialog");
Assert.equal(
dialogNode.getAttribute("buttondisabledaccept"),
acceptButtonShouldBeDisabled ? "true" : "", // it's a string
acceptButtonShouldBeDisabled ? "true" : null,
`dialog accept button should ${
acceptButtonShouldBeDisabled ? "" : "not "
}be disabled`

View file

@ -30,7 +30,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "",
password: "abcXYZ",
toggle: "visible",
@ -56,7 +56,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "",
password: "pass-changed",
toggle: "visible",
@ -80,7 +80,7 @@ let testCases = [
doorhanger: {
type: "password-change",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "user1",
password: "autopass-changed",
},
@ -104,7 +104,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "user2",
password: "pass2",
toggle: "visible",
@ -147,7 +147,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "user2",
password: "pass1",
toggle: "visible",
@ -174,7 +174,7 @@ let testCases = [
doorhanger: {
type: "password-change",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "user-saved",
password: "pass2",
toggle: "visible",
@ -198,7 +198,7 @@ let testCases = [
doorhanger: {
type: "password-change",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "user1",
password: "pass1",
toggle: "visible",
@ -244,7 +244,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "",
password: "a",
toggle: "visible",
@ -271,7 +271,7 @@ let testCases = [
doorhanger: {
type: "password-save",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "",
password: "abc",
toggle: "visible",
@ -296,7 +296,7 @@ let testCases = [
doorhanger: {
type: "password-change",
dismissed: true,
anchorExtraAttr: "",
anchorExtraAttr: null,
username: "",
password: "pass",
toggle: "visible",

View file

@ -130,7 +130,7 @@ function assertMenuitems(menuitems, expected) {
elmt =>
!elmt.id.includes("-sep-") &&
!elmt.hidden &&
["", "false"].includes(elmt.getAttribute("disabled"))
[null, "false"].includes(elmt.getAttribute("disabled"))
)
.map(elmt => elmt.id),
expected

View file

@ -69,11 +69,7 @@ TooltipTextProvider.prototype = {
}
if (tipElement.namespaceURI == XUL_NS) {
lookingForSVGTitle = false;
// NOTE: getAttribute behaves differently for XUL so we can't rely on
// it returning null, see bug 232598.
titleText = tipElement.hasAttribute("tooltiptext")
? tipElement.getAttribute("tooltiptext")
: null;
titleText = tipElement.getAttribute("tooltiptext");
} else if (!defView.SVGElement.isInstance(tipElement)) {
lookingForSVGTitle = false;
titleText = tipElement.getAttribute("title");

View file

@ -153,7 +153,7 @@ XULStore.prototype = {
}
const uri = node.ownerDocument.documentURI;
const value = node.getAttribute(attr);
const value = node.getAttribute(attr) || "";
if (node.localName == "window") {
this.log("Persisting attributes to windows is handled by AppWindow.");

View file

@ -732,7 +732,7 @@
}
get label() {
return this.getAttribute("label");
return this.getAttribute("label") || "";
}
set image(val) {
@ -762,9 +762,7 @@
}
get accessKey() {
return this.labelElement
? this.labelElement.accessKey
: this.getAttribute("accesskey");
return this.labelElement?.accessKey || this.getAttribute("accesskey");
}
};
MozElements.BaseTextMixin = BaseTextMixin;

View file

@ -40,7 +40,7 @@ function runTests()
let checkboxLabel = $("checkbox-label");
is(checkboxLabel.control, "checkbox", "checkbox control");
is(checkboxLabel.labeledControlElement, checkbox, "checkbox labeledControlElement");
is(checkbox.accessKey, "", "checkbox accessKey not set");
is(checkbox.accessKey, null, "checkbox accessKey not set");
checkboxLabel.accessKey = "C";
is(checkbox.accessKey, "C", "checkbox accessKey set");

View file

@ -49,10 +49,10 @@ function runTestSet(suffix)
var three = $("three" + suffix);
var four = $("four" + suffix);
checkAttributes(one, "One", "", "", true, false);
checkAttributes(two, "", "", "false", false, false);
checkAttributes(one, "One", null, null, true, false);
checkAttributes(two, null, null, "false", false, false);
checkAttributes(three, "Three", "T", "true", false, false);
checkAttributes(four, "Four", "F", "", false, false);
checkAttributes(four, "Four", "F", null, false, false);
if (isMac && suffix) {
var utils = window.windowUtils;
@ -62,8 +62,8 @@ function runTestSet(suffix)
$("menu" + suffix).open = true;
}
checkAttributes(one, "One", "", "", false, true);
checkAttributes(two, "Cat", "C", "", false, true);
checkAttributes(one, "One", null, null, false, true);
checkAttributes(two, "Cat", "C", null, false, true);
checkAttributes(three, "Dog", "D", "false", true, true);
checkAttributes(four, "Four", "F", "true", false, true);

View file

@ -34,7 +34,7 @@ function runTests()
list.selectedItem = null;
is(list.value, "", "Check list value after setting selectedItem to null");
is(list.getAttribute("label"), "", "Check list label after setting selectedItem to null");
is(list.getAttribute("label"), null, "Check list label after setting selectedItem to null");
// select something again to make sure the label is not already empty
list.selectedIndex = 1;
@ -61,14 +61,14 @@ function runTests()
// set the value to null and test it (bug 408940)
list.value = null;
is(list.value, "", "Check list value after setting value to null");
is(list.getAttribute("label"), "", "Check list label after setting value to null");
is(list.getAttribute("label"), null, "Check list label after setting value to null");
// select something again to make sure the label is not already empty
list.selectedIndex = 1;
// set the value to undefined and test it (bug 408940)
list.value = undefined;
is(list.value, "", "Check list value after setting value to undefined");
is(list.getAttribute("label"), "", "Check list label after setting value to undefined");
is(list.getAttribute("label"), null, "Check list label after setting value to undefined");
// select something again to make sure the label is not already empty
list.selectedIndex = 1;
@ -76,7 +76,7 @@ function runTests()
// and make sure the previous label is removed
list.value = "this does not exist";
is(list.value, "this does not exist", "Check the list value after setting it to something not associated witn an existing menuitem");
is(list.getAttribute("label"), "", "Check that the list label is empty after selecting a nonexistent item");
is(list.getAttribute("label"), null, "Check that the list label is empty after selecting a nonexistent item");
SimpleTest.finish();
}

View file

@ -16,15 +16,19 @@ function ok(condition, message) {
window.arguments[0].SimpleTest.ok(condition, message);
}
function is(a, b, message) {
window.arguments[0].SimpleTest.is(a, b, message);
}
function doSingleTest(param)
{
var exception = null;
try {
document.documentElement.removeAttribute("chromemargin");
document.documentElement.setAttribute("chromemargin", param);
ok(document.
is(document.
documentElement.
getAttribute("chromemargin") == param, "couldn't set/get chromemargin?");
getAttribute("chromemargin"), param, "couldn't set/get chromemargin?");
} catch (ex) {
exception = ex;
}
@ -44,7 +48,7 @@ function runTests()
// test remove
doc.removeAttribute("chromemargin");
ok(doc.getAttribute("chromemargin") == "", "couldn't remove chromemargin?");
is(doc.getAttribute("chromemargin"), null, "couldn't remove chromemargin?");
// we already test these really well in a c++ test in widget
doSingleTest("1,2,3,4");

View file

@ -82,7 +82,7 @@ function runTest()
document.documentElement.appendChild(keyset);
iterateKeys(true, "appended");
var accelText = menuitem => menuitem.getAttribute("acceltext").toLowerCase();
var accelText = menuitem => (menuitem.getAttribute("acceltext") || "").toLowerCase();
$("menubutton").open = true;

View file

@ -363,8 +363,8 @@ function testPopupMovement()
is(screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x");
is(screenY, 100, gTests[gTestIndex] + " (6000, 100) y");
is(popup.getAttribute("left"), "", gTests[gTestIndex] + " left is empty after moving");
is(popup.getAttribute("top"), "", gTests[gTestIndex] + " top is empty after moving");
is(popup.getAttribute("left"), null, gTests[gTestIndex] + " left is empty after moving");
is(popup.getAttribute("top"), null, gTests[gTestIndex] + " top is empty after moving");
popup.setAttribute("left", "80");
popup.setAttribute("top", "82");
[screenX, screenY] = getScreenXY(popup);
@ -387,8 +387,8 @@ function testPopupMovement()
is(screenX, expectedx, gTests[gTestIndex] + " move after set left and top x to -1");
is(screenY, expectedy, gTests[gTestIndex] + " move after set left and top y to -1");
is(popup.getAttribute("left"), "", gTests[gTestIndex] + " left is not set after moving to -1");
is(popup.getAttribute("top"), "", gTests[gTestIndex] + " top is not set after moving to -1");
is(popup.getAttribute("left"), null, gTests[gTestIndex] + " left is not set after moving to -1");
is(popup.getAttribute("top"), null, gTests[gTestIndex] + " top is not set after moving to -1");
popup.hidePopup();
}

View file

@ -321,11 +321,7 @@ function testtag_tree_columns(tree, expectedColumns, testid) {
// check the view's getColumnProperties method
var properties = tree.view.getColumnProperties(column);
var expectedProperties = expectedColumn.properties;
is(
properties,
expectedProperties ? expectedProperties : "",
adjtestid + "getColumnProperties"
);
is(properties, expectedProperties || "", adjtestid + "getColumnProperties");
}
is(columns.getFirstColumn(), columns[0], testid + "getFirstColumn");
@ -2151,12 +2147,12 @@ function convertDOMtoTreeRowInfo(treechildren, level, rowidx) {
for (var c = 0; c < treerow.childNodes.length; c++) {
var cell = treerow.childNodes[c];
cellInfo.push({
label: "" + cell.getAttribute("label"),
value: cell.getAttribute("value"),
properties: cell.getAttribute("properties"),
label: cell.getAttribute("label") || "",
value: cell.getAttribute("value") || "",
properties: cell.getAttribute("properties") || "",
editable: cell.getAttribute("editable") != "false",
selectable: cell.getAttribute("selectable") != "false",
image: cell.getAttribute("src"),
image: cell.getAttribute("src") || "",
mode: cell.hasAttribute("mode")
? parseInt(cell.getAttribute("mode"))
: 3,
@ -2170,7 +2166,7 @@ function convertDOMtoTreeRowInfo(treechildren, level, rowidx) {
: convertDOMtoTreeRowInfo(descendants, level + 1, rowidx);
obj.rows.push({
cells: cellInfo,
properties: treerow.getAttribute("properties"),
properties: treerow.getAttribute("properties") || "",
container: treeitem.getAttribute("container") == "true",
separator: treeitem.localName == "treeseparator",
children,

View file

@ -84,7 +84,7 @@
).toLowerCase();
// If the accesskey of the current button is pressed, just activate it
if (this.accessKey.toLowerCase() == charPressedLower) {
if (this.accessKey?.toLowerCase() == charPressedLower) {
this.click();
return;
}
@ -201,7 +201,7 @@
while (iterator.nextNode()) {
var test = iterator.currentNode;
if (
test.accessKey.toLowerCase() == aAccessKeyLower &&
test.accessKey?.toLowerCase() == aAccessKeyLower &&
!test.disabled &&
!test.collapsed &&
!test.hidden

View file

@ -19,7 +19,7 @@
this.setAttribute("value", val);
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
// nsIDOMXULSelectControlItemElement

View file

@ -153,7 +153,7 @@
// nsIDOMXULSelectControlElement
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
// nsIDOMXULMenuListElement
@ -163,12 +163,12 @@
// nsIDOMXULMenuListElement
get image() {
return this.getAttribute("image");
return this.getAttribute("image") || "";
}
// nsIDOMXULMenuListElement
get label() {
return this.getAttribute("label");
return this.getAttribute("label") || "";
}
set description(val) {
@ -176,7 +176,7 @@
}
get description() {
return this.getAttribute("description");
return this.getAttribute("description") || "";
}
// nsIDOMXULMenuListElement

View file

@ -214,7 +214,7 @@
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
set disabled(val) {
@ -526,7 +526,7 @@
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
get selected() {

View file

@ -116,7 +116,7 @@
var searchText =
"searchLabel" in listitem
? listitem.searchLabel
: listitem.getAttribute("label"); // (see also bug 250123)
: listitem.getAttribute("label") || ""; // (see also bug 250123)
searchText = searchText.substring(0, length).toLowerCase();
if (searchText == incrementalString) {
this.ensureIndexIsVisible(k);
@ -227,7 +227,7 @@
this.setAttribute("seltype", val);
}
get selType() {
return this.getAttribute("seltype");
return this.getAttribute("seltype") || "";
}
// nsIDOMXULSelectControlElement
@ -977,7 +977,7 @@
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
/**

View file

@ -459,7 +459,7 @@
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
get control() {
@ -563,7 +563,7 @@
}
get value() {
return this.getAttribute("value");
return this.getAttribute("value") || "";
}
get tabbox() {

View file

@ -1078,7 +1078,7 @@
}
get selType() {
return this.getAttribute("seltype");
return this.getAttribute("seltype") || "";
}
set currentIndex(val) {

View file

@ -56,9 +56,12 @@ export var ShortcutUtils = {
},
getModifierString(elemMod) {
if (!elemMod) {
return "";
}
let elemString = "";
let haveCloverLeaf = false;
if (elemMod.match("accel")) {
if (Services.appinfo.OS == "Darwin") {
haveCloverLeaf = true;

View file

@ -64,7 +64,7 @@ add_task(async function doorhanger_bc_multiUpdate() {
is(
PanelUI.menuButton.getAttribute("badge-status"),
"",
null,
"Should not have restart badge during staging"
);

View file

@ -74,7 +74,7 @@ add_task(async function doorhanger_bc_multiUpdate() {
is(
PanelUI.menuButton.getAttribute("badge-status"),
"",
null,
"Should not have restart badge during staging"
);