NEW222957
[Cocoa] Add tests for ArgumentCodersCocoa
https://bugs.webkit.org/show_bug.cgi?id=222957
Summary [Cocoa] Add tests for ArgumentCodersCocoa
Brent Fulgham
Reported 2021-03-08 20:43:51 PST
We wouldn't have encountered Bug 222856 if we had better coverage for our IPC argument coders. Let's star that effort by hitting a few of the recent cases we've encountered.
Attachments
Patch (18.84 KB, patch)
2021-03-08 21:29 PST, Brent Fulgham
no flags
Patch (15.64 KB, patch)
2021-03-09 20:03 PST, Brent Fulgham
ews-feeder: commit-queue-
Patch (15.63 KB, patch)
2021-03-09 20:36 PST, Brent Fulgham
bfulgham: review?
ews-feeder: commit-queue-
Radar WebKit Bug Importer
Comment 1 2021-03-08 20:44:27 PST
Brent Fulgham
Comment 2 2021-03-08 21:29:29 PST
Brent Fulgham
Comment 3 2021-03-09 20:03:12 PST
Brent Fulgham
Comment 4 2021-03-09 20:36:03 PST
Simon Fraser (smfr)
Comment 5 2021-03-10 09:14:08 PST
Comment on attachment 422790 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422790&action=review > Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:105 > ++ (Optional<RetainPtr<id>>)_roundTripIPCEncodeDecodeObject:(id)testObject ofClass:(Class)classType; Yuck.
Darin Adler
Comment 6 2021-03-10 09:46:13 PST
Comment on attachment 422790 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422790&action=review >> Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:105 >> ++ (Optional<RetainPtr<id>>)_roundTripIPCEncodeDecodeObject:(id)testObject ofClass:(Class)classType; > > Yuck. Why do we need to use Optional here? RetainPtr already has a nil value. Do we need to distinguish "nil" and "not present"?
Sam Weinig
Comment 7 2021-03-10 09:49:38 PST
Comment on attachment 422790 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422790&action=review > Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:360 > + auto encoder = IPC::Encoder(IPC::MessageName::WebPage_LoadRequest, 0); > + encoder << testObject; > + > + auto decoder = IPC::Decoder::create(encoder.buffer(), encoder.bufferSize(), nullptr, { }); > + if (!decoder) > + return WTF::nullopt; > + > + return IPC::decodeObject(*decoder, @[classType]); I think we should try to just write this code directly in TestWebKitAPI if we can, rather than exposing this new class method.
Sam Weinig
Comment 8 2021-03-10 10:18:46 PST
(In reply to Sam Weinig from comment #7) > Comment on attachment 422790 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=422790&action=review > > > Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:360 > > + auto encoder = IPC::Encoder(IPC::MessageName::WebPage_LoadRequest, 0); > > + encoder << testObject; > > + > > + auto decoder = IPC::Decoder::create(encoder.buffer(), encoder.bufferSize(), nullptr, { }); > > + if (!decoder) > > + return WTF::nullopt; > > + > > + return IPC::decodeObject(*decoder, @[classType]); > > I think we should try to just write this code directly in TestWebKitAPI if > we can, rather than exposing this new class method. Actually, I think that will probably require splitting the IPC code out into its own static library, which we should probably do. But not for this. I think the Optional<RetainPtr<>> is very odd though.
Brent Fulgham
Comment 9 2021-03-10 14:13:03 PST
Comment on attachment 422790 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422790&action=review >>> Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:105 >>> ++ (Optional<RetainPtr<id>>)_roundTripIPCEncodeDecodeObject:(id)testObject ofClass:(Class)classType; >> >> Yuck. > > Why do we need to use Optional here? RetainPtr already has a nil value. Do we need to distinguish "nil" and "not present"? It's a pretty common idiom in our IPC serialization code. We return an Optional (null opt) on errors. Sometimes the encoded value is null (but not an error). But maybe that's not important for this case. >>> Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:360 >>> + return IPC::decodeObject(*decoder, @[classType]); >> >> I think we should try to just write this code directly in TestWebKitAPI if we can, rather than exposing this new class method. > > Actually, I think that will probably require splitting the IPC code out into its own static library, which we should probably do. But not for this. > > I think the Optional<RetainPtr<>> is very odd though. It's just mirroring exactly what IPC::decodeObject returns. Optional (WTF::nullopt) signifies error, Optional(RefPtr<something null>) is an encoded null value.
Darin Adler
Comment 10 2021-03-10 14:48:21 PST
(In reply to Brent Fulgham from comment #9) > It's a pretty common idiom in our IPC serialization code. We return an > Optional (null opt) on errors. Sometimes the encoded value is null (but not > an error). But maybe that's not important for this case. Yes, I’m familiar with that idiom when we support encoding nil. I think in this case we don’t need the distinction. We don’t need to test the nil support. Not using Optional<> would simplify that test header.
Note You need to log in before you can comment on or make changes to this bug.