From 6ee65920e8fdd0d4c49bb2ebbb4acea50392fc29 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 24 Oct 2011 22:28:09 +0000 Subject: [PATCH] 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. :) --- .../jquery/jquery.textSelection.test.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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' }); -- 2.20.1