tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_mathml.js (3815B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 function testMathAttr(iface, attr, subrole, textLeafValue) {
      8  ok(iface.attributeNames.includes(attr), `Object has ${attr} attribute`);
      9  let value = iface.getAttributeValue(attr);
     10  is(
     11    value.getAttributeValue("AXSubrole"),
     12    subrole,
     13    `${attr} value has correct subrole`
     14  );
     15 
     16  if (textLeafValue) {
     17    let children = value.getAttributeValue("AXChildren");
     18    is(children.length, 1, `${attr} value has one child`);
     19 
     20    is(
     21      children[0].getAttributeValue("AXRole"),
     22      "AXStaticText",
     23      `${attr} value's child is static text`
     24    );
     25    is(
     26      children[0].getAttributeValue("AXValue"),
     27      textLeafValue,
     28      `${attr} value has correct text`
     29    );
     30  }
     31 }
     32 
     33 addAccessibleTask(
     34  `<math id="math">
     35     <msqrt id="sqrt">
     36      <mn>2</mn>
     37    </msqrt>
     38    </math>`,
     39  async (browser, accDoc) => {
     40    let math = getNativeInterface(accDoc, "math");
     41    is(
     42      math.getAttributeValue("AXSubrole"),
     43      "AXDocumentMath",
     44      "Math element has correct subrole"
     45    );
     46 
     47    let sqrt = getNativeInterface(accDoc, "sqrt");
     48    is(
     49      sqrt.getAttributeValue("AXSubrole"),
     50      "AXMathSquareRoot",
     51      "msqrt has correct subrole"
     52    );
     53 
     54    testMathAttr(sqrt, "AXMathRootRadicand", "AXMathNumber", "2");
     55  }
     56 );
     57 
     58 addAccessibleTask(
     59  `<math>
     60    <mroot id="root">
     61      <mi>sin</mi>
     62      <mn>3</mn>
     63    </mroot>
     64  </math>`,
     65  async (browser, accDoc) => {
     66    let root = getNativeInterface(accDoc, "root");
     67    is(
     68      root.getAttributeValue("AXSubrole"),
     69      "AXMathRoot",
     70      "mroot has correct subrole"
     71    );
     72 
     73    testMathAttr(root, "AXMathRootRadicand", "AXMathIdentifier", "sin");
     74    testMathAttr(root, "AXMathRootIndex", "AXMathNumber", "3");
     75  }
     76 );
     77 
     78 addAccessibleTask(
     79  `<math>
     80    <mfrac id="fraction">
     81      <mn>2</mn>
     82      <mn>3</mn>
     83     </mfrac>
     84  </math>`,
     85  async (browser, accDoc) => {
     86    let fraction = getNativeInterface(accDoc, "fraction");
     87    is(
     88      fraction.getAttributeValue("AXSubrole"),
     89      "AXMathFraction",
     90      "mfrac has correct subrole"
     91    );
     92    ok(fraction.attributeNames.includes("AXMathFractionNumerator"));
     93    ok(fraction.attributeNames.includes("AXMathFractionDenominator"));
     94    ok(fraction.attributeNames.includes("AXMathLineThickness"));
     95 
     96    // Bug 1639745
     97    todo_is(fraction.getAttributeValue("AXMathLineThickness"), 1);
     98 
     99    testMathAttr(fraction, "AXMathFractionNumerator", "AXMathNumber", "2");
    100    testMathAttr(fraction, "AXMathFractionDenominator", "AXMathNumber", "3");
    101  }
    102 );
    103 
    104 addAccessibleTask(
    105  `<math>
    106  <msubsup id="subsup">
    107    <mo>∫</mo>
    108    <mn>0</mn>
    109    <mn>1</mn>
    110  </msubsup>
    111  </math>`,
    112  async (browser, accDoc) => {
    113    let subsup = getNativeInterface(accDoc, "subsup");
    114    is(
    115      subsup.getAttributeValue("AXSubrole"),
    116      "AXMathSubscriptSuperscript",
    117      "msubsup has correct subrole"
    118    );
    119 
    120    testMathAttr(subsup, "AXMathSubscript", "AXMathNumber", "0");
    121    testMathAttr(subsup, "AXMathSuperscript", "AXMathNumber", "1");
    122    testMathAttr(subsup, "AXMathBase", "AXMathOperator", "∫");
    123  }
    124 );
    125 
    126 addAccessibleTask(
    127  `<math>
    128  <munderover id="underover">
    129    <mo>∫</mo>
    130    <mn>0</mn>
    131    <mi>∞</mi>
    132  </munderover>
    133  </math>`,
    134  async (browser, accDoc) => {
    135    let underover = getNativeInterface(accDoc, "underover");
    136    is(
    137      underover.getAttributeValue("AXSubrole"),
    138      "AXMathUnderOver",
    139      "munderover has correct subrole"
    140    );
    141 
    142    testMathAttr(underover, "AXMathUnder", "AXMathNumber", "0");
    143    testMathAttr(underover, "AXMathOver", "AXMathIdentifier", "∞");
    144    testMathAttr(underover, "AXMathBase", "AXMathOperator", "∫");
    145  }
    146 );