tor-browser

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

test_bug566046.html (7011B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=566046
      5 -->
      6 <head>
      7  <title>Test for Bug 566046</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  <base>
     12  <base target='frame2'>
     13  <base target=''>
     14 </head>
     15 <body>
     16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=566046">Mozilla Bug 566046</a>
     17 <p id="display"></p>
     18 <style>
     19  iframe { width: 130px; height: 100px;}
     20 </style>
     21 <iframe name='frame1' id='frame1'></iframe>
     22 <iframe name='frame2' id='frame2'></iframe>
     23 <iframe name='frame3' id='frame3'></iframe>
     24 <iframe name='frame4' id='frame4'></iframe>
     25 <iframe name='frame5' id='frame5'></iframe>
     26 <iframe name='frame5bis' id='frame5bis'></iframe>
     27 <iframe name='frame6' id='frame6'></iframe>
     28 <iframe name='frame7' id='frame7'></iframe>
     29 <iframe name='frame8' id='frame8'></iframe>
     30 <iframe name='frame9' id='frame9'></iframe>
     31 <div id="content">
     32  <form target='frame1' action="dummy_page.html" method="GET">
     33    <input name='foo' value='foo'>
     34  </form>
     35  <form action="dummy_page.html" method="GET">
     36    <input name='bar' value='bar'>
     37  </form>
     38  <form target="">
     39  </form>
     40 
     41  <!-- submit controls with formtarget that are validated with a CLICK -->
     42  <form target="tulip" action="dummy_page.html" method="GET">
     43    <input name='tulip' value='tulip'>
     44    <input type='submit' id='is' formtarget='frame3'>
     45  </form>
     46  <form action="dummy_page.html" method="GET">
     47    <input name='foobar' value='foobar'>
     48    <input type='image' id='ii' formtarget='frame4'>
     49  </form>
     50  <form action="dummy_page.html" method="GET">
     51    <input name='tulip2' value='tulip2'>
     52    <button type='submit' id='bs' formtarget='frame5'>submit</button>
     53  </form>
     54  <form action="dummy_page.html" method="GET">
     55    <input name='tulip3' value='tulip3'>
     56    <button type='submit' id='bsbis' formtarget='frame5bis'>submit</button>
     57  </form>
     58 
     59  <!-- submit controls with formtarget that are validated with ENTER -->
     60  <form target="tulip" action="dummy_page.html" method="GET">
     61    <input name='footulip' value='footulip'>
     62    <input type='submit' id='is2' formtarget='frame6'>
     63  </form>
     64  <form action="dummy_page.html" method="GET">
     65    <input name='tulipfoobar' value='tulipfoobar'>
     66    <input type='image' id='ii2' formtarget='frame7'>
     67  </form>
     68  <form action="dummy_page.html" method="GET">
     69    <input name='tulipbar' value='tulipbar'>
     70    <button type='submit' id='bs2' formtarget='frame8'>submit</button>
     71  </form>
     72 
     73  <!-- check that a which is not a submit control do not use @formtarget -->
     74  <form target='frame9' action="dummy_page.html" method="GET">
     75    <input id='enter' name='input' value='enter' formtarget='frame6'>
     76  </form>
     77 </div>
     78 <pre id="test">
     79 <script type="application/javascript">
     80 
     81 /** Test for Bug 566046 */
     82 
     83 SimpleTest.waitForExplicitFinish();
     84 addLoadEvent(function() {
     85  setTimeout(runTests, 0);
     86 });
     87 
     88 const BASE_URI = `${location.origin}/tests/dom/html/test/dummy_page.html`;
     89 var gTestResults = {
     90  frame1: BASE_URI + "?foo=foo",
     91  frame2: BASE_URI + "?bar=bar",
     92  frame3: BASE_URI + "?tulip=tulip",
     93  frame4: BASE_URI + "?foobar=foobar&x=0&y=0",
     94  frame5: BASE_URI + "?tulip2=tulip2",
     95  frame5bis: BASE_URI + "?tulip3=tulip3",
     96  frame6: BASE_URI + "?footulip=footulip",
     97  frame7: BASE_URI + "?tulipfoobar=tulipfoobar&x=0&y=0",
     98  frame8: BASE_URI + "?tulipbar=tulipbar",
     99  frame9: BASE_URI + "?input=enter",
    100 };
    101 
    102 var gPendingLoad = 0; // Has to be set after depending on the frames number.
    103 
    104 function runTests()
    105 {
    106  // Check the target IDL attribute.
    107  for (var i=0; i<document.forms.length; ++i) {
    108    var testValue = document.forms[i].getAttribute('target');
    109    is(document.forms[i].target, testValue ? testValue : "",
    110       "target IDL attribute should reflect the target content attribute");
    111  }
    112 
    113  // We add a load event for the frames which will be called when the forms
    114  // will be submitted.
    115  var frames = [ document.getElementById('frame1'),
    116                 document.getElementById('frame2'),
    117                 document.getElementById('frame3'),
    118                 document.getElementById('frame4'),
    119                 document.getElementById('frame5'),
    120                 document.getElementById('frame5bis'),
    121                 document.getElementById('frame6'),
    122                 document.getElementById('frame7'),
    123                 document.getElementById('frame8'),
    124                 document.getElementById('frame9'),
    125               ];
    126  gPendingLoad = frames.length;
    127 
    128  for (var i=0; i<frames.length; i++) {
    129    frames[i].setAttribute('onload', "frameLoaded(this);");
    130  }
    131 
    132  // Submitting only the forms with a valid target.
    133  document.forms[0].submit();
    134  document.forms[1].submit();
    135 
    136  /**
    137   * We are going to focus each element before interacting with either for
    138   * simulating the ENTER key (synthesizeKey) or a click (synthesizeMouse) or
    139   * using .click(). This because it may be needed (ENTER) and because we want
    140   * to have the element visible in the iframe.
    141   *
    142   * Focusing the first element (id='is') is launching the tests.
    143   */
    144  document.getElementById('is').addEventListener('focus', function(aEvent) {
    145    synthesizeMouse(document.getElementById('is'), 5, 5, {});
    146    document.getElementById('ii').focus();
    147  }, {once: true});
    148 
    149  document.getElementById('ii').addEventListener('focus', function(aEvent) {
    150    synthesizeMouse(document.getElementById('ii'), 5, 5, {});
    151    document.getElementById('bs').focus();
    152  }, {once: true});
    153 
    154  document.getElementById('bs').addEventListener('focus', function(aEvent) {
    155    synthesizeMouse(document.getElementById('bs'), 5, 5, {});
    156    document.getElementById('bsbis').focus();
    157  }, {once: true});
    158 
    159  document.getElementById('bsbis').addEventListener('focus', function(aEvent) {
    160    document.getElementById('bsbis').click();
    161    document.getElementById('is2').focus();
    162  }, {once: true});
    163 
    164  document.getElementById('is2').addEventListener('focus', function(aEvent) {
    165    synthesizeKey("KEY_Enter");
    166    document.getElementById('ii2').focus();
    167  }, {once: true});
    168 
    169  document.getElementById('ii2').addEventListener('focus', function(aEvent) {
    170    synthesizeKey("KEY_Enter");
    171    document.getElementById('bs2').focus();
    172  }, {once: true});
    173 
    174  document.getElementById('bs2').addEventListener('focus', function(aEvent) {
    175    synthesizeKey("KEY_Enter");
    176    document.getElementById('enter').focus();
    177  }, {once: true});
    178 
    179  document.getElementById('enter').addEventListener('focus', function(aEvent) {
    180    synthesizeKey("KEY_Enter");
    181  }, {once: true});
    182 
    183  document.getElementById('is').focus();
    184 }
    185 
    186 function frameLoaded(aFrame) {
    187  // Check if when target is unspecified, it fallback correctly to the base
    188  // element target attribute.
    189  is(aFrame.contentWindow.location.href, gTestResults[aFrame.name],
    190     "the target attribute doesn't have the correct behavior");
    191 
    192  if (--gPendingLoad == 0) {
    193    SimpleTest.finish();
    194  }
    195 }
    196 
    197 </script>
    198 </pre>
    199 </body>
    200 </html>