content/html/content/test/test_bug561636.html

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=561636
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 561636</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=561636">Mozilla Bug 561636</a>
michael@0 14 <p id="display"></p>
michael@0 15 <iframe style='width:50px; height: 50px;' name='t'></iframe>
michael@0 16 <iframe style='width:50px; height: 50px;' name='t2' id='i'></iframe>
michael@0 17 <div id="content">
michael@0 18 <form target='t' action='data:text/html,'>
michael@0 19 <input required>
michael@0 20 <input id='a' type='submit'>
michael@0 21 </form>
michael@0 22 <form target='t' action='data:text/html,'>
michael@0 23 <input type='checkbox' required>
michael@0 24 <button id='b' type='submit'></button>
michael@0 25 </form>
michael@0 26 <form target='t' action='data:text/html,'>
michael@0 27 <input id='c' required>
michael@0 28 </form>
michael@0 29 <form target='t' action='data:text/html,'>
michael@0 30 <input>
michael@0 31 <input id='s2' type='submit'>
michael@0 32 </form>
michael@0 33 <form target='t2' action='data:text/html,'>
michael@0 34 <input required>
michael@0 35 </form>
michael@0 36 </div>
michael@0 37 <pre id="test">
michael@0 38 <script type="application/javascript">
michael@0 39
michael@0 40 /** Test for Bug 561636 **/
michael@0 41
michael@0 42 SimpleTest.waitForExplicitFinish();
michael@0 43 addLoadEvent(runTest);
michael@0 44
michael@0 45 function runTest()
michael@0 46 {
michael@0 47 var formSubmitted = [ false, false ];
michael@0 48 var invalidHandled = false;
michael@0 49
michael@0 50 var os = SpecialPowers.Cc['@mozilla.org/observer-service;1']
michael@0 51 .getService(SpecialPowers.Ci.nsIObserverService);
michael@0 52 var observers = os.enumerateObservers("invalidformsubmit");
michael@0 53
michael@0 54 // The following test should not be done if there is no observer for
michael@0 55 // "invalidformsubmit" because the form submission will not be canceled in that
michael@0 56 // case.
michael@0 57 if (!observers.hasMoreElements()) {
michael@0 58 SimpleTest.finish();
michael@0 59 return;
michael@0 60 }
michael@0 61
michael@0 62 // Initialize
michael@0 63 document.forms[0].addEventListener('submit', function(aEvent) {
michael@0 64 aEvent.target.removeEventListener('submit', arguments.callee, false);
michael@0 65 formSubmitted[0] = true;
michael@0 66 }, false);
michael@0 67
michael@0 68 document.forms[1].addEventListener('submit', function(aEvent) {
michael@0 69 aEvent.target.removeEventListener('submit', arguments.callee, false);
michael@0 70 formSubmitted[1] = true;
michael@0 71 }, false);
michael@0 72
michael@0 73 document.forms[2].addEventListener('submit', function(aEvent) {
michael@0 74 aEvent.target.removeEventListener('submit', arguments.callee, false);
michael@0 75 formSubmitted[2] = true;
michael@0 76 }, false);
michael@0 77
michael@0 78 document.forms[3].addEventListener('submit', function(aEvent) {
michael@0 79 aEvent.target.removeEventListener('submit', arguments.callee, false);
michael@0 80 formSubmitted[3] = true;
michael@0 81
michael@0 82 ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid");
michael@0 83 ok(!formSubmitted[1], "Form 2 should not have been submitted because invalid");
michael@0 84 ok(!formSubmitted[2], "Form 3 should not have been submitted because invalid");
michael@0 85 ok(formSubmitted[3], "Form 4 should have been submitted because valid");
michael@0 86
michael@0 87 // Next test.
michael@0 88 document.forms[4].submit();
michael@0 89 }, false);
michael@0 90
michael@0 91 document.forms[4].elements[0].addEventListener('invalid', function(aEvent) {
michael@0 92 aEvent.target.removeEventListener('invalid', arguments.callee, false);
michael@0 93 invalidHandled = true;
michael@0 94 }, false);
michael@0 95
michael@0 96 document.getElementById('i').addEventListener('load', function(aEvent) {
michael@0 97 aEvent.target.removeEventListener('load', arguments.callee, false);
michael@0 98
michael@0 99 SimpleTest.executeSoon(function () {
michael@0 100 ok(true, "Form 5 should have been submitted because submit() has been used even if invalid");
michael@0 101 ok(!invalidHandled, "Invalid event should not have been sent");
michael@0 102
michael@0 103 SimpleTest.finish();
michael@0 104 });
michael@0 105 }, false);
michael@0 106
michael@0 107 document.getElementById('a').click();
michael@0 108 document.getElementById('b').click();
michael@0 109 var c = document.getElementById('c');
michael@0 110 c.focus(); synthesizeKey("VK_RETURN", {type: "keypress"});
michael@0 111 document.getElementById('s2').click();
michael@0 112 }
michael@0 113
michael@0 114 </script>
michael@0 115 </pre>
michael@0 116 </body>
michael@0 117 </html>

mercurial