Changeset 238512 in webkit


Ignore:
Timestamp:
Nov 26, 2018 12:41:19 PM (5 years ago)
Author:
dbates@webkit.org
Message:

Move testRunner.toggleCapsLock() to uiController
https://bugs.webkit.org/show_bug.cgi?id=191972

Reviewed by Tim Horton.

Tools:

Move testRunner.toggleCapsLock() to uiController as uiController is the preferred JavaScript
object for UI test functions. Having this functionality be on uiController makes it an
asynchronous function naturally and complements use of onkeydown, onkeyup listeners to know
when the Caps Lock key event is dispatched. It also facilitates its use directly as part of
scripts with other uiController functions invocations that are passed in a single invocation
of testRunner.runUIScript().

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::toggleCapsLock):

  • DumpRenderTree/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::toggleCapsLock):
Added stub functions that invoke the callback. We do not support toggling caps lock in Legacy
WebKit at the moment. Legacy WebKit reads the caps lock key state directly from the OS. Modern
WebKit caches the caps lock state in the WebProcess as a natural side effect of the fact that
the UIProcess is the only process capable of querying the caps lock key state from the OS and
hence the UIProcess must send over this state to the WebProcess.

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: Add IDL for new function.
  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:

(WTR::UIScriptController::toggleCapsLock): Added empty implementation for ports non-Cocoa ports.

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::toggleCapsLock): Deleted.

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::TestController::toggleCapsLock): Deleted; moved to UIScriptController::toggleCapsLock().
Removed logic to handle testRunner.toggleCapsLock().

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::toggleCapsLock): Add stub function that invokes the callback
and a FIXME comment that explains that we will implement this function in <https://bugs.webkit.org/show_bug.cgi?id=191815>.

  • WebKitTestRunner/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::toggleCapsLock): Moved the implementation from TestController::toggleCapsLock().

LayoutTests:

Updated existing test to use UIHelper.toggleCapsLock(), which calls uiController.toggleCapsLock(),
now that testRunner.toggleCapsLock() was removed.

  • fast/events/detect-caps-lock.html:
  • resources/ui-helper.js:

