http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100656

Revision: 100656
Author:   brion
Date:     2011-10-24 22:28:09 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
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. :)

Modified Paths:
--------------
    
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js

Modified: 
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
===================================================================
--- 
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js   
    2011-10-24 22:27:38 UTC (rev 100655)
+++ 
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js   
    2011-10-24 22:28:09 UTC (rev 100656)
@@ -241,9 +241,17 @@
                        });
                }
 
+               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 @@
 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'
 });
 


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to