|
759 | 759 |
|
760 | 760 | test.remove();
|
761 | 761 | }, 'Testing UseCounter for textformatupdate event.');
|
| 762 | + |
| 763 | +test(function(){ |
| 764 | + const kEditContextUpdateTextRangePrecedesOrOverlapsSelection = 5582; |
| 765 | + const kEditContextUpdateTextRangePrecedesCompositionRange = 5583; |
| 766 | + const kEditContextUpdateTextRangeOverlapsCompositionRange = 5584; |
| 767 | + internals.clearUseCounter(document, kEditContextUpdateTextRangePrecedesOrOverlapsSelection); |
| 768 | + internals.clearUseCounter(document, kEditContextUpdateTextRangePrecedesCompositionRange); |
| 769 | + internals.clearUseCounter(document, kEditContextUpdateTextRangeOverlapsCompositionRange); |
| 770 | + |
| 771 | + const text = "ABCD"; |
| 772 | + const editContext = new EditContext({text: text, selectionStart: 1, selectionEnd: 1}); |
| 773 | + const test = document.createElement("div"); |
| 774 | + test.textContent = text; |
| 775 | + document.body.appendChild(test); |
| 776 | + test.editContext = editContext; |
| 777 | + test.focus(); |
| 778 | + |
| 779 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesOrOverlapsSelection)); |
| 780 | + |
| 781 | + // UpdateText range is outside the selection range. |
| 782 | + editContext.updateText(4, 4, "1"); |
| 783 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesOrOverlapsSelection)); |
| 784 | + |
| 785 | + // UpdateText range is less than selection range. |
| 786 | + editContext.updateText(0, 0, "2"); |
| 787 | + assert_true(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesOrOverlapsSelection)); |
| 788 | + |
| 789 | + editContext.updateSelection(1, 1); |
| 790 | + textInputController.setComposition("foo"); |
| 791 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesCompositionRange)); |
| 792 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangeOverlapsCompositionRange)); |
| 793 | + |
| 794 | + // UpdeText range is outside the composition range. |
| 795 | + editContext.updateText(5, 5, "3"); |
| 796 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesCompositionRange)); |
| 797 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangeOverlapsCompositionRange)); |
| 798 | + |
| 799 | + // UpdateText range is less than composition range but does not overlap. |
| 800 | + editContext.updateText(0, 0, "4"); |
| 801 | + assert_true(internals.isUseCounted(document, kEditContextUpdateTextRangePrecedesCompositionRange)); |
| 802 | + assert_false(internals.isUseCounted(document, kEditContextUpdateTextRangeOverlapsCompositionRange)); |
| 803 | + |
| 804 | + // UpdateText range overlaps with composition range. |
| 805 | + editContext.updateText(0, 3, "5"); |
| 806 | + assert_true(internals.isUseCounted(document, kEditContextUpdateTextRangeOverlapsCompositionRange)); |
| 807 | + |
| 808 | + test.remove(); |
| 809 | +}, 'Testing UseCounter for updateText based on update range and selection/composition range.'); |
| 810 | + |
| 811 | +test(function(){ |
| 812 | + const kEditContextUpdateSelectionDuringActiveComposition = 5585; |
| 813 | + internals.clearUseCounter(document, kEditContextUpdateSelectionDuringActiveComposition); |
| 814 | + |
| 815 | + const text = "ABCD"; |
| 816 | + const editContext = new EditContext({text: text, selectionStart: 0, selectionEnd: 0}); |
| 817 | + const test = document.createElement("div"); |
| 818 | + test.textContent = text; |
| 819 | + document.body.appendChild(test); |
| 820 | + test.editContext = editContext; |
| 821 | + test.focus(); |
| 822 | + |
| 823 | + // Tracks when selection is updated to new value while a composition is active. |
| 824 | + assert_false(internals.isUseCounted(document, kEditContextUpdateSelectionDuringActiveComposition)); |
| 825 | + editContext.updateSelection(1, 1); |
| 826 | + assert_false(internals.isUseCounted(document, kEditContextUpdateSelectionDuringActiveComposition)); |
| 827 | + |
| 828 | + textInputController.setComposition("foo"); |
| 829 | + assert_equals(editContext.selectionStart, 4); |
| 830 | + assert_equals(editContext.selectionEnd, 4); |
| 831 | + editContext.updateSelection(4, 4); |
| 832 | + assert_false(internals.isUseCounted(document, kEditContextUpdateSelectionDuringActiveComposition)); |
| 833 | + |
| 834 | + editContext.updateSelection(2, 2); |
| 835 | + assert_true(internals.isUseCounted(document, kEditContextUpdateSelectionDuringActiveComposition)); |
| 836 | + |
| 837 | + test.remove(); |
| 838 | +}, 'Testing UseCounter for updateSelection during an active composition.'); |
762 | 839 | </script>
|
763 | 840 | </body>
|
764 | 841 | </html>
|
0 commit comments