diff --git a/accessible/base/nsAccessibilityService.cpp b/accessible/base/nsAccessibilityService.cpp index 2a42c26fd094..f06333814688 100644 --- a/accessible/base/nsAccessibilityService.cpp +++ b/accessible/base/nsAccessibilityService.cpp @@ -369,7 +369,11 @@ void nsAccessibilityService::NotifyOfPossibleBoundsChange( StaticPrefs::accessibility_cache_enabled_AtStartup()) { DocAccessible* document = GetDocAccessible(aPresShell); if (document) { - LocalAccessible* accessible = document->GetAccessible(aContent); + // DocAccessible::GetAccessible() won't return the document if a root + // element like body is passed. + LocalAccessible* accessible = aContent == document->GetContent() + ? document + : document->GetAccessible(aContent); if (accessible) { document->QueueCacheUpdate(accessible, CacheDomain::Bounds); } @@ -386,7 +390,11 @@ void nsAccessibilityService::NotifyOfComputedStyleChange( DocAccessible* document = GetDocAccessible(aPresShell); if (document) { - LocalAccessible* accessible = document->GetAccessible(aContent); + // DocAccessible::GetAccessible() won't return the document if a root + // element like body is passed. + LocalAccessible* accessible = aContent == document->GetContent() + ? document + : document->GetAccessible(aContent); if (accessible) { accessible->MaybeQueueCacheUpdateForStyleChanges(); } diff --git a/accessible/tests/browser/bounds/browser_test_iframe_transform.js b/accessible/tests/browser/bounds/browser_test_iframe_transform.js index d5c810be6eb0..31ad1139f857 100644 --- a/accessible/tests/browser/bounds/browser_test_iframe_transform.js +++ b/accessible/tests/browser/bounds/browser_test_iframe_transform.js @@ -140,3 +140,30 @@ addAccessibleTask( }, } ); + +/** + * Test document bounds change notifications. + * Note: This uses iframes to change the doc container size in order + * to have the doc accessible's bounds change. + */ +addAccessibleTask( + `
`, + async function(browser, accDoc, foo) { + const docWidth = () => { + let width = {}; + accDoc.getBounds({}, {}, width, {}); + return width.value; + }; + + await untilCacheIs(docWidth, 0, "Doc width is 0"); + await invokeSetStyleIframe(browser, DEFAULT_IFRAME_ID, "width", `300px`); + await untilCacheIs(docWidth, 300, "Doc width is 300"); + }, + { + chrome: false, + topLevel: false, + iframe: true, + remoteIframe: isCacheEnabled /* works, but timing is tricky with no cache */, + iframeAttrs: { style: "width: 0;" }, + } +);