Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=384147 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 384147</title> |
michael@0 | 8 | <script type="text/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=384147">Mozilla Bug 384147</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: block"> |
michael@0 | 16 | <div contentEditable id="editor"></div> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript;version=1.7"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 384147 **/ |
michael@0 | 22 | |
michael@0 | 23 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 24 | |
michael@0 | 25 | var editor = document.getElementById("editor"); |
michael@0 | 26 | |
michael@0 | 27 | editor.innerHTML = "<ol><li>Item 1</li><li>Item 2</li><ol><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>"; |
michael@0 | 28 | editor.focus(); |
michael@0 | 29 | |
michael@0 | 30 | // If executed directly, a race condition exists that will cause execCommand |
michael@0 | 31 | // to fail occasionally (but often). Defer test execution to page load. |
michael@0 | 32 | addLoadEvent(function() { |
michael@0 | 33 | |
michael@0 | 34 | var sel = window.getSelection(); |
michael@0 | 35 | |
michael@0 | 36 | // Test the effect that the tab key has on list items. Each test is |
michael@0 | 37 | // documented with the initial state of the list on the left, and the |
michael@0 | 38 | // expected state of the list on the right. {\t} indicates the list item |
michael@0 | 39 | // that will be indented. {\st} indicates that a shift-tab will be simulated |
michael@0 | 40 | // on that list item, outdenting it. |
michael@0 | 41 | // |
michael@0 | 42 | // Note: any test failing will likely result in all following tests failing |
michael@0 | 43 | // as well, since each test depends on the document being in a given state. |
michael@0 | 44 | // Unfortunately, due to the problems getting document focus and key events |
michael@0 | 45 | // to fire consistently, it's difficult to reset state between tests. |
michael@0 | 46 | // If there are test failures here, only debug the first test failure. |
michael@0 | 47 | |
michael@0 | 48 | // *** test 1 *** |
michael@0 | 49 | // 1. Item 1 1. Item 1 |
michael@0 | 50 | // 2. {\t}Item 2 1. Item 2 |
michael@0 | 51 | // 1. Item 3 2. Item 3 |
michael@0 | 52 | // * Item 4 * Item 4 |
michael@0 | 53 | // * Item 5 * Item 5 |
michael@0 | 54 | sel.removeAllRanges(); |
michael@0 | 55 | sel.selectAllChildren(editor.getElementsByTagName("li")[1]); |
michael@0 | 56 | document.execCommand("indent", false, null); |
michael@0 | 57 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 58 | "html output doesn't match expected value in test 1"); |
michael@0 | 59 | |
michael@0 | 60 | // *** test 2 *** |
michael@0 | 61 | // 1. Item 1 1. Item 1 |
michael@0 | 62 | // 1. Item 2 1. Item 2 |
michael@0 | 63 | // 2. {\t}Item 3 1. Item 3 |
michael@0 | 64 | // * Item 4 * Item 4 |
michael@0 | 65 | // * Item 5 * Item 5 |
michael@0 | 66 | sel.removeAllRanges(); |
michael@0 | 67 | sel.selectAllChildren(editor.getElementsByTagName("li")[2]); |
michael@0 | 68 | document.execCommand("indent", false, null); |
michael@0 | 69 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><ol><li>Item 3</li></ol></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 70 | "html output doesn't match expected value in test 2"); |
michael@0 | 71 | |
michael@0 | 72 | // *** test 3 *** |
michael@0 | 73 | // 1. Item 1 1. Item 1 |
michael@0 | 74 | // 1. Item 2 1. Item 2 |
michael@0 | 75 | // 1. {\st}Item 3 2. Item 3 |
michael@0 | 76 | // * Item 4 * Item 4 |
michael@0 | 77 | // * Item 5 * Item 5 |
michael@0 | 78 | document.execCommand("outdent", false, null); |
michael@0 | 79 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 80 | "html output doesn't match expected value in test 3"); |
michael@0 | 81 | |
michael@0 | 82 | // *** test 4 *** |
michael@0 | 83 | // 1. Item 1 1. Item 1 |
michael@0 | 84 | // 1. Item 2 1. Item 2 |
michael@0 | 85 | // 2. {\st}Item 3 2. Item 3 |
michael@0 | 86 | // * Item 4 * Item 4 |
michael@0 | 87 | // * Item 5 * Item 5 |
michael@0 | 88 | document.execCommand("outdent", false, null); |
michael@0 | 89 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li></ol><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 90 | "html output doesn't match expected value in test 4"); |
michael@0 | 91 | |
michael@0 | 92 | // *** test 5 *** |
michael@0 | 93 | // 1. Item 1 1. Item 1 |
michael@0 | 94 | // 1. {\st}Item 2 2. Item 2 |
michael@0 | 95 | // 2. Item 3 3. Item 3 |
michael@0 | 96 | // * Item 4 * Item 4 |
michael@0 | 97 | // * Item 5 * Item 5 |
michael@0 | 98 | sel.removeAllRanges(); |
michael@0 | 99 | sel.selectAllChildren(editor.getElementsByTagName("li")[1]); |
michael@0 | 100 | document.execCommand("outdent", false, null); |
michael@0 | 101 | ok(editor.innerHTML == "<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 102 | "html output doesn't match expected value in test 5"); |
michael@0 | 103 | |
michael@0 | 104 | // *** test 6 *** |
michael@0 | 105 | // 1. Item 1 1. Item 1 |
michael@0 | 106 | // 2. {\t}Item 2 1. Item 2 |
michael@0 | 107 | // 3. Item 3 2. Item 3 |
michael@0 | 108 | // * Item 4 * Item 4 |
michael@0 | 109 | // * Item 5 * Item 5 |
michael@0 | 110 | document.execCommand("indent", false, null); |
michael@0 | 111 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li></ol><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 112 | "html output doesn't match expected value in test 6"); |
michael@0 | 113 | |
michael@0 | 114 | // *** test 7 *** |
michael@0 | 115 | // 1. Item 1 1. Item 1 |
michael@0 | 116 | // 1. Item 2 1. Item 2 |
michael@0 | 117 | // 2. {\t}Item 3 2. Item 3 |
michael@0 | 118 | // * Item 4 * Item 4 |
michael@0 | 119 | // * Item 5 * Item 5 |
michael@0 | 120 | sel.removeAllRanges(); |
michael@0 | 121 | sel.selectAllChildren(editor.getElementsByTagName("li")[2]); |
michael@0 | 122 | document.execCommand("indent", false, null); |
michael@0 | 123 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", |
michael@0 | 124 | "html output doesn't match expected value in test 7"); |
michael@0 | 125 | |
michael@0 | 126 | // That covers the basics of merging lists on indent and outdent. |
michael@0 | 127 | // We also want to check that ul / ol lists won't be merged together, |
michael@0 | 128 | // since they're different types of lists. |
michael@0 | 129 | // *** test 8 *** |
michael@0 | 130 | // 1. Item 1 1. Item 1 |
michael@0 | 131 | // 1. Item 2 1. Item 2 |
michael@0 | 132 | // 2. Item 3 2. Item 3 |
michael@0 | 133 | // * {\t}Item 4 * Item 4 |
michael@0 | 134 | // * Item 5 * Item 5 |
michael@0 | 135 | sel.removeAllRanges(); |
michael@0 | 136 | sel.selectAllChildren(editor.getElementsByTagName("li")[3]); |
michael@0 | 137 | document.execCommand("indent", false, null); |
michael@0 | 138 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><ul><li>Item 4</li></ul><li>Item 5</li></ul>", |
michael@0 | 139 | "html output doesn't match expected value in test 8"); |
michael@0 | 140 | |
michael@0 | 141 | // Better test merging with <ul> rather than <ol> too. |
michael@0 | 142 | // *** test 9 *** |
michael@0 | 143 | // 1. Item 1 1. Item 1 |
michael@0 | 144 | // 1. Item 2 1. Item 2 |
michael@0 | 145 | // 2. Item 3 2. Item 3 |
michael@0 | 146 | // * Item 4 * Item 4 |
michael@0 | 147 | // * {\t}Item 5 * Item 5 |
michael@0 | 148 | sel.removeAllRanges(); |
michael@0 | 149 | sel.selectAllChildren(editor.getElementsByTagName("li")[4]); |
michael@0 | 150 | document.execCommand("indent", false, null); |
michael@0 | 151 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><ul><li>Item 4</li><li>Item 5</li></ul></ul>", |
michael@0 | 152 | "html output doesn't match expected value in test 9"); |
michael@0 | 153 | |
michael@0 | 154 | // Same test as test 8, but with outdent rather than indent. |
michael@0 | 155 | // *** test 10 *** |
michael@0 | 156 | // 1. Item 1 1. Item 1 |
michael@0 | 157 | // 1. Item 2 1. Item 2 |
michael@0 | 158 | // 2. Item 3 2. Item 3 |
michael@0 | 159 | // * {\st}Item 4 * Item 4 |
michael@0 | 160 | // * Item 5 * Item 5 |
michael@0 | 161 | sel.removeAllRanges(); |
michael@0 | 162 | sel.selectAllChildren(editor.getElementsByTagName("li")[3]); |
michael@0 | 163 | document.execCommand("outdent", false, null); |
michael@0 | 164 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><ul><li>Item 5</li></ul></ul>", |
michael@0 | 165 | "html output doesn't match expected value in test 10"); |
michael@0 | 166 | |
michael@0 | 167 | // Test indenting multiple items at once. Hold down "shift" and select |
michael@0 | 168 | // upwards to get all the <ol> items and the first <ul> item. |
michael@0 | 169 | // *** test 11 *** |
michael@0 | 170 | // 1. Item 1 1. Item 1 |
michael@0 | 171 | // 1. {\t}Item 2 1. Item 2 |
michael@0 | 172 | // 2. {\t}Item 3 2. Item 3 |
michael@0 | 173 | // * {\t}Item 4 * Item 4 |
michael@0 | 174 | // * Item 5 * Item 5 |
michael@0 | 175 | sel.removeAllRanges(); |
michael@0 | 176 | var range = document.createRange(); |
michael@0 | 177 | range.setStart(editor.getElementsByTagName("li")[1], 0); |
michael@0 | 178 | range.setEnd(editor.getElementsByTagName("li")[3], editor.getElementsByTagName("li")[3].childNodes.length); |
michael@0 | 179 | sel.addRange(range); |
michael@0 | 180 | document.execCommand("indent", false, null); |
michael@0 | 181 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><ol><li>Item 2</li><li>Item 3</li></ol></ol></ol><ul><ul><li>Item 4</li><li>Item 5</li></ul></ul>", |
michael@0 | 182 | "html output doesn't match expected value in test 11"); |
michael@0 | 183 | |
michael@0 | 184 | // Test outdenting multiple items at once. Selection is already ready... |
michael@0 | 185 | // *** test 12 *** |
michael@0 | 186 | // 1. Item 1 1. Item 1 |
michael@0 | 187 | // 1. {\st}Item 2 1. Item 2 |
michael@0 | 188 | // 2. {\st}Item 3 2. Item 3 |
michael@0 | 189 | // * {\st}Item 4 * Item 4 |
michael@0 | 190 | // * Item 5 * Item 5 |
michael@0 | 191 | document.execCommand("outdent", false, null); |
michael@0 | 192 | ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><ul><li>Item 5</li></ul></ul>", |
michael@0 | 193 | "html output doesn't match expected value in test 12"); |
michael@0 | 194 | |
michael@0 | 195 | SimpleTest.finish(); |
michael@0 | 196 | }); |
michael@0 | 197 | |
michael@0 | 198 | |
michael@0 | 199 | |
michael@0 | 200 | </script> |
michael@0 | 201 | </pre> |
michael@0 | 202 | </body> |
michael@0 | 203 | </html> |
michael@0 | 204 |