content/base/test/test_bug331959.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=331959
     5 -->
     6 <head>
     7   <title>Test for Bug 331959</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="application/javascript" 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=331959">Mozilla Bug 331959</a>
    14 <p id="display">
    15   <iframe id="link-in-link-mouse"></iframe>
    16   <iframe id="link-in-link-keyboard"></iframe>
    17   <iframe id="input-in-link-mouse"></iframe>
    18   <iframe id="input-in-link-keyboard"></iframe>
    19   <iframe id="button-in-link-mouse"></iframe>
    20   <iframe id="button-in-link-keyboard"></iframe>
    21 </p>
    22 <div id="content" style="display: none">
    24 </div>
    25 <pre id="test">
    26 <script type="application/javascript">
    28 /** Test for Bug 331959 **/
    29 SimpleTest.waitForExplicitFinish();
    31 const FAILURL = "data:text/plain,FAIL";
    32 const PASSURL = "data:text/plain,PASS";
    34 var currentTest = 0;
    35 var tests = [ testLinkInLinkMouse, testLinkInLinkKeyboard,
    36               testInputInLinkMouse, testInputInLinkKeyboard,
    37               testButtonInLinkMouse, testButtonInLinkKeyboard ];
    38 function doNextTest() {
    39   if (currentTest == tests.length) {
    40     SimpleTest.finish();
    41   } else {
    42     tests[currentTest++]();
    43   }
    44 }
    46 function generateLinkInLink(id, desc) {
    47   var doc = $(id).contentDocument;
    48   var outerA = doc.createElement("a");
    49   var innerA = doc.createElement("a");
    50   outerA.id = "outer";
    51   innerA.id = "inner";
    52   innerA.href = PASSURL;
    53   outerA.href = FAILURL;
    54   innerA.appendChild(doc.createTextNode("Text"));
    55   outerA.appendChild(innerA);
    56   doc.body.appendChild(outerA);
    57   $(id).onload = function() {
    58     is(this.contentDocument.documentElement.textContent, "PASS", desc);
    59     // Have to remove the iframe we used from the DOM, because the harness is
    60     // stupid and doesn't have enough space for more than one iframe.
    61     $(id).parentNode.removeChild($(id));
    62     doNextTest();
    63   };
    64   return [innerA, $(id).contentWindow];
    65 }
    67 function testLinkInLinkMouse() {
    68   var [innerA, testWin] =
    69     generateLinkInLink("link-in-link-mouse",
    70                        "Clicking an inner link should load the inner link");
    71   synthesizeMouseAtCenter(innerA, {}, testWin);
    72 }
    74 function testLinkInLinkKeyboard() {
    75   var [innerA, testWin] =
    76     generateLinkInLink("link-in-link-keyboard",
    77                        "Hitting enter on an inner link should load the inner link");
    78   innerA.focus();
    79   synthesizeKey("VK_RETURN", {}, testWin);
    80 }
    82 function generateInputInLink(id, desc) {
    83   var doc = $(id).contentDocument;
    84   doc.body.innerHTML =
    85     "<form action='" + PASSURL + "'><a href='" + FAILURL +
    86     "'><input type='submit' id='submit'>";
    87   $(id).onload = function() {
    88     is(this.contentDocument.documentElement.textContent, "PASS?", desc);
    89     // Have to remove the iframe we used from the DOM, because the harness is
    90     // stupid and doesn't have enough space for more than one iframe.
    91     $(id).parentNode.removeChild($(id));
    92     doNextTest();
    93   };
    94   var input = doc.getElementById("submit");
    95   doc.body.offsetWidth;
    96   return [input, $(id).contentWindow];
    97 }
    99 function testInputInLinkMouse() {
   100   var [input, testWin] =
   101     generateInputInLink("input-in-link-mouse",
   102                         "Clicking an submit input inside an anchor should submit the form");
   103   synthesizeMouseAtCenter(input, {}, testWin);
   104 }
   106 function testInputInLinkKeyboard() {
   107   var [input, testWin] =
   108     generateInputInLink("input-in-link-keyboard",
   109                         "Return on submit input inside an anchor should submit the form");
   110   input.focus();
   111   synthesizeKey("VK_RETURN", {}, testWin);
   112 }
   114 function generateButtonInLink(id, desc) {
   115   var doc = $(id).contentDocument;
   116   doc.body.innerHTML =
   117     "<form action='" + PASSURL + "'><a href='" + FAILURL +
   118     "'><button type='submit' id='submit'>Submit</button>";
   119   $(id).onload = function() {
   120     is(this.contentDocument.documentElement.textContent, "PASS?", desc);
   121     // Have to remove the iframe we used from the DOM, because the harness is
   122     // stupid and doesn't have enough space for more than one iframe.
   123     $(id).parentNode.removeChild($(id));
   124     doNextTest();
   125   };
   126   var button = doc.getElementById("submit");
   127   return [button, $(id).contentWindow];
   128 }
   130 function testButtonInLinkMouse() {
   131   var [button, testWin] =
   132     generateButtonInLink("button-in-link-mouse",
   133                         "Clicking an submit button inside an anchor should submit the form");
   134   synthesizeMouseAtCenter(button, {}, testWin);
   135 }
   137 function testButtonInLinkKeyboard() {
   138   var [button, testWin] =
   139     generateButtonInLink("button-in-link-keyboard",
   140                         "Return on submit button inside an anchor should submit the form");
   141   button.focus();
   142   synthesizeKey("VK_RETURN", {}, testWin);
   143 }
   145 // We need focus to handle clicks properly
   146 SimpleTest.waitForFocus(doNextTest);
   148 </script>
   149 </pre>
   150 </body>
   151 </html>

mercurial