Changeset 260756 in webkit


Ignore:
Timestamp:
Apr 27, 2020 8:44:26 AM (4 years ago)
Author:
dbates@webkit.org
Message:

Text interaction tests should ensure view is not scroll instead of looking for a zoom change
https://bugs.webkit.org/show_bug.cgi?id=211056

Reviewed by Dean Jackson.

For the text interaction sub-tests, override the scroll view's delegate so as to track
whether a scroll occurred or not instead of looking at the zoom scale. As the tests are
written looking at the zoom scale is racy. It is simpler and deterministic to detect
whether the scroll view scrolled.

The purpose of the text interaction sub-tests are to ensure that zooming to reveal
the focused element is suppressed until the interaction completes with a call to
-_didFinishTextInteractionInTextInputContext. I added some more assertions to ensure this.

  • TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm:

(-[TextInteractionScrollDelegate scrollViewDidScroll:]):
(TestWebKitAPI::TEST):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r260752 r260756  
     12020-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
    1212020-04-27  Carlos Garcia Campos  <cgarcia@igalia.com>
    222
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm

    r260541 r260756  
    6464} // namespace TestWebKitAPI
    6565
     66static 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
    6683@implementation TestWKWebView (SynchronousTextInputContext)
    6784
     
    552569}
    553570
    554 TEST(RequestTextInputContext, TextInteraction_FocusingReadOnlyElementChangesZoomScale)
     571TEST(RequestTextInputContext, TextInteraction_FocusingReadOnlyElementShouldScrollToReveal)
    555572{
    556573    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    566583    EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
    567584    [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.
    571591    {
    572592        TextInteractionForScope scope { webView, inputElement };
    573593        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);
    577599}
    578600
     
    591613
    592614    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();
    594619
    595620    // Save a reference to the framed document (to prevent its destruction when its frame is removed)
     
    600625        EXPECT_NULL([webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]);
    601626    }
     627
    602628    EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"g_framedDocument.activeElement.tagName"]);
    603     EXPECT_EQ(2, [webView scrollView].zoomScale);
    604 }
    605 
    606 TEST(RequestTextInputContext, TextInteraction_FocusingElementChangesZoomScale)
     629    EXPECT_FALSE(didScroll);
     630}
     631
     632TEST(RequestTextInputContext, TextInteraction_FocusingElementShouldScrollToReveal)
    607633{
    608634    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    617643
    618644    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.
    622651    {
    623652        TextInteractionForScope scope { webView, inputElement };
    624653        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
     661TEST(RequestTextInputContext, TextInteraction_FocusingElementMultipleTimesShouldScrollToReveal)
    631662{
    632663    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    641672
    642673    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.
    646680    {
    647681        TextInteractionForScope scope { webView, inputElement };
     
    649683        EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
    650684        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
     692TEST(RequestTextInputContext, TextInteraction_FocusDefocusDisableFocusAgainShouldNotScrollToReveal)
    657693{
    658694    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    667703
    668704    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();
    670709
    671710    {
     
    682721        [webView stringByEvaluatingJavaScript:@"input.disabled = true"];
    683722
    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.
    685724        EXPECT_NULL([webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]);
    686725        EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
    687726    }
    688     EXPECT_EQ(2, [webView scrollView].zoomScale);
    689 }
    690 
    691 TEST(RequestTextInputContext, TextInteraction_FocusDefocusFocusAgainShouldChangeZoomScale)
     727
     728    EXPECT_FALSE(didScroll);
     729}
     730
     731TEST(RequestTextInputContext, TextInteraction_FocusDefocusFocusAgainShouldScrollToReveal)
    692732{
    693733    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    702742
    703743    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();
    705748
    706749    {
     
    714757        EXPECT_WK_STREQ("BODY", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
    715758
    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.
    717760        EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]);
    718761        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
     768TEST(RequestTextInputContext, TextInteraction_FocusingAssistedElementShouldNotScrollToReveal)
    724769{
    725770    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    738783    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"input.focus()"];
    739784    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.
    743791    {
    744792        TextInteractionForScope scope { webView, inputElement };
    745793        EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:[inputElement boundingRect].origin]);
    746794    }
    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
     800TEST(RequestTextInputContext, TextInteraction_FocusingNonAssistedFocusedElementScrollsToReveal)
    752801{
    753802    IPhoneUserInterfaceSwizzler userInterfaceSwizzler;
     
    766815    [webView stringByEvaluatingJavaScript:@"input.focus()"]; // Will not start input assistance
    767816    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.
    771823    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
    772824    {
     
    774826        // Will start input assistance
    775827        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);
    779833}
    780834
Note: See TracChangeset for help on using the changeset viewer.