tor-browser

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

test_bug430351.html (17765B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=430351
      5 -->
      6 <head>
      7  <title>Test for Bug 430351</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=430351">Mozilla Bug 430351</a>
     14 <p id="display"></p>
     15 <div id="content">
     16  <div id="parent"></div>
     17  <div id="editableParent" contenteditable="true"></div>
     18  <iframe id="frame"></iframe>
     19  <map name="map"><area></map>
     20 </div>
     21 <pre id="test">
     22 <script class="testbody" type="text/javascript">
     23 
     24 /** Test for Bug 430351 */
     25 
     26 var focusableElements = [
     27    "<a tabindex=\"-1\"></a>",
     28    "<a tabindex=\"0\"></a>",
     29    "<a tabindex=\"0\" disabled></a>",
     30    "<a tabindex=\"1\"></a>",
     31    "<a contenteditable=\"true\"></a>",
     32 
     33    "<a href=\"#\"></a>",
     34    "<a href=\"#\" tabindex=\"-1\"></a>",
     35    "<a href=\"#\" tabindex=\"0\"></a>",
     36    "<a href=\"#\" tabindex=\"0\" disabled></a>",
     37    "<a href=\"#\" tabindex=\"1\"></a>",
     38    "<a href=\"#\" contenteditable=\"true\"></a>",
     39    "<a href=\"#\" disabled></a>",
     40 
     41    "<button></button>",
     42    "<button tabindex=\"-1\"></button>",
     43    "<button tabindex=\"0\"></button>",
     44    "<button tabindex=\"1\"></button>",
     45    "<button contenteditable=\"true\"></button>",
     46 
     47    "<button type=\"reset\"></button>",
     48    "<button type=\"reset\" tabindex=\"-1\"></button>",
     49    "<button type=\"reset\" tabindex=\"0\"></button>",
     50    "<button type=\"reset\" tabindex=\"1\"></button>",
     51    "<button type=\"reset\" contenteditable=\"true\"></button>",
     52 
     53    "<button type=\"submit\"></button>",
     54    "<button type=\"submit\" tabindex=\"-1\"></button>",
     55    "<button type=\"submit\" tabindex=\"0\"></button>",
     56    "<button type=\"submit\" tabindex=\"1\"></button>",
     57    "<button type=\"submit\" contenteditable=\"true\"></button>",
     58 
     59    "<div tabindex=\"-1\"></div>",
     60    "<div tabindex=\"0\"></div>",
     61    "<div tabindex=\"1\"></div>",
     62    "<div contenteditable=\"true\"></div>",
     63    "<div tabindex=\"0\" disabled></div>",
     64 
     65    "<embed>",
     66    "<embed tabindex=\"-1\">",
     67    "<embed tabindex=\"0\">",
     68    "<embed tabindex=\"0\" disabled>",
     69    "<embed tabindex=\"1\">",
     70    "<embed disabled>",
     71    "<embed contenteditable=\"true\">",
     72 
     73    "<iframe contenteditable=\"true\"></iframe>",
     74 
     75    "<iframe src=\"about:blank\"></iframe>",
     76    "<iframe src=\"about:blank\" disabled></iframe>",
     77    "<iframe src=\"about:blank\" tabindex=\"-1\"></iframe>",
     78    "<iframe src=\"about:blank\" tabindex=\"0\"></iframe>",
     79    "<iframe src=\"about:blank\" tabindex=\"0\" disabled></iframe>",
     80    "<iframe src=\"about:blank\" tabindex=\"1\"></iframe>",
     81    "<iframe src=\"about:blank\" contenteditable=\"true\"></iframe>",
     82 
     83    "<iframe></iframe>",
     84    "<iframe tabindex=\"-1\"></iframe>",
     85    "<iframe tabindex=\"0\"></iframe>",
     86    "<iframe tabindex=\"0\" disabled></iframe>",
     87    "<iframe tabindex=\"1\"></iframe>",
     88    "<iframe disabled></iframe>",
     89 
     90    "<img tabindex=\"-1\">",
     91    "<img tabindex=\"0\">",
     92    "<img tabindex=\"0\" disabled>",
     93    "<img tabindex=\"1\">",
     94 
     95    "<input>",
     96    "<input tabindex=\"-1\">",
     97    "<input tabindex=\"0\">",
     98    "<input tabindex=\"1\">",
     99    "<input contenteditable=\"true\">",
    100 
    101    "<input type=\"button\">",
    102    "<input type=\"button\" tabindex=\"-1\">",
    103    "<input type=\"button\" tabindex=\"0\">",
    104    "<input type=\"button\" tabindex=\"1\">",
    105    "<input type=\"button\" contenteditable=\"true\">",
    106 
    107    "<input type=\"checkbox\">",
    108    "<input type=\"checkbox\" tabindex=\"-1\">",
    109    "<input type=\"checkbox\" tabindex=\"0\">",
    110    "<input type=\"checkbox\" tabindex=\"1\">",
    111    "<input type=\"checkbox\" contenteditable=\"true\">",
    112 
    113    "<input type=\"image\">",
    114    "<input type=\"image\" tabindex=\"-1\">",
    115    "<input type=\"image\" tabindex=\"0\">",
    116    "<input type=\"image\" tabindex=\"1\">",
    117    "<input type=\"image\" contenteditable=\"true\">",
    118 
    119    "<input type=\"password\">",
    120    "<input type=\"password\" tabindex=\"-1\">",
    121    "<input type=\"password\" tabindex=\"0\">",
    122    "<input type=\"password\" tabindex=\"1\">",
    123    "<input type=\"password\" contenteditable=\"true\">",
    124 
    125    "<input type=\"radio\">",
    126    "<input type=\"radio\" tabindex=\"-1\">",
    127    "<input type=\"radio\" tabindex=\"0\">",
    128    "<input type=\"radio\" tabindex=\"1\">",
    129    "<input type=\"radio\" contenteditable=\"true\">",
    130    "<input type=\"radio\" checked>",
    131    "<form><input type=\"radio\" name=\"foo\"></form>",
    132 
    133    "<input type=\"reset\">",
    134    "<input type=\"reset\" tabindex=\"-1\">",
    135    "<input type=\"reset\" tabindex=\"0\">",
    136    "<input type=\"reset\" tabindex=\"1\">",
    137    "<input type=\"reset\" contenteditable=\"true\">",
    138 
    139    "<input type=\"submit\">",
    140    "<input type=\"submit\" tabindex=\"-1\">",
    141    "<input type=\"submit\" tabindex=\"0\">",
    142    "<input type=\"submit\" tabindex=\"1\">",
    143    "<input type=\"submit\" contenteditable=\"true\">",
    144 
    145    "<input type=\"text\">",
    146    "<input type=\"text\" tabindex=\"-1\">",
    147    "<input type=\"text\" tabindex=\"0\">",
    148    "<input type=\"text\" tabindex=\"1\">",
    149    "<input type=\"text\" contenteditable=\"true\">",
    150 
    151    "<input type=\"number\">",
    152    "<input type=\"number\" tabindex=\"-1\">",
    153    "<input type=\"number\" tabindex=\"0\">",
    154    "<input type=\"number\" tabindex=\"1\">",
    155    "<input type=\"number\" contenteditable=\"true\">",
    156 
    157    "<object tabindex=\"-1\"></object>",
    158    "<object tabindex=\"0\"></object>",
    159    "<object tabindex=\"1\"></object>",
    160    "<object contenteditable=\"true\"></object>",
    161 
    162    "<object classid=\"java:a\"></object>",
    163    "<object classid=\"java:a\" tabindex=\"-1\"></object>",
    164    "<object classid=\"java:a\" tabindex=\"0\"></object>",
    165    "<object classid=\"java:a\" tabindex=\"0\" disabled></object>",
    166    "<object classid=\"java:a\" tabindex=\"1\"></object>",
    167    "<object classid=\"java:a\" disabled></object>",
    168    "<object classid=\"java:a\" contenteditable=\"true\"></object>",
    169 
    170    "<select></select>",
    171    "<select tabindex=\"-1\"></select>",
    172    "<select tabindex=\"0\"></select>",
    173    "<select tabindex=\"1\"></select>",
    174    "<select contenteditable=\"true\"></select>",
    175 
    176    "<option tabindex='-1'></option>",
    177    "<option tabindex='0'></option>",
    178    "<option tabindex='1'></option>",
    179    "<option contenteditable></option>",
    180 
    181    "<optgroup tabindex='-1'></optgroup>",
    182    "<optgroup tabindex='0'></optgroup>",
    183    "<optgroup tabindex='1'></optgroup>",
    184    "<optgroup contenteditable></optgroup>"
    185 ];
    186 
    187 var nonFocusableElements = [
    188    "<a></a>",
    189    "<a disabled></a>",
    190 
    191    "<button tabindex=\"0\" disabled></button>",
    192    "<button disabled></button>",
    193 
    194    "<button type=\"reset\" tabindex=\"0\" disabled></button>",
    195    "<button type=\"reset\" disabled></button>",
    196 
    197    "<button type=\"submit\" tabindex=\"0\" disabled></button>",
    198    "<button type=\"submit\" disabled></button>",
    199 
    200    "<div></div>",
    201    "<div disabled></div>",
    202 
    203    "<img>",
    204    "<img disabled>",
    205    "<img contenteditable=\"true\">",
    206 
    207    "<img usemap=\"#map\">",
    208    "<img usemap=\"#map\" tabindex=\"-1\">",
    209    "<img usemap=\"#map\" tabindex=\"0\">",
    210    "<img usemap=\"#map\" tabindex=\"0\" disabled>",
    211    "<img usemap=\"#map\" tabindex=\"1\">",
    212    "<img usemap=\"#map\" disabled>",
    213    "<img usemap=\"#map\" contenteditable=\"true\">",
    214 
    215    "<input tabindex=\"0\" disabled>",
    216    "<input disabled>",
    217 
    218    "<input type=\"button\" tabindex=\"0\" disabled>",
    219    "<input type=\"button\" disabled>",
    220 
    221    "<input type=\"checkbox\" tabindex=\"0\" disabled>",
    222    "<input type=\"checkbox\" disabled>",
    223 
    224    "<input type=\"file\" tabindex=\"0\" disabled>",
    225    "<input type=\"file\" disabled>",
    226 
    227    "<input type=\"hidden\">",
    228    "<input type=\"hidden\" tabindex=\"-1\">",
    229    "<input type=\"hidden\" tabindex=\"0\">",
    230    "<input type=\"hidden\" tabindex=\"0\" disabled>",
    231    "<input type=\"hidden\" tabindex=\"1\">",
    232    "<input type=\"hidden\" disabled>",
    233    "<input type=\"hidden\" contenteditable=\"true\">",
    234 
    235    "<input type=\"image\" tabindex=\"0\" disabled>",
    236    "<input type=\"image\" disabled>",
    237 
    238    "<input type=\"password\" tabindex=\"0\" disabled>",
    239    "<input type=\"password\" disabled>",
    240 
    241    "<input type=\"radio\" tabindex=\"0\" disabled>",
    242    "<input type=\"radio\" disabled>",
    243 
    244    "<input type=\"reset\" tabindex=\"0\" disabled>",
    245    "<input type=\"reset\" disabled>",
    246 
    247    "<input type=\"submit\" tabindex=\"0\" disabled>",
    248    "<input type=\"submit\" disabled>",
    249 
    250    "<input type=\"text\" tabindex=\"0\" disabled>",
    251    "<input type=\"text\" disabled>",
    252 
    253    "<object></object>",
    254 
    255    "<select tabindex=\"0\" disabled></select>",
    256    "<select disabled></select>",
    257 
    258    "<option></option>",
    259    "<option tabindex='1' disabled></option>",
    260 
    261    "<optgroup></optgroup>",
    262    "<optgroup tabindex='1' disabled></optgroup>"
    263 ];
    264 
    265 var focusableInContentEditable = [
    266    "<button></button>",
    267    "<button tabindex=\"-1\"></button>",
    268    "<button tabindex=\"0\"></button>",
    269    "<button tabindex=\"1\"></button>",
    270    "<button contenteditable=\"true\"></button>",
    271 
    272    "<button type=\"reset\"></button>",
    273    "<button type=\"reset\" tabindex=\"-1\"></button>",
    274    "<button type=\"reset\" tabindex=\"0\"></button>",
    275    "<button type=\"reset\" tabindex=\"1\"></button>",
    276    "<button type=\"reset\" contenteditable=\"true\"></button>",
    277 
    278    "<button type=\"submit\"></button>",
    279    "<button type=\"submit\" tabindex=\"-1\"></button>",
    280    "<button type=\"submit\" tabindex=\"0\"></button>",
    281    "<button type=\"submit\" tabindex=\"1\"></button>",
    282    "<button type=\"submit\" contenteditable=\"true\"></button>",
    283 
    284    "<div tabindex=\"-1\"></div>",
    285    "<div tabindex=\"0\"></div>",
    286    "<div tabindex=\"1\"></div>",
    287    "<div tabindex=\"0\" disabled></div>",
    288 
    289    "<embed>",
    290    "<embed tabindex=\"-1\">",
    291    "<embed tabindex=\"0\">",
    292    "<embed tabindex=\"0\" disabled>",
    293    "<embed tabindex=\"1\">",
    294    "<embed disabled>",
    295    "<embed contenteditable=\"true\">",
    296 
    297    "<iframe src=\"about:blank\"></iframe>",
    298    "<iframe></iframe>",
    299    "<iframe src=\"about:blank\" disabled></iframe>",
    300    "<iframe disabled></iframe>",
    301    "<iframe src=\"about:blank\" tabindex=\"-1\"></iframe>",
    302    "<iframe tabindex=\"-1\"></iframe>",
    303    "<iframe src=\"about:blank\" tabindex=\"0\"></iframe>",
    304    "<iframe tabindex=\"0\"></iframe>",
    305    "<iframe src=\"about:blank\" tabindex=\"0\" disabled></iframe>",
    306    "<iframe tabindex=\"0\" disabled></iframe>",
    307    "<iframe src=\"about:blank\" tabindex=\"1\"></iframe>",
    308    "<iframe tabindex=\"1\"></iframe>",
    309    "<iframe src=\"about:blank\" contenteditable=\"true\"></iframe>",
    310    "<iframe contenteditable=\"true\"></iframe>",
    311 
    312    "<img tabindex=\"-1\">",
    313    "<img tabindex=\"0\">",
    314    "<img tabindex=\"0\" disabled>",
    315    "<img tabindex=\"1\">",
    316 
    317    "<input>",
    318    "<input tabindex=\"-1\">",
    319    "<input tabindex=\"0\">",
    320    "<input tabindex=\"1\">",
    321    "<input contenteditable=\"true\">",
    322 
    323    "<input type=\"button\">",
    324    "<input type=\"button\" tabindex=\"-1\">",
    325    "<input type=\"button\" tabindex=\"0\">",
    326    "<input type=\"button\" tabindex=\"1\">",
    327    "<input type=\"button\" contenteditable=\"true\">",
    328 
    329    "<input type=\"file\">",
    330    "<input type=\"file\" tabindex=\"-1\">",
    331    "<input type=\"file\" tabindex=\"0\">",
    332    "<input type=\"file\" tabindex=\"1\">",
    333    "<input type=\"file\" contenteditable=\"true\">",
    334 
    335    "<input type=\"checkbox\">",
    336    "<input type=\"checkbox\" tabindex=\"-1\">",
    337    "<input type=\"checkbox\" tabindex=\"0\">",
    338    "<input type=\"checkbox\" tabindex=\"1\">",
    339    "<input type=\"checkbox\" contenteditable=\"true\">",
    340 
    341    "<input type=\"image\">",
    342    "<input type=\"image\" tabindex=\"-1\">",
    343    "<input type=\"image\" tabindex=\"0\">",
    344    "<input type=\"image\" tabindex=\"1\">",
    345    "<input type=\"image\" contenteditable=\"true\">",
    346 
    347    "<input type=\"password\">",
    348    "<input type=\"password\" tabindex=\"-1\">",
    349    "<input type=\"password\" tabindex=\"0\">",
    350    "<input type=\"password\" tabindex=\"1\">",
    351    "<input type=\"password\" contenteditable=\"true\">",
    352 
    353    "<input type=\"radio\">",
    354    "<input type=\"radio\" tabindex=\"-1\">",
    355    "<input type=\"radio\" tabindex=\"0\">",
    356    "<input type=\"radio\" tabindex=\"1\">",
    357    "<input type=\"radio\" contenteditable=\"true\">",
    358    "<input type=\"radio\" checked>",
    359    "<form><input type=\"radio\" name=\"foo\"></form>",
    360 
    361    "<input type=\"reset\">",
    362    "<input type=\"reset\" tabindex=\"-1\">",
    363    "<input type=\"reset\" tabindex=\"0\">",
    364    "<input type=\"reset\" tabindex=\"1\">",
    365    "<input type=\"reset\" contenteditable=\"true\">",
    366 
    367    "<input type=\"submit\">",
    368    "<input type=\"submit\" tabindex=\"-1\">",
    369    "<input type=\"submit\" tabindex=\"0\">",
    370    "<input type=\"submit\" tabindex=\"1\">",
    371    "<input type=\"submit\" contenteditable=\"true\">",
    372 
    373    "<input type=\"text\">",
    374    "<input type=\"text\" tabindex=\"-1\">",
    375    "<input type=\"text\" tabindex=\"0\">",
    376    "<input type=\"text\" tabindex=\"1\">",
    377    "<input type=\"text\" contenteditable=\"true\">",
    378 
    379    "<input type=\"number\">",
    380    "<input type=\"number\" tabindex=\"-1\">",
    381    "<input type=\"number\" tabindex=\"0\">",
    382    "<input type=\"number\" tabindex=\"1\">",
    383    "<input type=\"number\" contenteditable=\"true\">",
    384 
    385    "<object tabindex=\"-1\"></object>",
    386    "<object tabindex=\"0\"></object>",
    387    "<object tabindex=\"1\"></object>",
    388 
    389    // Disabled doesn't work for <object>.
    390    "<object tabindex=\"0\" disabled></object>",
    391    "<object disabled></object>",
    392 
    393    "<select></select>",
    394    "<select tabindex=\"-1\"></select>",
    395    "<select tabindex=\"0\"></select>",
    396    "<select tabindex=\"1\"></select>",
    397    "<select contenteditable=\"true\"></select>",
    398 
    399    "<option tabindex='-1'></option>",
    400    "<option tabindex='0'></option>",
    401    "<option tabindex='1'></option>",
    402 
    403    "<optgroup tabindex='-1'></optgroup>",
    404    "<optgroup tabindex='0'></optgroup>",
    405    "<optgroup tabindex='1'></optgroup>"
    406 ];
    407 
    408 var focusableInDesignMode = [
    409    "<embed>",
    410    "<embed tabindex=\"-1\">",
    411    "<embed tabindex=\"0\">",
    412    "<embed tabindex=\"0\" disabled>",
    413    "<embed tabindex=\"1\">",
    414    "<embed disabled>",
    415    "<embed contenteditable=\"true\">",
    416 
    417    "<img tabindex=\"-1\">",
    418    "<img tabindex=\"0\">",
    419    "<img tabindex=\"0\" disabled>",
    420    "<img tabindex=\"1\">",
    421 ];
    422 
    423 // Can't currently test these, need a plugin.
    424 var focusableElementsTODO = [
    425    "<object classid=\"java:a\"></object>",
    426    "<object classid=\"java:a\" tabindex=\"-1\"></object>",
    427    "<object classid=\"java:a\" tabindex=\"0\"></object>",
    428    "<object classid=\"java:a\" tabindex=\"0\" disabled></object>",
    429    "<object classid=\"java:a\" tabindex=\"1\"></object>",
    430    "<object classid=\"java:a\" disabled></object>",
    431    "<object classid=\"java:a\" contenteditable=\"true\"></object>",
    432 ];
    433 
    434 var serializer = new XMLSerializer();
    435 
    436 function testElements(parent, tags, shouldBeFocusable)
    437 {
    438    var focusable, errorSuffix = "";
    439    if (parent.ownerDocument.designMode == "on") {
    440        focusable = focusableInDesignMode;
    441        errorSuffix = " in a document with designMode=on";
    442    }
    443    else if (parent.contentEditable == "true") {
    444        focusable = focusableInContentEditable;
    445    }
    446 
    447    for (var tag of tags) {
    448        parent.ownerDocument.body.focus();
    449 
    450        if (focusableElementsTODO.indexOf(tag) > -1) {
    451            todo_is(parent.ownerDocument.activeElement, parent.firstChild,
    452                    tag + " should be focusable" + errorSuffix);
    453            continue;
    454        }
    455 
    456        parent.innerHTML = tag;
    457 
    458        // Focus the deepest descendant.
    459        var descendant = parent;
    460        while ((descendant = descendant.firstChild))
    461            element = descendant;
    462 
    463        if (element.nodeName == "IFRAME")
    464            var foo = element.contentDocument;
    465 
    466        element.focus();
    467 
    468        var errorPrefix = serializer.serializeToString(element) + " in " +
    469                          serializer.serializeToString(parent);
    470 
    471        try {
    472          // Make sure activeElement doesn't point to a
    473          // native anonymous element.
    474          parent.ownerDocument.activeElement.localName;
    475        } catch (ex) {
    476          ok(false, ex + errorPrefix + errorSuffix);
    477        }
    478        if (focusable ? focusable.indexOf(tag) > -1 : shouldBeFocusable) {
    479            is(parent.ownerDocument.activeElement, element,
    480               errorPrefix + " should be focusable" + errorSuffix);
    481        }
    482        else {
    483            isnot(parent.ownerDocument.activeElement, element,
    484                  errorPrefix + " should not be focusable" + errorSuffix);
    485        }
    486 
    487        parent.innerHTML = "";
    488    }
    489 }
    490 
    491 function test()
    492 {
    493    var parent = document.getElementById("parent");
    494    var editableParent = document.getElementById("editableParent");
    495 
    496    testElements(parent, focusableElements, true);
    497    testElements(parent, nonFocusableElements, false);
    498 
    499    testElements(editableParent, focusableElements, true);
    500    testElements(editableParent, nonFocusableElements, false);
    501 
    502    var frame = document.getElementById("frame");
    503    frame.contentDocument.body.innerHTML = document.getElementById("content").innerHTML;
    504    frame.contentDocument.designMode = "on";
    505    parent = frame.contentDocument.getElementById("parent");
    506    editableParent = frame.contentDocument.getElementById("editableParent");
    507 
    508    testElements(parent, focusableElements, false);
    509    testElements(parent, nonFocusableElements, false);
    510 
    511    testElements(editableParent, focusableElements, false);
    512    testElements(editableParent, nonFocusableElements, false);
    513 }
    514 
    515 SimpleTest.waitForExplicitFinish();
    516 addLoadEvent(test);
    517 addLoadEvent(SimpleTest.finish);
    518 
    519 </script>
    520 </pre>
    521 </body>
    522 </html>