diff --git a/accessible/moz.build b/accessible/moz.build index daa2a5feb27b..af09ead62ac8 100644 --- a/accessible/moz.build +++ b/accessible/moz.build @@ -31,6 +31,7 @@ if CONFIG['MOZ_XUL']: TEST_DIRS += ['tests/mochitest'] BROWSER_CHROME_MANIFESTS += [ + 'tests/browser/bounds/browser.ini', 'tests/browser/browser.ini', 'tests/browser/e10s/browser.ini', 'tests/browser/scroll/browser.ini', @@ -38,4 +39,4 @@ BROWSER_CHROME_MANIFESTS += [ ] with Files("**"): - BUG_COMPONENT = ("Core", "Disability Access APIs") \ No newline at end of file + BUG_COMPONENT = ("Core", "Disability Access APIs") diff --git a/accessible/tests/browser/bounds/browser.ini b/accessible/tests/browser/bounds/browser.ini new file mode 100644 index 000000000000..2826cb87edd9 --- /dev/null +++ b/accessible/tests/browser/bounds/browser.ini @@ -0,0 +1,12 @@ +[DEFAULT] +skip-if = e10s && os == 'win' && release_or_beta +support-files = + head.js + !/accessible/tests/browser/events.js + !/accessible/tests/browser/shared-head.js + !/accessible/tests/mochitest/*.js + !/accessible/tests/mochitest/letters.gif + +[browser_test_zoom.js] +[browser_test_zoom_text.js] +skip-if = os == 'win' # Bug 1372296 diff --git a/accessible/tests/browser/bounds/browser_test_zoom.js b/accessible/tests/browser/bounds/browser_test_zoom.js new file mode 100644 index 000000000000..badbe051c15e --- /dev/null +++ b/accessible/tests/browser/bounds/browser_test_zoom.js @@ -0,0 +1,68 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* import-globals-from ../../mochitest/layout.js */ + +async function getContentBoundsForDOMElm(browser, id) { + return ContentTask.spawn(browser, id, contentId => { + this.ok = ok; + return getBoundsForDOMElm(contentId); + }); +} + +async function testContentBounds(browser, acc) { + let [expectedX, expectedY, expectedWidth, expectedHeight] = + await getContentBoundsForDOMElm(browser, getAccessibleDOMNodeID(acc)); + + let [x, y, width, height] = getBounds(acc); + let prettyAccName = prettyName(acc); + is(x, expectedX, "Wrong x coordinate of " + prettyAccName); + is(y, expectedY, "Wrong y coordinate of " + prettyAccName); + is(width, expectedWidth, "Wrong width of " + prettyAccName); + is(height, expectedHeight, "Wrong height of " + prettyAccName); +} + +async function runTests(browser, accDoc) { + loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR }); + + let p1 = findAccessibleChildByID(accDoc, "p1"); + let p2 = findAccessibleChildByID(accDoc, "p2"); + let imgmap = findAccessibleChildByID(accDoc, "imgmap"); + if (!imgmap.childCount) { + // An image map may not be available even after the doc and image load + // is complete. We don't recieve any DOM events for this change either, + // so we need to wait for a REORDER. + await waitForEvent(EVENT_REORDER, "imgmap"); + } + let area = imgmap.firstChild; + + await testContentBounds(browser, p1); + await testContentBounds(browser, p2); + await testContentBounds(browser, area); + + await ContentTask.spawn(browser, {}, () => { + zoomDocument(document, 2.0); + }); + + await testContentBounds(browser, p1); + await testContentBounds(browser, p2); + await testContentBounds(browser, area); +} + +/** + * Test accessible boundaries when page is zoomed + */ +addAccessibleTask(` +

para 1

para 2

+ + mozilla.org + +`, + runTests +); diff --git a/accessible/tests/browser/bounds/browser_test_zoom_text.js b/accessible/tests/browser/bounds/browser_test_zoom_text.js new file mode 100644 index 000000000000..758aaffb2d2a --- /dev/null +++ b/accessible/tests/browser/bounds/browser_test_zoom_text.js @@ -0,0 +1,41 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* import-globals-from ../../mochitest/layout.js */ + +async function runTests(browser, accDoc) { + function testTextNode(id) { + let hyperTextNode = findAccessibleChildByID(accDoc, id); + let textNode = hyperTextNode.firstChild; + + let [x, y, width, height] = getBounds(textNode); + testTextBounds(hyperTextNode, 0, -1, [x, y, width, height], + COORDTYPE_SCREEN_RELATIVE); + } + + loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR }); + + testTextNode("p1"); + testTextNode("p2"); + + await ContentTask.spawn(browser, {}, () => { + zoomDocument(document, 2.0); + }); + + testTextNode("p1"); + + await ContentTask.spawn(browser, {}, () => { + zoomDocument(document, 1.0); + }); +} + +/** + * Test the text range boundary when page is zoomed + */ +addAccessibleTask(` +

Tilimilitryamdiya

+

ل

`, runTests +); diff --git a/accessible/tests/browser/bounds/head.js b/accessible/tests/browser/bounds/head.js new file mode 100644 index 000000000000..6718fc5c7415 --- /dev/null +++ b/accessible/tests/browser/bounds/head.js @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +'use strict'; + +// Load the shared-head file first. +/* import-globals-from ../shared-head.js */ +Services.scriptloader.loadSubScript( + 'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js', + this); + +// Loading and common.js from accessible/tests/mochitest/ for all tests, as +// well as events.js. +loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, + { name: 'layout.js', dir: MOCHITESTS_DIR }, 'events.js'); diff --git a/accessible/tests/browser/scroll/browser_test_zoom_text.js b/accessible/tests/browser/scroll/browser_test_zoom_text.js index 3fa4bd2450fa..a3122f6ad70d 100644 --- a/accessible/tests/browser/scroll/browser_test_zoom_text.js +++ b/accessible/tests/browser/scroll/browser_test_zoom_text.js @@ -8,6 +8,8 @@ loadScripts({ name: 'layout.js', dir: MOCHITESTS_DIR }); async function runTests(browser, accDoc) { + loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR }); + let paragraph = findAccessibleChildByID(accDoc, "paragraph", [nsIAccessibleText]); let offset = 64; // beginning of 4th stanza @@ -18,7 +20,9 @@ async function runTests(browser, accDoc) { COORDTYPE_SCREEN_RELATIVE, docX, docY); testTextPos(paragraph, offset, [x, docY], COORDTYPE_SCREEN_RELATIVE); - await zoomContent(browser, 2.0); + await ContentTask.spawn(browser, {}, () => { + zoomDocument(document, 2.0); + }); paragraph = findAccessibleChildByID(accDoc, "paragraph2", [nsIAccessibleText]); offset = 52; // // beginning of 4th stanza diff --git a/accessible/tests/browser/scroll/head.js b/accessible/tests/browser/scroll/head.js index 4af98a2a27d0..1454e55c7e9e 100644 --- a/accessible/tests/browser/scroll/head.js +++ b/accessible/tests/browser/scroll/head.js @@ -4,27 +4,12 @@ 'use strict'; -/* exported zoomContent */ - // Load the shared-head file first. /* import-globals-from ../shared-head.js */ Services.scriptloader.loadSubScript( 'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js', this); -async function zoomContent(browser, zoom) -{ - return ContentTask.spawn(browser, zoom, _zoom => { - let docShell = content - .QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebNavigation) - .QueryInterface(Components.interfaces.nsIDocShell); - let docViewer = docShell.contentViewer; - - docViewer.fullZoom = _zoom; - }); -} - // Loading and common.js from accessible/tests/mochitest/ for all tests, as // well as events.js. loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, 'events.js'); diff --git a/accessible/tests/browser/shared-head.js b/accessible/tests/browser/shared-head.js index 1158f9812baf..16c8daecd8de 100644 --- a/accessible/tests/browser/shared-head.js +++ b/accessible/tests/browser/shared-head.js @@ -8,7 +8,7 @@ /* import-globals-from events.js */ /* exported Logger, MOCHITESTS_DIR, invokeSetAttribute, invokeFocus, - invokeSetStyle, getAccessibleDOMNodeID, + invokeSetStyle, getAccessibleDOMNodeID, getAccessibleTagName, addAccessibleTask, findAccessibleChildByID, isDefunct, CURRENT_CONTENT_DIR, loadScripts, loadFrameScripts, Cc, Cu */ @@ -31,6 +31,8 @@ const MOCHITESTS_DIR = const CURRENT_CONTENT_DIR = 'http://example.com/browser/accessible/tests/browser/'; +const LOADED_FRAMESCRIPTS = new Map(); + /** * Used to dump debug information. */ @@ -188,7 +190,17 @@ function loadFrameScripts(browser, ...scripts) { // Script is a object that has { dir, name } format. frameScript = `${script.dir}${script.name}`; } + + let loadedScriptSet = LOADED_FRAMESCRIPTS.get(frameScript); + if (!loadedScriptSet) { + loadedScriptSet = new WeakSet(); + LOADED_FRAMESCRIPTS.set(frameScript, loadedScriptSet); + } else if (loadedScriptSet.has(browser)) { + continue; + } + mm.loadFrameScript(frameScript, false, true); + loadedScriptSet.add(browser); } } @@ -280,6 +292,19 @@ function isDefunct(accessible) { return defunct; } +/** + * Get the DOM tag name for a given accessible. + * @param {nsIAccessible} accessible accessible + * @return {String?} tag name of associated DOM node, or null. + */ +function getAccessibleTagName(acc) { + try { + return acc.attributes.getStringProperty("tag"); + } catch (e) { + return null; + } +} + /** * Traverses the accessible tree starting from a given accessible as a root and * looks for an accessible that matches based on its DOMNode id. diff --git a/accessible/tests/mochitest/bounds/a11y.ini b/accessible/tests/mochitest/bounds/a11y.ini index d60bd46a50fe..bdb8c02f90a2 100644 --- a/accessible/tests/mochitest/bounds/a11y.ini +++ b/accessible/tests/mochitest/bounds/a11y.ini @@ -4,5 +4,3 @@ support-files = [test_list.html] [test_select.html] -[test_zoom.html] -[test_zoom_text.html] diff --git a/accessible/tests/mochitest/bounds/test_zoom.html b/accessible/tests/mochitest/bounds/test_zoom.html deleted file mode 100644 index fc2dee4828e2..000000000000 --- a/accessible/tests/mochitest/bounds/test_zoom.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - Accessible boundaries when page is zoomed - - - - - - - - - - - - - - - - - - Mozilla Bug 650241 - -

- -
-  
- - diff --git a/accessible/tests/mochitest/bounds/test_zoom_text.html b/accessible/tests/mochitest/bounds/test_zoom_text.html deleted file mode 100644 index 1637f344e31c..000000000000 --- a/accessible/tests/mochitest/bounds/test_zoom_text.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - The text range boundary when page is zoomed - - - - - - - - - - - - - - - - - - Mozilla Bug 727942 - -

- -
-  
- -