tor-browser

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

test_plugin_fallback_focus.html (2882B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test that plugins reject focus</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <script src="/tests/SimpleTest/EventUtils.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body>
     11 <div id="content">
     12 <object id="obj_elt" type="application/x-shockwave-flash"></object>
     13 <object tabindex='0' id="obj_elt_with_idx" type="application/x-shockwave-flash"></object>
     14 <embed id="embed_elt" type="application/x-shockwave-flash"></embed>
     15 </div>
     16 <script type="application/javascript">
     17 var objElt = document.getElementById('obj_elt');
     18 var objEltWithIdx = document.getElementById('obj_elt_with_idx');
     19 var embedElt = document.getElementById('embed_elt');
     20 
     21 function checkHasFocus(expected, typeOfElts, elt) {
     22 ok((document.activeElement == elt) == expected,
     23 	typeOfElts + " element should " + (expected ? "" : "not ") + "accept focus");
     24 }
     25 
     26 function checkNoneHasFocus(typeOfElts) {
     27 checkHasFocus(false, typeOfElts + " <object>", objElt);
     28 checkHasFocus(false, typeOfElts + " <object> with tabindex", objEltWithIdx);
     29 checkHasFocus(false, typeOfElts + " <embed>", embedElt);
     30 }
     31 
     32 function checkFocusable(expected, typeOfElts, elt) {
     33 elt.focus();
     34 checkHasFocus(expected, typeOfElts, elt);
     35 }
     36 
     37 // As plugins, object and embed elements are not given focus
     38 ok(objElt != null, "object element should exist");
     39 ok(objEltWithIdx != null, "object element with tabindex should exist");
     40 ok(embedElt != null, "embed element should exist");
     41 
     42 // As plugins, obj/embed_elt can not take focus
     43 checkNoneHasFocus("plugin");
     44 
     45 // Switch obj/embed_elt attributes from plugin to image
     46 objElt.data = "large-pic.jpg";
     47 objElt.width = 100;
     48 objElt.height = 100;
     49 objElt.type = "image/jpg";
     50 objEltWithIdx.data = "large-pic.jpg";
     51 objEltWithIdx.width = 100;
     52 objEltWithIdx.height = 100;
     53 objEltWithIdx.type = "image/jpg";
     54 embedElt.src = "large-pic.jpg";
     55 embedElt.width = 100;
     56 embedElt.height = 100;
     57 embedElt.type = "image/jpg";
     58 
     59 // As images, obj/embed_elt can take focus as image
     60 // object image elements require a tabindex to accept focus. 
     61 // embed elements must be reparented before new type is recognized.
     62 checkFocusable(false, "<object> image", objElt);
     63 checkFocusable(true, "<object> image with tabindex", objEltWithIdx);
     64 checkFocusable(true, "<embed> plugin with image attribs before reparenting", embedElt);
     65 embedElt.parentNode.appendChild(embedElt);
     66 checkFocusable(true, "<embed> image", embedElt);
     67 
     68 // Switch obj/embed_elt attributes from image to plugin
     69 objElt.type = "application/x-shockwave-flash";
     70 embedElt.type = "application/x-shockwave-flash";
     71 
     72 // embed elements must be reparented before new type is recognized.
     73 checkFocusable(true, "<embed> image with plugin attribs", embedElt);
     74 embedElt.parentNode.appendChild(embedElt);
     75 checkNoneHasFocus("plugin");
     76 </script>
     77 </body>
     78 </html>