From 1c20c25eda9d3d558afc8b7eefb83c27bc14a0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 18 Mar 2024 09:15:07 +0000 Subject: [PATCH] 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 --- browser/base/content/browser.js | 2 +- .../test/favicons/browser_missing_favicon.js | 2 +- .../base/content/test/siteIdentity/head.js | 12 +++++------ .../base/content/test/sync/browser_sync.js | 2 +- .../browser_auth_spoofing_protection.js | 4 ++-- .../tabs/browser_lazy_tab_browser_events.js | 14 ++++++------- ...ect_tabs_move_to_new_window_contextmenu.js | 16 +++++++++------ .../browser_pinnedTabs_closeByKeyboard.js | 2 +- .../content/test/tabs/browser_tab_tooltips.js | 2 +- .../browser_extension_update_background.js | 6 +++--- ...er_extension_update_background_noprompt.js | 2 +- .../browser_devices_get_user_media_anim.js | 4 ++-- browser/base/content/utilityOverlay.js | 4 ++-- .../tests/browser/browser_sessionRestore.js | 2 +- .../test/browser/browser_guessusercontext.js | 2 +- .../browser_customization_context_menus.js | 6 +++--- .../test/browser_open_in_lazy_tab.js | 2 +- .../test/browser_synced_tabs_menu.js | 2 +- .../browser_ext_browserAction_context.js | 6 +++++- .../browser/browser_ext_contextMenus_icons.js | 6 +++--- browser/components/places/content/places.js | 2 +- .../browser_bookmark_context_menu_contents.js | 4 ++-- .../test/browser_pocket_button_icon_state.js | 6 +++++- .../tests/browser_applications_selection.js | 20 +++++++++++-------- .../tests/browser_contentblocking.js | 2 +- .../preferences/tests/browser_subdialogs.js | 2 +- .../sessionstore/SessionStore.sys.mjs | 2 +- .../test/browser_sessionStoreContainer.js | 2 +- .../components/uitour/test/browser_UITour3.js | 10 +++++----- .../browser/browser_UrlbarInput_overflow.js | 2 +- .../browser/browser_locationBarCommand.js | 2 +- .../test/browser_dynamic_tool_enabling.js | 2 +- .../test/browser_toolbox_remoteness_change.js | 2 +- ...ser_computed_search-filter_context-menu.js | 12 +++++------ ...rowser_rules_search-filter_context-menu.js | 12 +++++------ ...er_inspector_search-filter_context-menu.js | 12 +++++------ ...itor_reverse_search_keyboard_navigation.js | 4 ++-- dom/base/Element.cpp | 8 +------- dom/base/test/test_bug564863-2.xhtml | 6 +++--- .../JSWindowActor/browser_event_listener.js | 10 +++++++--- .../test_xul_custom_element.xhtml | 12 +++++------ .../browser/browser_loadPKCS11Module_ui.js | 2 +- .../browser_doorhanger_form_password_edit.js | 20 +++++++++---------- .../test/browser_pdfjs_editing_contextmenu.js | 2 +- .../tooltiptext/TooltipTextProvider.sys.mjs | 6 +----- toolkit/components/xulstore/XULStore.sys.mjs | 2 +- toolkit/content/customElements.js | 6 ++---- .../tests/chrome/test_labelcontrol.xhtml | 2 +- .../tests/chrome/test_menuitem_commands.xhtml | 10 +++++----- .../chrome/test_menulist_null_value.xhtml | 8 ++++---- .../tests/chrome/window_chromemargin.xhtml | 10 +++++++--- .../content/tests/chrome/window_keys.xhtml | 2 +- .../tests/chrome/window_largemenu.xhtml | 8 ++++---- toolkit/content/tests/widgets/tree_shared.js | 16 ++++++--------- toolkit/content/widgets/button.js | 4 ++-- toolkit/content/widgets/menu.js | 2 +- toolkit/content/widgets/menulist.js | 8 ++++---- toolkit/content/widgets/radio.js | 4 ++-- toolkit/content/widgets/richlistbox.js | 6 +++--- toolkit/content/widgets/tabbox.js | 4 ++-- toolkit/content/widgets/tree.js | 2 +- toolkit/modules/ShortcutUtils.sys.mjs | 5 ++++- .../browser_doorhanger_bc_multiUpdate.js | 2 +- ...oorhanger_bc_multiUpdate_promptWaitTime.js | 2 +- 64 files changed, 188 insertions(+), 177 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index c91a5d4db29a..bb75f114c791 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -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; } diff --git a/browser/base/content/test/favicons/browser_missing_favicon.js b/browser/base/content/test/favicons/browser_missing_favicon.js index f6194259093b..fd60d362b417 100644 --- a/browser/base/content/test/favicons/browser_missing_favicon.js +++ b/browser/base/content/test/favicons/browser_missing_favicon.js @@ -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." ); } diff --git a/browser/base/content/test/siteIdentity/head.js b/browser/base/content/test/siteIdentity/head.js index 733796ffb792..9936a8bf6f17 100644 --- a/browser/base/content/test/siteIdentity/head.js +++ b/browser/base/content/test/siteIdentity/head.js @@ -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 - .getElementById("identity-popup-securityView-extended-info") - .getAttribute("mixedcontent"); + let popupAttr = + doc.getElementById("identity-popup").getAttribute("mixedcontent") || ""; + let bodyAttr = + doc + .getElementById("identity-popup-securityView-extended-info") + .getAttribute("mixedcontent") || ""; is( popupAttr.includes("active-loaded"), diff --git a/browser/base/content/test/sync/browser_sync.js b/browser/base/content/test/sync/browser_sync.js index 168c6f22b079..aa77a619c133 100644 --- a/browser/base/content/test/sync/browser_sync.js +++ b/browser/base/content/test/sync/browser_sync.js @@ -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) { diff --git a/browser/base/content/test/tabPrompts/browser_auth_spoofing_protection.js b/browser/base/content/test/tabPrompts/browser_auth_spoofing_protection.js index 86d7c992c588..121169497328 100644 --- a/browser/base/content/test/tabPrompts/browser_auth_spoofing_protection.js +++ b/browser/base/content/test/tabPrompts/browser_auth_spoofing_protection.js @@ -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( diff --git a/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js b/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js index 665bdb7f69f6..5e09225cde2a 100644 --- a/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js +++ b/browser/base/content/test/tabs/browser_lazy_tab_browser_events.js @@ -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"); diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js b/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js index d668d21df866..f2947698981a 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_move_to_new_window_contextmenu.js @@ -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( diff --git a/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js b/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js index fbcd0bb492ff..17dde48bb258 100644 --- a/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js +++ b/browser/base/content/test/tabs/browser_pinnedTabs_closeByKeyboard.js @@ -12,7 +12,7 @@ function test() { is( elemAttr("key_close", "disabled"), - "", + null, "key_closed should always be enabled" ); is( diff --git a/browser/base/content/test/tabs/browser_tab_tooltips.js b/browser/base/content/test/tabs/browser_tab_tooltips.js index ee82816bcebe..79be4d0a3633 100644 --- a/browser/base/content/test/tabs/browser_tab_tooltips.js +++ b/browser/base/content/test/tabs/browser_tab_tooltips.js @@ -57,7 +57,7 @@ add_task(async function () { ); is( tooltip.getAttribute("position"), - "", + null, "tooltip position attribute for tab" ); diff --git a/browser/base/content/test/webextensions/browser_extension_update_background.js b/browser/base/content/test/webextensions/browser_extension_update_background.js index 490544b2ec9a..5619bacb4db2 100644 --- a/browser/base/content/test/webextensions/browser_extension_update_background.js +++ b/browser/base/content/test/webextensions/browser_extension_update_background.js @@ -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(); diff --git a/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js b/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js index a0b10c82e2cd..204e7fb44af4 100644 --- a/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js +++ b/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js @@ -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; diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js index dd20a672c3ee..f1052565b8eb 100644 --- a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js @@ -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" ); } diff --git a/browser/base/content/utilityOverlay.js b/browser/base/content/utilityOverlay.js index 5967c878b307..dc3aeffaed7b 100644 --- a/browser/base/content/utilityOverlay.js +++ b/browser/base/content/utilityOverlay.js @@ -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; } } diff --git a/browser/components/aboutlogins/tests/browser/browser_sessionRestore.js b/browser/components/aboutlogins/tests/browser/browser_sessionRestore.js index 5ab03f98670d..86e754084b06 100644 --- a/browser/components/aboutlogins/tests/browser/browser_sessionRestore.js +++ b/browser/components/aboutlogins/tests/browser/browser_sessionRestore.js @@ -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) { diff --git a/browser/components/contextualidentity/test/browser/browser_guessusercontext.js b/browser/components/contextualidentity/test/browser/browser_guessusercontext.js index 69461e67b581..90ccba9ca484 100644 --- a/browser/components/contextualidentity/test/browser/browser_guessusercontext.js +++ b/browser/components/contextualidentity/test/browser/browser_guessusercontext.js @@ -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" ); }); diff --git a/browser/components/customizableui/test/browser_customization_context_menus.js b/browser/components/customizableui/test/browser_customization_context_menus.js index 526b3abd1bb4..c26c95b04d72 100644 --- a/browser/components/customizableui/test/browser_customization_context_menus.js +++ b/browser/components/customizableui/test/browser_customization_context_menus.js @@ -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( diff --git a/browser/components/customizableui/test/browser_open_in_lazy_tab.js b/browser/components/customizableui/test/browser_open_in_lazy_tab.js index c18de6769821..696bfde69b51 100644 --- a/browser/components/customizableui/test/browser_open_in_lazy_tab.js +++ b/browser/components/customizableui/test/browser_open_in_lazy_tab.js @@ -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"), diff --git a/browser/components/customizableui/test/browser_synced_tabs_menu.js b/browser/components/customizableui/test/browser_synced_tabs_menu.js index ff60167fead7..c16ddb784c3a 100644 --- a/browser/components/customizableui/test/browser_synced_tabs_menu.js +++ b/browser/components/customizableui/test/browser_synced_tabs_menu.js @@ -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"); diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js index e5d315c5d20b..a55952e61084 100644 --- a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js +++ b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js @@ -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, diff --git a/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js b/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js index 30d4d528b2d8..cb81d9a93b96 100644 --- a/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js +++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js @@ -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" ); diff --git a/browser/components/places/content/places.js b/browser/components/places/content/places.js index 685fa12b51c5..9e2abaafcc10 100644 --- a/browser/components/places/content/places.js +++ b/browser/components/places/content/places.js @@ -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") { diff --git a/browser/components/places/tests/browser/browser_bookmark_context_menu_contents.js b/browser/components/places/tests/browser/browser_bookmark_context_menu_contents.js index 16aeb08ad80a..228fea654e34 100644 --- a/browser/components/places/tests/browser/browser_bookmark_context_menu_contents.js +++ b/browser/components/places/tests/browser/browser_bookmark_context_menu_contents.js @@ -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}` ); } diff --git a/browser/components/pocket/test/browser_pocket_button_icon_state.js b/browser/components/pocket/test/browser_pocket_button_icon_state.js index c2cba8133bb0..83dc485f04a0 100644 --- a/browser/components/pocket/test/browser_pocket_button_icon_state.js +++ b/browser/components/pocket/test/browser_pocket_button_icon_state.js @@ -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 }) { diff --git a/browser/components/preferences/tests/browser_applications_selection.js b/browser/components/preferences/tests/browser_applications_selection.js index 683ce76a8903..23f0e00af82a 100644 --- a/browser/components/preferences/tests/browser_applications_selection.js +++ b/browser/components/preferences/tests/browser_applications_selection.js @@ -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; diff --git a/browser/components/preferences/tests/browser_contentblocking.js b/browser/components/preferences/tests/browser_contentblocking.js index 3d33f2ed7dc6..c178233a729c 100644 --- a/browser/components/preferences/tests/browser_contentblocking.js +++ b/browser/components/preferences/tests/browser_contentblocking.js @@ -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" ); diff --git a/browser/components/preferences/tests/browser_subdialogs.js b/browser/components/preferences/tests/browser_subdialogs.js index 8763ae9146c8..2d6e59b3ad1b 100644 --- a/browser/components/preferences/tests/browser_subdialogs.js +++ b/browser/components/preferences/tests/browser_subdialogs.js @@ -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( diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs index 91febbe4ae95..fc9e133ad098 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -3635,7 +3635,7 @@ var SessionStoreInternal = { } // Create a new tab. - let userContextId = aTab.getAttribute("usercontextid"); + let userContextId = aTab.getAttribute("usercontextid") || ""; let tabOptions = { userContextId, diff --git a/browser/components/sessionstore/test/browser_sessionStoreContainer.js b/browser/components/sessionstore/test/browser_sessionStoreContainer.js index 86833dea82a2..e4f3ecea9ff1 100644 --- a/browser/components/sessionstore/test/browser_sessionStoreContainer.js +++ b/browser/components/sessionstore/test/browser_sessionStoreContainer.js @@ -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); diff --git a/browser/components/uitour/test/browser_UITour3.js b/browser/components/uitour/test/browser_UITour3.js index 526994f4201f..2820fbd02026 100644 --- a/browser/components/uitour/test/browser_UITour3.js +++ b/browser/components/uitour/test/browser_UITour3.js @@ -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" ); diff --git a/browser/components/urlbar/tests/browser/browser_UrlbarInput_overflow.js b/browser/components/urlbar/tests/browser/browser_UrlbarInput_overflow.js index f191cae321d9..d01734959a3f 100644 --- a/browser/components/urlbar/tests/browser/browser_UrlbarInput_overflow.js +++ b/browser/components/urlbar/tests/browser/browser_UrlbarInput_overflow.js @@ -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)); diff --git a/browser/components/urlbar/tests/browser/browser_locationBarCommand.js b/browser/components/urlbar/tests/browser/browser_locationBarCommand.js index 84c45e586aad..92409f979f02 100644 --- a/browser/components/urlbar/tests/browser/browser_locationBarCommand.js +++ b/browser/components/urlbar/tests/browser/browser_locationBarCommand.js @@ -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" ); diff --git a/devtools/client/framework/test/browser_dynamic_tool_enabling.js b/devtools/client/framework/test/browser_dynamic_tool_enabling.js index 56313607cf37..0caf32b134de 100644 --- a/devtools/client/framework/test/browser_dynamic_tool_enabling.js +++ b/devtools/client/framework/test/browser_dynamic_tool_enabling.js @@ -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) { diff --git a/devtools/client/framework/test/browser_toolbox_remoteness_change.js b/devtools/client/framework/test/browser_toolbox_remoteness_change.js index af5f10521406..ff019d1826ec 100644 --- a/devtools/client/framework/test/browser_toolbox_remoteness_change.js +++ b/devtools/client/framework/test/browser_toolbox_remoteness_change.js @@ -19,7 +19,7 @@ add_task(async function () { ); is( tab.linkedBrowser.getAttribute("remote"), - "", + null, "And running in parent process" ); diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter_context-menu.js b/devtools/client/inspector/computed/test/browser_computed_search-filter_context-menu.js index 0069d644c7b9..bea344e5f54e 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter_context-menu.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter_context-menu.js @@ -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(); diff --git a/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js b/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js index 881b5274eeef..009c67cd70e1 100644 --- a/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js +++ b/devtools/client/inspector/rules/test/browser_rules_search-filter_context-menu.js @@ -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(); diff --git a/devtools/client/inspector/test/browser_inspector_search-filter_context-menu.js b/devtools/client/inspector/test/browser_inspector_search-filter_context-menu.js index dad2ffa0b84d..e8392b1425cf 100644 --- a/devtools/client/inspector/test/browser_inspector_search-filter_context-menu.js +++ b/devtools/client/inspector/test/browser_inspector_search-filter_context-menu.js @@ -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(); diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_editor_reverse_search_keyboard_navigation.js b/devtools/client/webconsole/test/browser/browser_jsterm_editor_reverse_search_keyboard_navigation.js index 0b9b828ce335..2a88433a86ff 100644 --- a/devtools/client/webconsole/test/browser/browser_jsterm_editor_reverse_search_keyboard_navigation.js +++ b/devtools/client/webconsole/test/browser/browser_jsterm_editor_reverse_search_keyboard_navigation.js @@ -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" ); diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index be31000278a1..12e184fb8cc8 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1460,13 +1460,7 @@ void Element::GetAttribute(const nsAString& aName, DOMString& aReturn) { if (val) { val->ToString(aReturn); } else { - if (IsXULElement()) { - // XXX should be SetDOMStringToNull(aReturn); - // See bug 232598 - // aReturn is already empty - } else { - aReturn.SetNull(); - } + aReturn.SetNull(); } } diff --git a/dom/base/test/test_bug564863-2.xhtml b/dom/base/test/test_bug564863-2.xhtml index 6f338f612d84..c860a7f6d778 100644 --- a/dom/base/test/test_bug564863-2.xhtml +++ b/dom/base/test/test_bug564863-2.xhtml @@ -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 { diff --git a/dom/ipc/tests/JSWindowActor/browser_event_listener.js b/dom/ipc/tests/JSWindowActor/browser_event_listener.js index 725c2c37533c..21cb0c5ee909 100644 --- a/dom/ipc/tests/JSWindowActor/browser_event_listener.js +++ b/dom/ipc/tests/JSWindowActor/browser_event_listener.js @@ -144,7 +144,7 @@ declTest("test in-process content events are not processed twice", { "content", "Should be a content " ); - 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 "); - is(chromeBrowser.getAttribute("remotetype"), "", "Should not be remote"); + is( + chromeBrowser.getAttribute("type"), + null, + "Should be a chrome " + ); + is(chromeBrowser.getAttribute("remotetype"), null, "Should not be remote"); await testEventProcessedOnce(chromeBrowser, "dummyChromePage.html"); diff --git a/dom/tests/mochitest/webcomponents/test_xul_custom_element.xhtml b/dom/tests/mochitest/webcomponents/test_xul_custom_element.xhtml index 0e172cb70d12..7048163372f2 100644 --- a/dom/tests/mochitest/webcomponents/test_xul_custom_element.xhtml +++ b/dom/tests/mochitest/webcomponents/test_xul_custom_element.xhtml @@ -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"); diff --git a/security/manager/ssl/tests/mochitest/browser/browser_loadPKCS11Module_ui.js b/security/manager/ssl/tests/mochitest/browser/browser_loadPKCS11Module_ui.js index 4b7b78df8def..8b65d1e41188 100644 --- a/security/manager/ssl/tests/mochitest/browser/browser_loadPKCS11Module_ui.js +++ b/security/manager/ssl/tests/mochitest/browser/browser_loadPKCS11Module_ui.js @@ -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` diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js index 23afd2c6ab99..ad91270eb534 100644 --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_form_password_edit.js @@ -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", diff --git a/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js b/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js index 779a3a6ad43e..f13d03d643c7 100644 --- a/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js +++ b/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js @@ -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 diff --git a/toolkit/components/tooltiptext/TooltipTextProvider.sys.mjs b/toolkit/components/tooltiptext/TooltipTextProvider.sys.mjs index 96a3e8dd5f65..a231f5b4cc1f 100644 --- a/toolkit/components/tooltiptext/TooltipTextProvider.sys.mjs +++ b/toolkit/components/tooltiptext/TooltipTextProvider.sys.mjs @@ -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"); diff --git a/toolkit/components/xulstore/XULStore.sys.mjs b/toolkit/components/xulstore/XULStore.sys.mjs index eb1965ec6d29..5648eedbedcb 100644 --- a/toolkit/components/xulstore/XULStore.sys.mjs +++ b/toolkit/components/xulstore/XULStore.sys.mjs @@ -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."); diff --git a/toolkit/content/customElements.js b/toolkit/content/customElements.js index b0a8f33fe6ca..ef58963a027c 100644 --- a/toolkit/content/customElements.js +++ b/toolkit/content/customElements.js @@ -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; diff --git a/toolkit/content/tests/chrome/test_labelcontrol.xhtml b/toolkit/content/tests/chrome/test_labelcontrol.xhtml index 06e7f9610515..937d3e74037c 100644 --- a/toolkit/content/tests/chrome/test_labelcontrol.xhtml +++ b/toolkit/content/tests/chrome/test_labelcontrol.xhtml @@ -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"); diff --git a/toolkit/content/tests/chrome/test_menuitem_commands.xhtml b/toolkit/content/tests/chrome/test_menuitem_commands.xhtml index 60a35b36c5a9..a342b9d1d527 100644 --- a/toolkit/content/tests/chrome/test_menuitem_commands.xhtml +++ b/toolkit/content/tests/chrome/test_menuitem_commands.xhtml @@ -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); diff --git a/toolkit/content/tests/chrome/test_menulist_null_value.xhtml b/toolkit/content/tests/chrome/test_menulist_null_value.xhtml index 9312c236dc4b..e0ef42f5bdac 100644 --- a/toolkit/content/tests/chrome/test_menulist_null_value.xhtml +++ b/toolkit/content/tests/chrome/test_menulist_null_value.xhtml @@ -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(); } diff --git a/toolkit/content/tests/chrome/window_chromemargin.xhtml b/toolkit/content/tests/chrome/window_chromemargin.xhtml index 81bcba62fe08..8c7cf5c0d3cd 100644 --- a/toolkit/content/tests/chrome/window_chromemargin.xhtml +++ b/toolkit/content/tests/chrome/window_chromemargin.xhtml @@ -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"); diff --git a/toolkit/content/tests/chrome/window_keys.xhtml b/toolkit/content/tests/chrome/window_keys.xhtml index 77a098ef0b8e..51f3be0a332c 100644 --- a/toolkit/content/tests/chrome/window_keys.xhtml +++ b/toolkit/content/tests/chrome/window_keys.xhtml @@ -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; diff --git a/toolkit/content/tests/chrome/window_largemenu.xhtml b/toolkit/content/tests/chrome/window_largemenu.xhtml index d84b045e78e7..8e6b6718b428 100644 --- a/toolkit/content/tests/chrome/window_largemenu.xhtml +++ b/toolkit/content/tests/chrome/window_largemenu.xhtml @@ -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(); } diff --git a/toolkit/content/tests/widgets/tree_shared.js b/toolkit/content/tests/widgets/tree_shared.js index ba52bf828e8e..ed3c4797fa3b 100644 --- a/toolkit/content/tests/widgets/tree_shared.js +++ b/toolkit/content/tests/widgets/tree_shared.js @@ -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, diff --git a/toolkit/content/widgets/button.js b/toolkit/content/widgets/button.js index ce48fac1e91e..7ca2eddbed26 100644 --- a/toolkit/content/widgets/button.js +++ b/toolkit/content/widgets/button.js @@ -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 diff --git a/toolkit/content/widgets/menu.js b/toolkit/content/widgets/menu.js index 1a55d799b60f..70b9521a271b 100644 --- a/toolkit/content/widgets/menu.js +++ b/toolkit/content/widgets/menu.js @@ -19,7 +19,7 @@ this.setAttribute("value", val); } get value() { - return this.getAttribute("value"); + return this.getAttribute("value") || ""; } // nsIDOMXULSelectControlItemElement diff --git a/toolkit/content/widgets/menulist.js b/toolkit/content/widgets/menulist.js index 3672d4ccf19d..8a6e778ab5fd 100644 --- a/toolkit/content/widgets/menulist.js +++ b/toolkit/content/widgets/menulist.js @@ -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 diff --git a/toolkit/content/widgets/radio.js b/toolkit/content/widgets/radio.js index 41e8a945bacf..52ace9bf6bd6 100644 --- a/toolkit/content/widgets/radio.js +++ b/toolkit/content/widgets/radio.js @@ -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() { diff --git a/toolkit/content/widgets/richlistbox.js b/toolkit/content/widgets/richlistbox.js index 01d970e6ed93..f965dfc3d03d 100644 --- a/toolkit/content/widgets/richlistbox.js +++ b/toolkit/content/widgets/richlistbox.js @@ -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") || ""; } /** diff --git a/toolkit/content/widgets/tabbox.js b/toolkit/content/widgets/tabbox.js index b1b2ddeccefb..f4003d002ca2 100644 --- a/toolkit/content/widgets/tabbox.js +++ b/toolkit/content/widgets/tabbox.js @@ -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() { diff --git a/toolkit/content/widgets/tree.js b/toolkit/content/widgets/tree.js index 4993bef0c29c..a871d3396f7c 100644 --- a/toolkit/content/widgets/tree.js +++ b/toolkit/content/widgets/tree.js @@ -1078,7 +1078,7 @@ } get selType() { - return this.getAttribute("seltype"); + return this.getAttribute("seltype") || ""; } set currentIndex(val) { diff --git a/toolkit/modules/ShortcutUtils.sys.mjs b/toolkit/modules/ShortcutUtils.sys.mjs index e45855602bb2..3632c52e6971 100644 --- a/toolkit/modules/ShortcutUtils.sys.mjs +++ b/toolkit/modules/ShortcutUtils.sys.mjs @@ -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; diff --git a/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate.js b/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate.js index 07e7bf51fabf..0ca510cfcf6b 100644 --- a/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate.js +++ b/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate.js @@ -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" ); diff --git a/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate_promptWaitTime.js b/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate_promptWaitTime.js index 00c61bcbb4da..8012250f36e3 100644 --- a/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate_promptWaitTime.js +++ b/toolkit/mozapps/update/tests/browser/browser_doorhanger_bc_multiUpdate_promptWaitTime.js @@ -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" );