From: Brion Vibber Date: Mon, 24 Oct 2011 22:28:09 +0000 (+0000) Subject: Followup r100391: fix caret position test case on Opera, Firefox 3.5/3.6/4.0/5.0 X-Git-Tag: 1.31.0-rc.0~26922 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=6ee65920e8fdd0d4c49bb2ebbb4acea50392fc29;p=lhc%2Fweb%2Fwiklou.git Followup r100391: fix caret position test case on Opera, Firefox 3.5/3.6/4.0/5.0 Opera (through 11.52 at least) & Firefox prior to 6.0 set the caret initially to the end of the textarea, which gave a mismatch. All we really need is to know we got a sane value, so checking for both (start == 0; end == text.length) gets the job done. Under ideal circumstances, we'd check after a user clicks in the textarea on the first line, but no good way to trigger that. :) --- diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index 5cd49de076..a493bbeed6 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -241,9 +241,17 @@ var caretTest = function(options) { }); } + var among = function(actual, expected, message) { + if ($.isArray(expected)) { + ok($.inArray(actual, expected) !== -1 , message + ' (got ' + actual + '; expected one of ' + expected.join(', ') + ')'); + } else { + equal(actual, expected, message); + } + }; + var pos = $textarea.textSelection('getCaretPosition', {startAndEnd: true}); - equal(pos[0], options.start, 'Caret start should be where we set it.'); - equal(pos[1], options.end, 'Caret end should be where we set it.'); + among(pos[0], options.start, 'Caret start should be where we set it.'); + among(pos[1], options.end, 'Caret end should be where we set it.'); }); } @@ -252,8 +260,8 @@ var caretSample = "Some big text that we like to work with. Nothing fancy... you caretTest({ description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8', text: caretSample, - start: 0, - end: 0, + start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length) + end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both. mode: 'get' });