Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js |
— | — | @@ -222,3 +222,54 @@ |
223 | 223 | }, |
224 | 224 | replace: ulist |
225 | 225 | }); |
| 226 | + |
| 227 | + |
| 228 | +var caretTest = function(options) { |
| 229 | + test(options.description, function() { |
| 230 | + expect(2); |
| 231 | + |
| 232 | + var $fixture = $( '<div id="qunit-fixture"></div>' ); |
| 233 | + var $textarea = $( '<textarea>' ).text(options.text); |
| 234 | + |
| 235 | + $fixture.append($textarea); |
| 236 | + $( 'body' ).append($fixture); |
| 237 | + |
| 238 | + if (options.mode == 'set') { |
| 239 | + $textarea.textSelection('setSelection', { |
| 240 | + start: options.start, |
| 241 | + end: options.end |
| 242 | + }); |
| 243 | + } |
| 244 | + |
| 245 | + var pos = $textarea.textSelection('getCaretPosition', {startAndEnd: true}); |
| 246 | + equal(pos[0], options.start, 'Caret start should be where we set it.'); |
| 247 | + equal(pos[1], options.end, 'Caret end should be where we set it.'); |
| 248 | + }); |
| 249 | +} |
| 250 | + |
| 251 | +var caretSample = "Some big text that we like to work with. Nothing fancy... you know what I mean?"; |
| 252 | + |
| 253 | +caretTest({ |
| 254 | + description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8', |
| 255 | + text: caretSample, |
| 256 | + start: 0, |
| 257 | + end: 0, |
| 258 | + mode: 'get' |
| 259 | +}); |
| 260 | + |
| 261 | +caretTest({ |
| 262 | + description: 'set/getCaretPosition with forced empty selection', |
| 263 | + text: caretSample, |
| 264 | + start: 7, |
| 265 | + end: 7, |
| 266 | + mode: 'set' |
| 267 | +}); |
| 268 | + |
| 269 | +caretTest({ |
| 270 | + description: 'set/getCaretPosition with small selection', |
| 271 | + text: caretSample, |
| 272 | + start: 6, |
| 273 | + end: 11, |
| 274 | + mode: 'set' |
| 275 | +}); |
| 276 | + |