tor-browser

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

test_bug674770-2.html (11797B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=674770
      5 -->
      6 <head>
      7  <title>Test for Bug 674770</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=674770">Mozilla Bug 674770</a>
     14 <p id="display"></p>
     15 <div id="content">
     16 <iframe id="iframe" style="display: block; height: 14em;"
     17  srcdoc="<input id='text' value='pasted'><input id='input' style='display: block;'><p id='editor1' contenteditable>editor1:</p><p id='editor2' contenteditable>editor2:</p>"></iframe>
     18 </div>
     19 <pre id="test">
     20 <script type="application/javascript">
     21 
     22 /** Test for Bug 674770 */
     23 SimpleTest.waitForExplicitFinish();
     24 
     25 var iframe = document.getElementById("iframe");
     26 var frameWindow, frameDocument;
     27 
     28 var gClicked = false;
     29 var gClicking = null;
     30 var gDoPreventDefault1 = null;
     31 var gDoPreventDefault2 = null;
     32 
     33 function clickEventHandler(aEvent) {
     34  if (aEvent.button == 1 && aEvent.target == gClicking) {
     35    gClicked = true;
     36  }
     37  if (gDoPreventDefault1 == aEvent.target) {
     38    aEvent.preventDefault();
     39  }
     40  if (gDoPreventDefault2 == aEvent.target) {
     41    aEvent.preventDefault();
     42  }
     43 }
     44 
     45 // NOTE: tests need to check the result *after* the content is actually
     46 //       modified.  Sometimes, the modification is delayed. Therefore, there
     47 //       are a lot of functions and SimpleTest.executeSoon()s.
     48 SimpleTest.waitForFocus(function() {
     49  SpecialPowers.pushPrefEnv({"set": [["middlemouse.contentLoadURL", false],
     50                                     ["middlemouse.paste", true]]}, startTest);
     51 });
     52 function startTest() {
     53  frameWindow = iframe.contentWindow;
     54  frameDocument = iframe.contentDocument;
     55 
     56  frameDocument.getElementById("input").addEventListener("click", clickEventHandler);
     57  frameDocument.getElementById("editor1").addEventListener("click", clickEventHandler);
     58  frameDocument.getElementById("editor2").addEventListener("click", clickEventHandler);
     59 
     60  var text = frameDocument.getElementById("text");
     61 
     62  text.focus();
     63  synthesizeKey("a", { accelKey: true }, frameWindow);
     64  // Windows and Mac don't have primary selection, we should copy the text to
     65  // the global clipboard.
     66  if (!SpecialPowers.supportsSelectionClipboard()) {
     67    SimpleTest.waitForClipboard("pasted",
     68      function() { synthesizeKey("c", { accelKey: true }, frameWindow); },
     69      function() { SimpleTest.executeSoon(runInputTests1); },
     70      cleanup);
     71  } else {
     72    // Otherwise, don't call waitForClipboard since it breaks primary
     73    // selection.
     74    runInputTests1();
     75  }
     76 }
     77 
     78 function runInputTests1() {
     79  var input = frameDocument.getElementById("input");
     80 
     81  // first, copy text.
     82 
     83  // when middle clicked in focused input element, text should be pasted.
     84  input.value = "";
     85  input.focus();
     86 
     87  SimpleTest.executeSoon(function() {
     88    gClicked = false;
     89    gClicking = input;
     90    gDoPreventDefault1 = null;
     91    gDoPreventDefault2 = null;
     92 
     93    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
     94 
     95    SimpleTest.executeSoon(function() {
     96      todo(gClicked, "click event hasn't been fired for runInputTests1");
     97      is(input.value, "pasted", "failed to paste in input element");
     98 
     99      SimpleTest.executeSoon(runInputTests2);
    100    });
    101  });
    102 }
    103 
    104 function runInputTests2() {
    105  var input = frameDocument.getElementById("input");
    106 
    107  // even if the input element hasn't had focus, middle click should set focus
    108  // to it and paste the text.
    109  input.value = "";
    110  input.blur();
    111 
    112  SimpleTest.executeSoon(function() {
    113    gClicked = false;
    114    gClicking = input;
    115    gDoPreventDefault1 = null;
    116    gDoPreventDefault2 = null;
    117 
    118    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
    119 
    120    SimpleTest.executeSoon(function() {
    121      todo(gClicked, "click event hasn't been fired for runInputTests2");
    122      is(input.value, "pasted",
    123         "failed to paste in input element when it hasn't had focus yet");
    124 
    125      SimpleTest.executeSoon(runInputTests3);
    126    });
    127  });
    128 }
    129 
    130 function runInputTests3() {
    131  var input = frameDocument.getElementById("input");
    132  var editor1 = frameDocument.getElementById("editor1");
    133 
    134  // preventDefault() of HTML editor's click event handler shouldn't prevent
    135  // middle click pasting in input element.
    136  input.value = "";
    137  input.focus();
    138 
    139  SimpleTest.executeSoon(function() {
    140    gClicked = false;
    141    gClicking = input;
    142    gDoPreventDefault1 = editor1;
    143    gDoPreventDefault2 = null;
    144 
    145    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
    146 
    147    SimpleTest.executeSoon(function() {
    148      todo(gClicked, "click event hasn't been fired for runInputTests3");
    149      is(input.value, "pasted",
    150         "failed to paste in input element when editor1 does preventDefault()");
    151 
    152      SimpleTest.executeSoon(runInputTests4);
    153    });
    154  });
    155 }
    156 
    157 function runInputTests4() {
    158  var input = frameDocument.getElementById("input");
    159 
    160  // preventDefault() of input element's click event handler should prevent
    161  // middle click pasting in it.
    162  input.value = "";
    163  input.focus();
    164 
    165  SimpleTest.executeSoon(function() {
    166    gClicked = false;
    167    gClicking = input;
    168    gDoPreventDefault1 = input;
    169    gDoPreventDefault2 = null;
    170 
    171    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
    172 
    173    SimpleTest.executeSoon(function() {
    174      todo(gClicked, "click event hasn't been fired for runInputTests4");
    175      todo_is(input.value, "",
    176         "pasted in input element when it does preventDefault()");
    177 
    178      SimpleTest.executeSoon(runContentEditableTests1);
    179    });
    180  });
    181 }
    182 
    183 function runContentEditableTests1() {
    184  var editor1 = frameDocument.getElementById("editor1");
    185 
    186  // when middle clicked in focused contentediable editor, text should be
    187  // pasted.
    188  editor1.innerHTML = "editor1:";
    189  editor1.focus();
    190 
    191  SimpleTest.executeSoon(function() {
    192    gClicked = false;
    193    gClicking = editor1;
    194    gDoPreventDefault1 = null;
    195    gDoPreventDefault2 = null;
    196 
    197    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
    198 
    199    SimpleTest.executeSoon(function() {
    200      todo(gClicked, "click event hasn't been fired for runContentEditableTests1");
    201      is(editor1.innerHTML, "editor1:pasted",
    202         "failed to paste text in contenteditable editor");
    203      SimpleTest.executeSoon(runContentEditableTests2);
    204    });
    205  });
    206 }
    207 
    208 function runContentEditableTests2() {
    209  var editor1 = frameDocument.getElementById("editor1");
    210 
    211  // even if the contenteditable editor hasn't had focus, middle click should
    212  // set focus to it and paste the text.
    213  editor1.innerHTML = "editor1:";
    214  editor1.blur();
    215 
    216  SimpleTest.executeSoon(function() {
    217    gClicked = false;
    218    gClicking = editor1;
    219    gDoPreventDefault1 = null;
    220    gDoPreventDefault2 = null;
    221 
    222    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
    223 
    224    SimpleTest.executeSoon(function() {
    225      todo(gClicked, "click event hasn't been fired for runContentEditableTests2");
    226      is(editor1.innerHTML, "editor1:pasted",
    227         "failed to paste in contenteditable editor #1 when it hasn't had focus yet");
    228      SimpleTest.executeSoon(runContentEditableTests3);
    229    });
    230  });
    231 }
    232 
    233 function runContentEditableTests3() {
    234  var editor1 = frameDocument.getElementById("editor1");
    235  var editor2 = frameDocument.getElementById("editor2");
    236 
    237  // When editor1 has focus but editor2 is middle clicked, should be pasted
    238  // in the editor2.
    239  editor1.innerHTML = "editor1:";
    240  editor2.innerHTML = "editor2:";
    241  editor1.focus();
    242 
    243  SimpleTest.executeSoon(function() {
    244    gClicked = false;
    245    gClicking = editor2;
    246    gDoPreventDefault1 = null;
    247    gDoPreventDefault2 = null;
    248 
    249    synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
    250 
    251    SimpleTest.executeSoon(function() {
    252      todo(gClicked, "click event hasn't been fired for runContentEditableTests3");
    253      is(editor1.innerHTML, "editor1:",
    254         "pasted in contenteditable editor #1 when editor2 is clicked");
    255      is(editor2.innerHTML, "editor2:pasted",
    256         "failed to paste in contenteditable editor #2 when editor2 is clicked");
    257      SimpleTest.executeSoon(runContentEditableTests4);
    258    });
    259  });
    260 }
    261 
    262 function runContentEditableTests4() {
    263  var editor1 = frameDocument.getElementById("editor1");
    264 
    265  // preventDefault() of editor1's click event handler should prevent
    266  // middle click pasting in it.
    267  editor1.innerHTML = "editor1:";
    268  editor1.focus();
    269 
    270  SimpleTest.executeSoon(function() {
    271    gClicked = false;
    272    gClicking = editor1;
    273    gDoPreventDefault1 = editor1;
    274    gDoPreventDefault2 = null;
    275 
    276    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
    277 
    278    SimpleTest.executeSoon(function() {
    279      todo(gClicked, "click event hasn't been fired for runContentEditableTests4");
    280      todo_is(editor1.innerHTML, "editor1:",
    281         "pasted in contenteditable editor #1 when it does preventDefault()");
    282      SimpleTest.executeSoon(runContentEditableTests5);
    283    });
    284  });
    285 }
    286 
    287 function runContentEditableTests5() {
    288  var editor1 = frameDocument.getElementById("editor1");
    289  var editor2 = frameDocument.getElementById("editor2");
    290 
    291  // preventDefault() of editor1's click event handler shouldn't prevent
    292  // middle click pasting in editor2.
    293  editor1.innerHTML = "editor1:";
    294  editor2.innerHTML = "editor2:";
    295  editor2.focus();
    296 
    297  SimpleTest.executeSoon(function() {
    298    gClicked = false;
    299    gClicking = editor2;
    300    gDoPreventDefault1 = editor1;
    301    gDoPreventDefault2 = null;
    302 
    303    synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
    304 
    305    SimpleTest.executeSoon(function() {
    306      todo(gClicked, "click event hasn't been fired for runContentEditableTests5");
    307      is(editor1.innerHTML, "editor1:",
    308         "pasted in contenteditable editor #1?");
    309      is(editor2.innerHTML, "editor2:pasted",
    310         "failed to paste in contenteditable editor #2");
    311 
    312      SimpleTest.executeSoon(initForBodyEditableDocumentTests);
    313    });
    314  });
    315 }
    316 
    317 function initForBodyEditableDocumentTests() {
    318  frameDocument.getElementById("input").removeEventListener("click", clickEventHandler);
    319  frameDocument.getElementById("editor1").removeEventListener("click", clickEventHandler);
    320  frameDocument.getElementById("editor2").removeEventListener("click", clickEventHandler);
    321 
    322  iframe.onload =
    323    function() { SimpleTest.executeSoon(runBodyEditableDocumentTests1); };
    324  iframe.srcdoc = "<body contenteditable>body:</body>";
    325 }
    326 
    327 function runBodyEditableDocumentTests1() {
    328  frameWindow = iframe.contentWindow;
    329  frameDocument = iframe.contentDocument;
    330 
    331  var body = frameDocument.body;
    332 
    333  is(body.innerHTML, "body:",
    334     "failed to initialize at runBodyEditableDocumentTests1");
    335 
    336  // middle click on html element should cause pasting text in its body.
    337  synthesizeMouseAtCenter(frameDocument.documentElement, {button: 1}, frameWindow);
    338 
    339  SimpleTest.executeSoon(function() {
    340    is(body.innerHTML,
    341       "body:pasted",
    342       "failed to paste in editable body element when clicked on html element");
    343 
    344    SimpleTest.executeSoon(runBodyEditableDocumentTests2);
    345  });
    346 }
    347 
    348 function runBodyEditableDocumentTests2() {
    349  frameDocument.body.innerHTML = "body:<span id='span' contenteditable='false'>non-editable</span>";
    350 
    351  var body = frameDocument.body;
    352 
    353  is(body.innerHTML, "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
    354     "failed to initialize at runBodyEditableDocumentTests2");
    355 
    356  synthesizeMouseAtCenter(frameDocument.getElementById("span"), {button: 1}, frameWindow);
    357 
    358  SimpleTest.executeSoon(function() {
    359    is(body.innerHTML,
    360       "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
    361       "pasted when middle clicked in non-editable element");
    362 
    363    SimpleTest.executeSoon(cleanup);
    364  });
    365 }
    366 
    367 function cleanup() {
    368  SimpleTest.finish();
    369 }
    370 
    371 </script>
    372 </pre>
    373 </body>
    374 </html>