Bug 1275983 - adding relations caching tests. r=eeejay
authorYura Zenevich <yzenevich@mozilla.com>
Fri, 27 May 2016 12:49:38 -0400
changeset 299407 dfa30f88a5e56529c1c077c5120d6f70d832d294
parent 299406 6e80d6ebb0f9122f779931c3a3a657b8659489e6
child 299408 1b661134e2caa95f9c68615202f876995b84ec49
push id77555
push useryura.zenevich@gmail.com
push dateSat, 28 May 2016 03:20:54 +0000
treeherdermozilla-inbound@dfa30f88a5e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay
bugs1275983
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1275983 - adding relations caching tests. r=eeejay MozReview-Commit-ID: 3cisZF54kp0
accessible/tests/browser/.eslintrc
accessible/tests/browser/browser.ini
accessible/tests/browser/browser_caching_relations.js
--- a/accessible/tests/browser/.eslintrc
+++ b/accessible/tests/browser/.eslintrc
@@ -9,16 +9,17 @@
 
     // Defined in accessible/tests/mochitest/ common.js, name.js, states.js
     "prettyName": true,
     "statesToString": true,
     "eventTypeToString": true,
     "testName": true,
     "testDescr": true,
     "testStates": true,
+    "testRelation": true,
     "testAccessibleTree": true,
     "isAccessible": true,
     "getAccessibleDOMNodeID": true,
 
     // Defined for all accessibility browser tests.
     "addAccessibleTask": true,
     "BrowserTestUtils": true,
     "ContentTask": true,
--- a/accessible/tests/browser/browser.ini
+++ b/accessible/tests/browser/browser.ini
@@ -12,16 +12,17 @@ support-files =
   !/accessible/tests/mochitest/*.js
   !/accessible/tests/mochitest/letters.gif
   !/accessible/tests/mochitest/moz.png
 
 # Caching tests
 [browser_caching_description.js]
 [browser_caching_name.js]
 skip-if = e10s
+[browser_caching_relations.js]
 [browser_caching_states.js]
 
 # Events tests
 [browser_events_caretmove.js]
 [browser_events_hide.js]
 [browser_events_show.js]
 [browser_events_statechange.js]
 [browser_events_textchange.js]
new file mode 100644
--- /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(`
+  <div id="dependant1">label</div>
+  <div id="dependant2">label2</div>
+  <div role="checkbox" id="host"></div>`,
+  function* (browser, accDoc) {
+    for (let spec of attrRelationsSpec) {
+      yield testRelated(browser, accDoc, ...spec);
+    }
+  }
+);