Changeset 268633 in webkit


Ignore:
Timestamp:
Oct 16, 2020 9:21:09 PM (3 years ago)
Author:
rniwa@webkit.org
Message:

IPC testing API should expose whether a given IPC message has sync reply or not
https://bugs.webkit.org/show_bug.cgi?id=217861

Reviewed by Darin Adler.

Source/WebKit:

This patch adds IPC.messages.*.isSync to indicate whether a given IPC message has a sync reply or not.

Test: TestWebKitAPI.IPCTestingAPI.AlertIsSyncMessage

  • Platform/IPC/MessageArgumentDescriptions.h:
  • Scripts/webkit/messages.py:

(generate_js_value_conversion_function): Fixed a typo.
(generate_js_argument_descriptions): Ditto.
(generate_message_argument_description_implementation): Generate messageIsSync function.

  • WebProcess/WebPage/IPCTestingAPI.cpp:

(WebKit::JSIPC::wrapperClass): Updated the class name to match the implementation.
(WebKit::IPCTestingAPI::JSIPC::messages): Added isSync as a boolean property on message description.

Tools:

Added a test for IPC.messages.*.isSync using RunJavaScriptAlert.

  • TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:

(createWebViewWithIPCTestingAPI): Extracted to share more code between tests.
(IPCTestingAPI.AlertIsSyncMessage): Added.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r268632 r268633  
     12020-10-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        IPC testing API should expose whether a given IPC message has sync reply or not
     4        https://bugs.webkit.org/show_bug.cgi?id=217861
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch adds IPC.messages.*.isSync to indicate whether a given IPC message has a sync reply or not.
     9
     10        Test: TestWebKitAPI.IPCTestingAPI.AlertIsSyncMessage
     11
     12        * Platform/IPC/MessageArgumentDescriptions.h:
     13        * Scripts/webkit/messages.py:
     14        (generate_js_value_conversion_function): Fixed a typo.
     15        (generate_js_argument_descriptions): Ditto.
     16        (generate_message_argument_description_implementation): Generate messageIsSync function.
     17        * WebProcess/WebPage/IPCTestingAPI.cpp:
     18        (WebKit::JSIPC::wrapperClass): Updated the class name to match the implementation.
     19        (WebKit::IPCTestingAPI::JSIPC::messages): Added isSync as a boolean property on message description.
     20
    1212020-10-16  Peng Liu  <peng.liu6@apple.com>
    222
  • trunk/Source/WebKit/Platform/IPC/MessageArgumentDescriptions.h

    r268503 r268633  
    5353Optional<Vector<ArgumentDescription>> messageArgumentDescriptions(MessageName);
    5454Optional<Vector<ArgumentDescription>> messageReplyArgumentDescriptions(MessageName);
     55bool messageIsSync(MessageName);
    5556
    5657}
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r268503 r268633  
    10651065        if receiver.condition:
    10661066            result.append('#if %s\n' % receiver.condition)
    1067         prevision_message_condition = None
     1067        previous_message_condition = None
    10681068        for message in receiver.messages:
    10691069            if not predicate(message):
    10701070                continue
    1071             if prevision_message_condition != message.condition:
    1072                 if prevision_message_condition:
     1071            if previous_message_condition != message.condition:
     1072                if previous_message_condition:
    10731073                    result.append('#endif\n')
    10741074                if message.condition:
    10751075                    result.append('#if %s\n' % message.condition)
    1076             prevision_message_condition = message.condition
     1076            previous_message_condition = message.condition
    10771077            result.append('    case MessageName::%s_%s:\n' % (receiver.name, message.name))
    10781078            result.append('        return jsValueForDecodedArguments<Messages::%s::%s::%s>(globalObject, decoder);\n' % (receiver.name, message.name, argument_type))
    1079         if prevision_message_condition:
     1079        if previous_message_condition:
    10801080            result.append('#endif\n')
    10811081        if receiver.condition:
     
    10961096        if receiver.condition:
    10971097            result.append('#if %s\n' % receiver.condition)
    1098         prevision_message_condition = None
     1098        previous_message_condition = None
    10991099        for message in receiver.messages:
    11001100            argument_list = arguments_from_message(message)
    11011101            if argument_list is None:
    11021102                continue
    1103             if prevision_message_condition != message.condition:
    1104                 if prevision_message_condition:
     1103            if previous_message_condition != message.condition:
     1104                if previous_message_condition:
    11051105                    result.append('#endif\n')
    11061106                if message.condition:
    11071107                    result.append('#if %s\n' % message.condition)
    1108             prevision_message_condition = message.condition
     1108            previous_message_condition = message.condition
    11091109            result.append('    case MessageName::%s_%s:\n' % (receiver.name, message.name))
    11101110
     
    11261126                result.append('            {"%s", "%s", %s, %s},\n' % (argument.name, argument_type, enum_type or 'nullptr', 'true' if is_optional else 'false'))
    11271127            result.append('        };\n')
    1128         if prevision_message_condition:
     1128        if previous_message_condition:
    11291129            result.append('#endif\n')
    11301130        if receiver.condition:
     
    11781178
    11791179    result.append('\n')
     1180    result.append('bool messageIsSync(MessageName name)\n')
     1181    result.append('{\n')
     1182    result.append('    switch (name) {\n')
     1183    for receiver in receivers:
     1184        has_emit_receiver_condition = False
     1185        previous_message_condition = None
     1186        for message in receiver.messages:
     1187            if message.reply_parameters is None or not message.has_attribute(SYNCHRONOUS_ATTRIBUTE):
     1188                continue
     1189            if not has_emit_receiver_condition and receiver.condition:
     1190                has_emit_receiver_condition = True
     1191                result.append('#if %s\n' % receiver.condition)
     1192            if previous_message_condition != message.condition:
     1193                if previous_message_condition:
     1194                    result.append('#endif\n')
     1195                if message.condition:
     1196                    result.append('#if %s\n' % message.condition)
     1197            previous_message_condition = message.condition
     1198            result.append('    case MessageName::%s_%s:\n' % (receiver.name, message.name))
     1199            result.append('        return true;\n')
     1200        if previous_message_condition:
     1201            result.append('#endif\n')
     1202        if has_emit_receiver_condition:
     1203            result.append('#endif\n')
     1204    result.append('    default:\n')
     1205    result.append('        break;\n')
     1206    result.append('    }\n')
     1207    result.append('    return false;\n')
     1208    result.append('}\n')
     1209    result.append('\n')
    11801210
    11811211    result.append('} // namespace WebKit\n')
  • trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp

    r268503 r268633  
    100100    if (!jsClass) {
    101101        JSClassDefinition definition = kJSClassDefinitionEmpty;
    102         definition.className = "UIProcess";
     102        definition.className = "IPC";
    103103        definition.parentClass = 0;
    104104        definition.staticValues = staticValues();
     
    773773    auto nameIdent = JSC::Identifier::fromString(vm, "name");
    774774    auto replyArgumentsIdent = JSC::Identifier::fromString(vm, "replyArguments");
     775    auto isSyncIdent = JSC::Identifier::fromString(vm, "isSync");
    775776    for (unsigned i = 0; i < static_cast<unsigned>(IPC::MessageName::Last); ++i) {
    776777        auto name = static_cast<IPC::MessageName>(i);
     
    792793            return JSValueMakeUndefined(context);
    793794        dictionary->putDirect(vm, replyArgumentsIdent, replyArgumentDescriptions);           
     795        RETURN_IF_EXCEPTION(scope, JSValueMakeUndefined(context));
     796
     797        dictionary->putDirect(vm, isSyncIdent, JSC::jsBoolean(messageIsSync(name)));           
    794798        RETURN_IF_EXCEPTION(scope, JSValueMakeUndefined(context));
    795799
  • trunk/Tools/ChangeLog

    r268616 r268633  
     12020-10-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        IPC testing API should expose whether a given IPC message has sync reply or not
     4        https://bugs.webkit.org/show_bug.cgi?id=217861
     5
     6        Reviewed by Darin Adler.
     7
     8        Added a test for IPC.messages.*.isSync using RunJavaScriptAlert.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
     11        (createWebViewWithIPCTestingAPI): Extracted to share more code between tests.
     12        (IPCTestingAPI.AlertIsSyncMessage): Added.
     13
    1142020-10-16  Antoine Quint  <graouts@webkit.org>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm

    r268503 r268633  
    8282#if ENABLE(IPC_TESTING_API)
    8383
    84 TEST(IPCTestingAPI, CanSendAlert)
     84static RetainPtr<TestWKWebView> createWebViewWithIPCTestingAPI()
    8585{
    8686    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     
    9191        }
    9292    }
    93     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     93    return adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     94}
     95
     96TEST(IPCTestingAPI, CanSendAlert)
     97{
     98    auto webView = createWebViewWithIPCTestingAPI();
    9499
    95100    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     
    104109}
    105110
     111TEST(IPCTestingAPI, AlertIsSyncMessage)
     112{
     113    auto webView = createWebViewWithIPCTestingAPI();
     114
     115    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     116    [webView setUIDelegate:delegate.get()];
     117
     118    done = false;
     119    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>alert(IPC.messages.WebPageProxy_RunJavaScriptAlert.isSync);</script>"];
     120    TestWebKitAPI::Util::run(&done);
     121
     122    EXPECT_STREQ([alertMessage UTF8String], "true");
     123}
     124
    106125TEST(IPCTestingAPI, CanSendInvalidAsyncMessageWithoutTermination)
    107126{
    108     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    109     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
    110         if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
    111             [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
    112             break;
    113         }
    114     }
    115     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     127    auto webView = createWebViewWithIPCTestingAPI();
    116128
    117129    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     
    129141TEST(IPCTestingAPI, CanSendInvalidMessageWithoutTermination)
    130142{
    131     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    132     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
    133         if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
    134             [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
    135             break;
    136         }
    137     }
    138     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     143    auto webView = createWebViewWithIPCTestingAPI();
    139144
    140145    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     
    152157TEST(IPCTestingAPI, DecodesReplyArgumentsForPrompt)
    153158{
    154     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    155     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
    156         if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
    157             [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
    158             break;
    159         }
    160     }
    161     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     159    auto webView = createWebViewWithIPCTestingAPI();
    162160
    163161    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     
    177175TEST(IPCTestingAPI, DecodesReplyArgumentsForAsyncMessage)
    178176{
    179     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    180     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
    181         if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
    182             [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
    183             break;
    184         }
    185     }
    186     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     177    auto webView = createWebViewWithIPCTestingAPI();
    187178
    188179    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     
    202193TEST(IPCTestingAPI, DescribesArguments)
    203194{
    204     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    205     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
    206         if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
    207             [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
    208             break;
    209         }
    210     }
    211     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     195    auto webView = createWebViewWithIPCTestingAPI();
    212196
    213197    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
Note: See TracChangeset for help on using the changeset viewer.