(window.UIHelper.toggleCapsLock): Added. Convenience function to call uiController.toggleCapsLock()
and return a Promise that is resolved once the UIProcess has dispatched the NSEvent to simulate
pressing the caps lock key.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238496 r238512  
     12018-11-26  Daniel Bates  <dabates@apple.com>
     2
     3        Move testRunner.toggleCapsLock() to uiController
     4        https://bugs.webkit.org/show_bug.cgi?id=191972
     5
     6        Reviewed by Tim Horton.
     7
     8        Updated existing test to use UIHelper.toggleCapsLock(), which calls uiController.toggleCapsLock(),
     9        now that testRunner.toggleCapsLock() was removed.
     10
     11        * fast/events/detect-caps-lock.html:
     12        * resources/ui-helper.js:
     13        (window.UIHelper.toggleCapsLock): Added. Convenience function to call uiController.toggleCapsLock()
     14        and return a Promise that is resolved once the UIProcess has dispatched the NSEvent to simulate
     15        pressing the caps lock key.
     16
    1172018-11-26  Zalan Bujtas  <zalan@apple.com>
    218
  • trunk/LayoutTests/fast/events/detect-caps-lock.html

    r237886 r238512  
    11<!DOCTYPE html>
    2 <html><head></head>
     2<html>
     3<head>
     4<script src="../../resources/ui-helper.js"></script>
     5</head>
    36    <body>
    47        <p>This test verifies that the function WebCore::currentCapsLockState() returns true when Caps Lock is on.</p>
     
    4447            input.addEventListener('keyup', keyUp, false);
    4548            input.focus();
    46            
     49
     50            async function runTest()
     51            {
     52                await UIHelper.toggleCapsLock();
     53                testRunner.setWindowIsKey(false);
     54                testRunner.setWindowIsKey(true);
     55                await UIHelper.toggleCapsLock();
     56               
     57                testRunner.setWindowIsKey(false);
     58                await UIHelper.toggleCapsLock();
     59                testRunner.setWindowIsKey(true);
     60                await UIHelper.toggleCapsLock();
     61
     62                testRunner.setWindowIsKey(true);
     63                await UIHelper.toggleCapsLock();
     64                await UIHelper.toggleCapsLock();
     65
     66                testRunner.setWindowIsKey(false);
     67                await UIHelper.toggleCapsLock();
     68                await UIHelper.toggleCapsLock();
     69
     70                eventSender.keyDown("q", []);
     71            }
     72
    4773            if (window.testRunner) {
    4874                testRunner.dumpAsText();
    4975                testRunner.waitUntilDone();
    50                
    51                 testRunner.toggleCapsLock();
    52                 testRunner.setWindowIsKey(false);
    53                 testRunner.setWindowIsKey(true);
    54                 testRunner.toggleCapsLock();
    55                
    56                 testRunner.setWindowIsKey(false);
    57                 testRunner.toggleCapsLock();
    58                 testRunner.setWindowIsKey(true);
    59                 testRunner.toggleCapsLock();
    6076
    61                 testRunner.setWindowIsKey(true);
    62                 testRunner.toggleCapsLock();
    63                 testRunner.toggleCapsLock();
    64 
    65                 testRunner.setWindowIsKey(false);
    66                 testRunner.toggleCapsLock();
    67                 testRunner.toggleCapsLock();
    68 
    69                 eventSender.keyDown("q", []);
     77                runTest();
    7078            }
    7179        </script>
  • trunk/LayoutTests/resources/ui-helper.js

    r238235 r238512  
    6464        return new Promise((resolve) => {
    6565            testRunner.runUIScript(`uiController.keyDown("${key}", ${JSON.stringify(modifiers)});`, resolve);
     66        });
     67    }
     68
     69    static toggleCapsLock()
     70    {
     71        return new Promise((resolve) => {
     72            testRunner.runUIScript(`uiController.toggleCapsLock(() => uiController.uiScriptComplete('Done'));`, resolve);
    6673        });
    6774    }
  • trunk/Tools/ChangeLog

    r238501 r238512  
     12018-11-26  Daniel Bates  <dabates@apple.com>
     2
     3        Move testRunner.toggleCapsLock() to uiController
     4        https://bugs.webkit.org/show_bug.cgi?id=191972
     5
     6        Reviewed by Tim Horton.
     7
     8        Move testRunner.toggleCapsLock() to uiController as uiController is the preferred JavaScript
     9        object for UI test functions. Having this functionality be on uiController makes it an
     10        asynchronous function naturally and complements use of onkeydown, onkeyup listeners to know
     11        when the Caps Lock key event is dispatched. It also facilitates its use directly as part of
     12        scripts with other uiController functions invocations that are passed in a single invocation
     13        of testRunner.runUIScript().
     14
     15        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     16        (WTR::UIScriptController::toggleCapsLock):
     17        * DumpRenderTree/mac/UIScriptControllerMac.mm:
     18        (WTR::UIScriptController::toggleCapsLock):
     19        Added stub functions that invoke the callback. We do not support toggling caps lock in Legacy
     20        WebKit at the moment. Legacy WebKit reads the caps lock key state directly from the OS. Modern
     21        WebKit caches the caps lock state in the WebProcess as a natural side effect of the fact that
     22        the UIProcess is the only process capable of querying the caps lock key state from the OS and
     23        hence the UIProcess must send over this state to the WebProcess.
     24
     25        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: Add IDL for new function.
     26        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     27        (WTR::UIScriptController::toggleCapsLock): Added empty implementation for ports non-Cocoa ports.
     28        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     29
     30        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     31        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     32        (WTR::TestRunner::toggleCapsLock): Deleted.
     33        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     34        * WebKitTestRunner/TestController.h:
     35        * WebKitTestRunner/TestInvocation.cpp:
     36        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     37        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     38        (WTR::TestController::toggleCapsLock): Deleted; moved to UIScriptController::toggleCapsLock().
     39        Removed logic to handle testRunner.toggleCapsLock().
     40
     41        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     42        (WTR::UIScriptController::toggleCapsLock): Add stub function that invokes the callback
     43        and a FIXME comment that explains that we will implement this function in <https://bugs.webkit.org/show_bug.cgi?id=191815>.
     44        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
     45        (WTR::UIScriptController::toggleCapsLock): Moved the implementation from TestController::toggleCapsLock().
     46
    1472018-11-26  Brent Fulgham  <bfulgham@apple.com>
    248
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r238235 r238512  
    423423}
    424424
     425void UIScriptController::toggleCapsLock(JSValueRef callback)
     426{
     427    doAsyncTask(callback);
     428}
     429
    425430}
    426431
  • trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

    r237924 r238512  
    206206{
    207207}
    208    
     208
     209void UIScriptController::toggleCapsLock(JSValueRef callback)
     210{
     211    doAsyncTask(callback);
     212}
     213
    209214}
    210215
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r238235 r238512  
    7171
    7272    void keyDown(DOMString character, object modifierArray);
     73    void toggleCapsLock(object callback);
    7374
    7475    // eventsJSON describes a series of user events in JSON form. For the keys, see HIDEventGenerator.mm.
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r238235 r238512  
    207207
    208208#if !PLATFORM(COCOA)
     209
    209210void UIScriptController::zoomToScale(double, JSValueRef)
    210211{
     
    236237    return nullptr;
    237238}
    238    
    239 #endif
     239
     240void UIScriptController::toggleCapsLock(JSValueRef)
     241{
     242}
     243
     244#endif // !PLATFORM(COCOA)
    240245
    241246void UIScriptController::playBackEventStream(JSStringRef stream, JSValueRef callback)
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r238235 r238512  
    9292
    9393    void keyDown(JSStringRef character, JSValueRef modifierArray);
     94    void toggleCapsLock(JSValueRef callback);
    9495
    9596    void keyboardAccessoryBarNext();
     
    222223
    223224    UIScriptContext* m_context;
     225
     226#if PLATFORM(MAC)
     227    bool m_capsLockOn { false };
     228#endif
    224229};
    225230
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r238438 r238512  
    362362    void cleanUpKeychain(DOMString attrLabel);
    363363    boolean keyExistsInKeychain(DOMString attrLabel, DOMString applicationTagBase64);
    364 
    365     void toggleCapsLock();
    366364};
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r238438 r238512  
    26352635}
    26362636
    2637 void TestRunner::toggleCapsLock()
    2638 {
    2639     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("ToggleCapsLock"));
    2640     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
    2641 }
    2642 
    26432637} // namespace WTR
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r238438 r238512  
    480480    bool keyExistsInKeychain(JSStringRef attrLabel, JSStringRef applicationTagBase64);
    481481
    482     void toggleCapsLock();
    483 
    484482private:
    485483    TestRunner();
  • trunk/Tools/WebKitTestRunner/TestController.h

    r237924 r238512  
    282282    bool keyExistsInKeychain(const String& attrLabel, const String& applicationTagBase64);
    283283
    284     void toggleCapsLock();
    285 
    286284#if PLATFORM(COCOA)
    287285    RetainPtr<NSString> getOverriddenCalendarIdentifier() const;
     
    519517    bool m_didReceiveServerRedirectForProvisionalNavigation { false };
    520518
    521     bool m_capsLockOn { false };
    522 
    523519    WKRetainPtr<WKArrayRef> m_openPanelFileURLs;
    524520
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r238098 r238512  
    15101510    }
    15111511
    1512 #if PLATFORM(MAC)
    1513     if (WKStringIsEqualToUTF8CString(messageName, "ToggleCapsLock")) {
    1514         TestController::singleton().toggleCapsLock();
    1515         return nullptr;
    1516     }
    1517 #endif
    1518 
    15191512    ASSERT_NOT_REACHED();
    15201513    return nullptr;
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r238125 r238512  
    390390}
    391391
    392 #if PLATFORM(MAC)
    393 void TestController::toggleCapsLock()
    394 {
    395     m_capsLockOn = !m_capsLockOn;
    396     NSEvent *fakeEvent = [NSEvent keyEventWithType:NSEventTypeFlagsChanged
    397         location:NSZeroPoint
    398         modifierFlags:m_capsLockOn ? NSEventModifierFlagCapsLock : 0
    399         timestamp:0
    400         windowNumber:[mainWebView()->platformWindow() windowNumber]
    401         context:nullptr
    402         characters:@""
    403         charactersIgnoringModifiers:@""
    404         isARepeat:NO
    405         keyCode:57];
    406    
    407     [mainWebView()->platformWindow() sendEvent:fakeEvent];
    408 }
    409 #endif
    410 
    411392} // namespace WTR
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r238475 r238512  
    911911}
    912912
     913void UIScriptController::toggleCapsLock(JSValueRef callback)
     914{
     915    // FIXME: Implement for iOS. See <https://bugs.webkit.org/show_bug.cgi?id=191815>.
     916    doAsyncTask(callback);
     917}
     918
    913919}
    914920
  • trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r237786 r238512  
    192192}
    193193
     194void UIScriptController::toggleCapsLock(JSValueRef callback)
     195{
     196    m_capsLockOn = !m_capsLockOn;
     197    NSWindow *window = [TestController::singleton().mainWebView()->platformView() window];
     198    NSEvent *fakeEvent = [NSEvent keyEventWithType:NSEventTypeFlagsChanged
     199        location:NSZeroPoint
     200        modifierFlags:m_capsLockOn ? NSEventModifierFlagCapsLock : 0
     201        timestamp:0
     202        windowNumber:window.windowNumber
     203        context:nullptr
     204        characters:@""
     205        charactersIgnoringModifiers:@""
     206        isARepeat:NO
     207        keyCode:57];
     208    [window sendEvent:fakeEvent];
     209    doAsyncTask(callback);
     210}
     211
    194212} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.