Closed Bug 1797221 Opened 2 years ago Closed 2 years ago

[CTW] Removing alt text on img does not update accessible name properly

Categories

(Core :: Disability Access APIs, defect)

defect

Tracking

()

RESOLVED INVALID

People

(Reporter: nlapre, Unassigned)

References

Details

Consider the following code, which you can paste into some file in accessible/tests/browser/e10s/, like browser_treeupdate_imagemap.js:

// Verify that the alt text changes correctly.
const IMG_ID = "img-id";
const ALT_TEXT = "some-alt-text";
addAccessibleTask(
  `<img id="${IMG_ID}" src="${MOCHITESTS_DIR}/moz.png" alt="${ALT_TEXT}"/>`,
  async function (browser, accDoc) {
    // Test initial state; the img has alt text.
    const acc = findAccessibleChildByID(accDoc, IMG_ID);
    let tree = {
      role: ROLE_GRAPHIC, name: ALT_TEXT, children: [],
    };
    testAccessibleTree(acc, tree);

    // Set the alt text to the empty string.
    // WARNING: This will fail with the cache enabled!
    await invokeSetAttribute(browser, IMG_ID, "alt", "");
    tree = {
      role: ROLE_GRAPHIC, name: "", children: [],
    };
    testAccessibleTree(acc, tree);
  },
  { iframe: true, remoteIframe: true }
);

When running the test with the cache enabled (pref flipped on), we get the following failures (trimmed for clarity):

accessible/tests/browser/e10s/browser_treeupdate_imagemap.js
  FAIL Wrong value of property 'name' for [DOM node id: img-id, role: graphic, name: 'some-alt-text', address: [xpconnect wrapped nsIAccessible]]. - Got "some-alt-text", expected ""
  FAIL Wrong value of property 'name' for [DOM node id: img-id, role: graphic, address: [xpconnect wrapped nsIAccessible]]. - Got null, expected ""
  FAIL Wrong value of property 'name' for [DOM node id: img-id, role: graphic, name: 'some-alt-text', address: [xpconnect wrapped nsIAccessible]]. - Got "some-alt-text", expected ""

I would expect that setting the alt attribute to the empty string would set the name to the empty string, but it doesn't.

Note that not all of the scenarios are the same failure. Without the cache enabled, these tests pass. Seems like something weird is happening with cache pushes here, but I haven't yet dug further.

This is most likely failing because you're not waiting for an event. You can get away with this without the cache because Name is fetched on-demand for images. In contrast, when the cache is enabled, we have to wait for the push, which happens just before the event. If you change the test to this, does it work?

    // Set the alt text to the empty string.
    // WARNING: This will fail with the cache enabled!
    let nameChanged = waitForEvent(EVENT_NAME_CHANGE, IMG_ID);
    await invokeSetAttribute(browser, IMG_ID, "alt", "");
    await nameChanged;
    tree = {
      role: ROLE_GRAPHIC, name: "", children: [],
    };
    testAccessibleTree(acc, tree);
Flags: needinfo?(nlapre)

FWIW, the tests still fail with that change, with the cache on. The difference is that they now all fail in the same way (got null, expected ""). I'm sure there's a reason for that, but ultimately this will be remedied with the work I'm doing for this other bug (to be landed soon), so I doubt it's worth spending time on.

Flags: needinfo?(nlapre)

(and I'll close this issue when that other patch lands)

Closing this since the patch has landed for Bug 1748585.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.