Thu, 15 Jan 2015 15:59:08 +0100
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=391994 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 391994</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391994">Mozilla Bug 391994</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 391994 **/ |
michael@0 | 21 | var testNumber = 0; |
michael@0 | 22 | |
michael@0 | 23 | function assertSelected(aOption, aExpectDefaultSelected, aExpectSelected) { |
michael@0 | 24 | ++testNumber; |
michael@0 | 25 | is(aOption.defaultSelected, aExpectDefaultSelected, |
michael@0 | 26 | "Asserting default-selected state for option " + testNumber); |
michael@0 | 27 | is(aOption.selected, aExpectSelected, |
michael@0 | 28 | "Asserting selected state for option " + testNumber); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function assertSame(aSel1, aSel2Str, aTestNumber) { |
michael@0 | 32 | var div = document.createElement("div"); |
michael@0 | 33 | div.innerHTML = aSel2Str; |
michael@0 | 34 | sel2 = div.firstChild; |
michael@0 | 35 | is(aSel1.options.length, sel2.options.length, |
michael@0 | 36 | "Length should be same in select test " + aTestNumber); |
michael@0 | 37 | is(aSel1.selectedIndex, sel2.selectedIndex, |
michael@0 | 38 | "Selected index should be same in select test " + aTestNumber); |
michael@0 | 39 | for (var i = 0; i < aSel1.options.length; ++i) { |
michael@0 | 40 | is(aSel1.options[i].selected, sel2.options[i].selected, |
michael@0 | 41 | "Options[" + i + "].selected should be the same in select test " + |
michael@0 | 42 | aTestNumber); |
michael@0 | 43 | is(aSel1.options[i].defaultSelected, sel2.options[i].defaultSelected, |
michael@0 | 44 | "Options[" + i + |
michael@0 | 45 | "].defaultSelected should be the same in select test " + |
michael@0 | 46 | aTestNumber); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | // Creation methods |
michael@0 | 51 | var opt = document.createElement("option"); |
michael@0 | 52 | assertSelected(opt, false, false); |
michael@0 | 53 | |
michael@0 | 54 | opt = new Option(); |
michael@0 | 55 | assertSelected(opt, false, false); |
michael@0 | 56 | |
michael@0 | 57 | // Setting of defaultSelected |
michael@0 | 58 | opt = new Option(); |
michael@0 | 59 | opt.setAttribute("selected", "selected"); |
michael@0 | 60 | assertSelected(opt, true, true); |
michael@0 | 61 | |
michael@0 | 62 | opt = new Option(); |
michael@0 | 63 | opt.defaultSelected = true; |
michael@0 | 64 | assertSelected(opt, true, true); |
michael@0 | 65 | is(opt.hasAttribute("selected"), true, "Attribute should be set"); |
michael@0 | 66 | is(opt.getAttribute("selected"), "", |
michael@0 | 67 | "Attribute should be set to empty string"); |
michael@0 | 68 | |
michael@0 | 69 | // Setting of selected |
michael@0 | 70 | opt = new Option(); |
michael@0 | 71 | opt.selected = false; |
michael@0 | 72 | assertSelected(opt, false, false); |
michael@0 | 73 | |
michael@0 | 74 | opt = new Option(); |
michael@0 | 75 | opt.selected = true; |
michael@0 | 76 | assertSelected(opt, false, true); |
michael@0 | 77 | |
michael@0 | 78 | // Interaction of selected and defaultSelected |
michael@0 | 79 | opt = new Option(); |
michael@0 | 80 | opt.selected; |
michael@0 | 81 | opt.setAttribute("selected", "selected"); |
michael@0 | 82 | assertSelected(opt, true, true); |
michael@0 | 83 | |
michael@0 | 84 | opt = new Option(); |
michael@0 | 85 | opt.selected = false; |
michael@0 | 86 | opt.setAttribute("selected", "selected"); |
michael@0 | 87 | assertSelected(opt, true, false); |
michael@0 | 88 | |
michael@0 | 89 | opt = new Option(); |
michael@0 | 90 | opt.setAttribute("selected", "selected"); |
michael@0 | 91 | opt.selected = true; |
michael@0 | 92 | opt.removeAttribute("selected"); |
michael@0 | 93 | assertSelected(opt, false, true); |
michael@0 | 94 | |
michael@0 | 95 | // First test of putting things in a <select>: Adding default-selected option |
michael@0 | 96 | // should select it. |
michael@0 | 97 | var sel = document.createElement("select"); |
michael@0 | 98 | sel.appendChild(new Option()); |
michael@0 | 99 | is(sel.selectedIndex, 0, "First option should be selected"); |
michael@0 | 100 | assertSelected(sel.firstChild, false, true); |
michael@0 | 101 | |
michael@0 | 102 | sel.appendChild(new Option()); |
michael@0 | 103 | is(sel.selectedIndex, 0, "First option should still be selected"); |
michael@0 | 104 | assertSelected(sel.firstChild, false, true); |
michael@0 | 105 | assertSelected(sel.firstChild.nextSibling, false, false); |
michael@0 | 106 | |
michael@0 | 107 | opt = new Option(); |
michael@0 | 108 | opt.defaultSelected = true; |
michael@0 | 109 | sel.appendChild(opt); |
michael@0 | 110 | assertSelected(sel.firstChild, false, false); |
michael@0 | 111 | assertSelected(sel.firstChild.nextSibling, false, false); |
michael@0 | 112 | assertSelected(opt, true, true); |
michael@0 | 113 | is(opt, sel.firstChild.nextSibling.nextSibling, "What happened here?"); |
michael@0 | 114 | is(sel.options[0], sel.firstChild, "Unexpected option 0"); |
michael@0 | 115 | is(sel.options[1], sel.firstChild.nextSibling, "Unexpected option 1"); |
michael@0 | 116 | is(sel.options[2], opt, "Unexpected option 2"); |
michael@0 | 117 | is(sel.selectedIndex, 2, "Unexpected selectedIndex in select test 1"); |
michael@0 | 118 | |
michael@0 | 119 | assertSame(sel, "<select><option><option><option selected></select>", 1); |
michael@0 | 120 | |
michael@0 | 121 | // Second test of putting things in a <select>: Adding two default-selected |
michael@0 | 122 | // options should select the second one. |
michael@0 | 123 | sel = document.createElement("select"); |
michael@0 | 124 | sel.appendChild(new Option()); |
michael@0 | 125 | sel.appendChild(new Option()); |
michael@0 | 126 | opt = new Option(); |
michael@0 | 127 | opt.defaultSelected = true; |
michael@0 | 128 | sel.appendChild(opt); |
michael@0 | 129 | opt = new Option(); |
michael@0 | 130 | opt.defaultSelected = true; |
michael@0 | 131 | sel.appendChild(opt); |
michael@0 | 132 | assertSelected(sel.options[0], false, false); |
michael@0 | 133 | assertSelected(sel.options[1], false, false); |
michael@0 | 134 | assertSelected(sel.options[2], true, false); |
michael@0 | 135 | assertSelected(sel.options[3], true, true); |
michael@0 | 136 | is(sel.selectedIndex, 3, "Unexpected selectedIndex in select test 2"); |
michael@0 | 137 | |
michael@0 | 138 | assertSame(sel, |
michael@0 | 139 | "<select><option><option><option selected><option selected></select>", 2); |
michael@0 | 140 | |
michael@0 | 141 | // Third test of putting things in a <select>: adding a selected option earlier |
michael@0 | 142 | // than another selected option should make the new option selected. |
michael@0 | 143 | sel = document.createElement("select"); |
michael@0 | 144 | sel.appendChild(new Option()); |
michael@0 | 145 | sel.appendChild(new Option()); |
michael@0 | 146 | opt = new Option(); |
michael@0 | 147 | opt.defaultSelected = true; |
michael@0 | 148 | sel.appendChild(opt); |
michael@0 | 149 | opt = new Option(); |
michael@0 | 150 | opt.defaultSelected = true; |
michael@0 | 151 | sel.options[0] = opt; |
michael@0 | 152 | assertSelected(sel.options[0], true, true); |
michael@0 | 153 | assertSelected(sel.options[1], false, false); |
michael@0 | 154 | assertSelected(sel.options[2], true, false); |
michael@0 | 155 | is(sel.selectedIndex, 0, "Unexpected selectedIndex in select test 3"); |
michael@0 | 156 | |
michael@0 | 157 | // Fourth test of putting things in a <select>: Just like second test, but with |
michael@0 | 158 | // a <select multiple> |
michael@0 | 159 | sel = document.createElement("select"); |
michael@0 | 160 | sel.multiple = true; |
michael@0 | 161 | sel.appendChild(new Option()); |
michael@0 | 162 | sel.appendChild(new Option()); |
michael@0 | 163 | opt = new Option(); |
michael@0 | 164 | opt.defaultSelected = true; |
michael@0 | 165 | sel.appendChild(opt); |
michael@0 | 166 | opt = new Option(); |
michael@0 | 167 | opt.defaultSelected = true; |
michael@0 | 168 | sel.appendChild(opt); |
michael@0 | 169 | assertSelected(sel.options[0], false, false); |
michael@0 | 170 | assertSelected(sel.options[1], false, false); |
michael@0 | 171 | assertSelected(sel.options[2], true, true); |
michael@0 | 172 | assertSelected(sel.options[3], true, true); |
michael@0 | 173 | is(sel.selectedIndex, 2, "Unexpected selectedIndex in select test 4"); |
michael@0 | 174 | |
michael@0 | 175 | assertSame(sel, |
michael@0 | 176 | "<select multiple><option><option>" + |
michael@0 | 177 | "<option selected><option selected></select>", |
michael@0 | 178 | 4); |
michael@0 | 179 | |
michael@0 | 180 | </script> |
michael@0 | 181 | </pre> |
michael@0 | 182 | </body> |
michael@0 | 183 | </html> |
michael@0 | 184 |