diff --git a/accessible/tests/browser/.eslintrc b/accessible/tests/browser/.eslintrc index 5a539c9add19..c4fb8675f192 100644 --- a/accessible/tests/browser/.eslintrc +++ b/accessible/tests/browser/.eslintrc @@ -14,6 +14,7 @@ "testName": true, "testDescr": true, "testStates": true, + "testRelation": true, "testAccessibleTree": true, "isAccessible": true, "getAccessibleDOMNodeID": true, diff --git a/accessible/tests/browser/browser.ini b/accessible/tests/browser/browser.ini index 269d6912b561..b677aa85ba82 100644 --- a/accessible/tests/browser/browser.ini +++ b/accessible/tests/browser/browser.ini @@ -17,6 +17,7 @@ support-files = [browser_caching_description.js] [browser_caching_name.js] skip-if = e10s +[browser_caching_relations.js] [browser_caching_states.js] # Events tests diff --git a/accessible/tests/browser/browser_caching_relations.js b/accessible/tests/browser/browser_caching_relations.js new file mode 100644 index 000000000000..772aee96a643 --- /dev/null +++ b/accessible/tests/browser/browser_caching_relations.js @@ -0,0 +1,86 @@ +/* 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'; + +/* global RELATION_LABELLED_BY, RELATION_LABEL_FOR, RELATION_DESCRIBED_BY, + RELATION_DESCRIPTION_FOR, RELATION_CONTROLLER_FOR, + RELATION_CONTROLLED_BY, RELATION_FLOWS_TO, RELATION_FLOWS_FROM */ + +loadScripts({ name: 'relations.js', dir: MOCHITESTS_DIR }); + +/** + * A test specification that has the following format: + * [ + * attr relevant aria attribute + * hostRelation corresponding host relation type + * dependantRelation corresponding dependant relation type + * ] + */ +const attrRelationsSpec = [ + ['aria-labelledby', RELATION_LABELLED_BY, RELATION_LABEL_FOR], + ['aria-describedby', RELATION_DESCRIBED_BY, RELATION_DESCRIPTION_FOR], + ['aria-controls', RELATION_CONTROLLER_FOR, RELATION_CONTROLLED_BY], + ['aria-flowto', RELATION_FLOWS_TO, RELATION_FLOWS_FROM] +]; + +function* testRelated(browser, accDoc, attr, hostRelation, dependantRelation) { + let host = findAccessibleChildByID(accDoc, 'host'); + let dependant1 = findAccessibleChildByID(accDoc, 'dependant1'); + let dependant2 = findAccessibleChildByID(accDoc, 'dependant2'); + + /** + * Test data has the format of: + * { + * desc {String} description for better logging + * attrs {?Array} an optional list of attributes to update + * expected {Array} expected relation values for dependant1, dependant2 + * and host respectively. + * } + */ + const tests = [{ + desc: 'No attribute', + expected: [ null, null, null ] + }, { + desc: 'Set attribute', + attrs: [{ key: attr, value: 'dependant1' }], + expected: [ host, null, dependant1 ] + }, { + desc: 'Change attribute', + attrs: [{ key: attr, value: 'dependant2' }], + expected: [ null, host, dependant2 ] + }, { + desc: 'Remove attribute', + attrs: [{ key: attr }], + expected: [ null, null, null ] + }]; + + for (let { desc, attrs, expected } of tests) { + info(desc); + + if (attrs) { + for (let { key, value } of attrs) { + yield invokeSetAttribute(browser, 'host', key, value); + } + } + + testRelation(dependant1, dependantRelation, expected[0]); + testRelation(dependant2, dependantRelation, expected[1]); + testRelation(host, hostRelation, expected[2]); + } +} + +/** + * Test caching of relations between accessible objects. + */ +addAccessibleTask(` +
label
+
label2
+ `, + function* (browser, accDoc) { + for (let spec of attrRelationsSpec) { + yield testRelated(browser, accDoc, ...spec); + } + } +);