Changeset 260756 in webkit
- Timestamp:
- Apr 27, 2020 8:44:26 AM (4 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r260752 r260756 1 2020-04-27 Daniel Bates <dabates@apple.com> 2 3 Text interaction tests should ensure view is not scroll instead of looking for a zoom change 4 https://bugs.webkit.org/show_bug.cgi?id=211056 5 6 Reviewed by Dean Jackson. 7 8 For the text interaction sub-tests, override the scroll view's delegate so as to track 9 whether a scroll occurred or not instead of looking at the zoom scale. As the tests are 10 written looking at the zoom scale is racy. It is simpler and deterministic to detect 11 whether the scroll view scrolled. 12 13 The purpose of the text interaction sub-tests are to ensure that zooming to reveal 14 the focused element is suppressed until the interaction completes with a call to 15 -_didFinishTextInteractionInTextInputContext. I added some more assertions to ensure this. 16 17 * TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm: 18 (-[TextInteractionScrollDelegate scrollViewDidScroll:]): 19 (TestWebKitAPI::TEST): 20 1 21 2020-04-27 Carlos Garcia Campos <cgarcia@igalia.com> 2 22 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm
r260541 r260756 64 64 } // namespace TestWebKitAPI 65 65 66 static bool didScroll; 67 68 @interface TextInteractionScrollDelegate : NSObject <UIScrollViewDelegate> 69 @end 70 71 // Ideally this would ensure that the focused element is actually in view. 72 // For the purposes of the tests in this file it is enough to know whether 73 // a scroll occurred. 74 @implementation TextInteractionScrollDelegate 75 76 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 77 { 78 didScroll = true; 79 } 80 81 @end 82 66 83 @implementation TestWKWebView (SynchronousTextInputContext) 67 84 … … 552 569 } 553 570 554 TEST(RequestTextInputContext, TextInteraction_FocusingReadOnlyElement ChangesZoomScale)571 TEST(RequestTextInputContext, TextInteraction_FocusingReadOnlyElementShouldScrollToReveal) 555 572 { 556 573 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 566 583 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 567 584 [webView stringByEvaluatingJavaScript:@"input.readOnly = true"]; 568 [webView scrollView].zoomScale = 2; 569 570 // Focus the field using -focusTextInputContext; zoom scale of scroll view should change to reveal the focused element. 585 586 didScroll = false; 587 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 588 [webView scrollView].delegate = scrollDelegate.get(); 589 590 // Focus the field using -focusTextInputContext; scroll view should scroll to reveal the focused element. 571 591 { 572 592 TextInteractionForScope scope { webView, inputElement }; 573 593 EXPECT_NULL([webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 574 } 575 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 576 EXPECT_LT([webView scrollView].zoomScale, 2); 594 EXPECT_FALSE(didScroll); 595 } 596 597 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 598 EXPECT_TRUE(didScroll); 577 599 } 578 600 … … 591 613 592 614 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.querySelector('iframe').contentDocument.activeElement.tagName"]); 593 [webView scrollView].zoomScale = 2; 615 616 didScroll = false; 617 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 618 [webView scrollView].delegate = scrollDelegate.get(); 594 619 595 620 // Save a reference to the framed document (to prevent its destruction when its frame is removed) … … 600 625 EXPECT_NULL([webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 601 626 } 627 602 628 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"g_framedDocument.activeElement.tagName"]); 603 EXPECT_ EQ(2, [webView scrollView].zoomScale);604 } 605 606 TEST(RequestTextInputContext, TextInteraction_FocusingElement ChangesZoomScale)629 EXPECT_FALSE(didScroll); 630 } 631 632 TEST(RequestTextInputContext, TextInteraction_FocusingElementShouldScrollToReveal) 607 633 { 608 634 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 617 643 618 644 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 619 [webView scrollView].zoomScale = 2; 620 621 // Zoom scale of scroll view should change to reveal the focused element. 645 646 didScroll = false; 647 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 648 [webView scrollView].delegate = scrollDelegate.get(); 649 650 // Scroll view should scroll to reveal the focused element. 622 651 { 623 652 TextInteractionForScope scope { webView, inputElement }; 624 653 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 625 } 626 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 627 EXPECT_LT([webView scrollView].zoomScale, 2); 628 } 629 630 TEST(RequestTextInputContext, TextInteraction_FocusingElementMultipleTimesChangesZoomScale) 654 EXPECT_FALSE(didScroll); 655 } 656 657 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 658 EXPECT_TRUE(didScroll); 659 } 660 661 TEST(RequestTextInputContext, TextInteraction_FocusingElementMultipleTimesShouldScrollToReveal) 631 662 { 632 663 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 641 672 642 673 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 643 [webView scrollView].zoomScale = 2; 644 645 // Zoom scale of scroll view should change to reveal the focused element. 674 675 didScroll = false; 676 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 677 [webView scrollView].delegate = scrollDelegate.get(); 678 679 // Scroll view should scroll to reveal the focused element. 646 680 { 647 681 TextInteractionForScope scope { webView, inputElement }; … … 649 683 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 650 684 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 651 } 652 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 653 EXPECT_LT([webView scrollView].zoomScale, 2); 654 } 655 656 TEST(RequestTextInputContext, TextInteraction_FocusDefocusDisableFocusAgainShouldNotChangeZoomScale) 685 EXPECT_FALSE(didScroll); 686 } 687 688 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 689 EXPECT_TRUE(didScroll); 690 } 691 692 TEST(RequestTextInputContext, TextInteraction_FocusDefocusDisableFocusAgainShouldNotScrollToReveal) 657 693 { 658 694 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 667 703 668 704 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 669 [webView scrollView].zoomScale = 2; 705 706 didScroll = false; 707 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 708 [webView scrollView].delegate = scrollDelegate.get(); 670 709 671 710 { … … 682 721 [webView stringByEvaluatingJavaScript:@"input.disabled = true"]; 683 722 684 // 4. Focus again; focused element and zoom scale of scroll view should be unchanged.723 // 4. Focus again; focused element should be unchanged and scroll view should not scroll. 685 724 EXPECT_NULL([webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 686 725 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 687 726 } 688 EXPECT_EQ(2, [webView scrollView].zoomScale); 689 } 690 691 TEST(RequestTextInputContext, TextInteraction_FocusDefocusFocusAgainShouldChangeZoomScale) 727 728 EXPECT_FALSE(didScroll); 729 } 730 731 TEST(RequestTextInputContext, TextInteraction_FocusDefocusFocusAgainShouldScrollToReveal) 692 732 { 693 733 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 702 742 703 743 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 704 [webView scrollView].zoomScale = 2; 744 745 didScroll = false; 746 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 747 [webView scrollView].delegate = scrollDelegate.get(); 705 748 706 749 { … … 714 757 EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 715 758 716 // 3. Focus again; focused element and zoom scale of scroll view should change.759 // 3. Focus again; focused element should change and scroll view should scroll to reveal focused element. 717 760 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 718 761 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 719 } 720 EXPECT_LT([webView scrollView].zoomScale, 2); 721 } 722 723 TEST(RequestTextInputContext, TextInteraction_FocusingAssistedElementShouldNotChangeZoomScale) 762 EXPECT_FALSE(didScroll); 763 } 764 765 EXPECT_TRUE(didScroll); 766 } 767 768 TEST(RequestTextInputContext, TextInteraction_FocusingAssistedElementShouldNotScrollToReveal) 724 769 { 725 770 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 738 783 [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"input.focus()"]; 739 784 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 740 [webView scrollView].zoomScale = 2; 741 742 // Focus the field using -focusTextInputContext; zoom scale of scroll view should be unchanged. 785 786 didScroll = false; 787 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 788 [webView scrollView].delegate = scrollDelegate.get(); 789 790 // Focus the field using -focusTextInputContext; scroll view should not scroll to reveal focused element. 743 791 { 744 792 TextInteractionForScope scope { webView, inputElement }; 745 793 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 746 794 } 747 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 748 EXPECT_EQ(2, [webView scrollView].zoomScale); 749 } 750 751 TEST(RequestTextInputContext, TextInteraction_FocusingNonAssistedFocusedElementChangesZoomScale) 795 796 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 797 EXPECT_FALSE(didScroll); 798 } 799 800 TEST(RequestTextInputContext, TextInteraction_FocusingNonAssistedFocusedElementScrollsToReveal) 752 801 { 753 802 IPhoneUserInterfaceSwizzler userInterfaceSwizzler; … … 766 815 [webView stringByEvaluatingJavaScript:@"input.focus()"]; // Will not start input assistance 767 816 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 768 [webView scrollView].zoomScale = 2; 769 770 // Focus the field using -focusTextInputContext; zoom scale of scroll view should change to reveal the focused element. 817 818 didScroll = false; 819 auto scrollDelegate = adoptNS([[TextInteractionScrollDelegate alloc] init]); 820 [webView scrollView].delegate = scrollDelegate.get(); 821 822 // Focus the field using -focusTextInputContext; scroll view should scroll to reveal the focused element. 771 823 [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }]; 772 824 { … … 774 826 // Will start input assistance 775 827 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]); 776 } 777 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 778 EXPECT_LT([webView scrollView].zoomScale, 2); 828 EXPECT_FALSE(didScroll); 829 } 830 831 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 832 EXPECT_TRUE(didScroll); 779 833 } 780 834
Note: See TracChangeset
for help on using the changeset viewer.