Issue metadata
Sign in to add a comment
|
Simplify ChromeSecurityStateModelClient console message tests |
||||||||||||||||||||
Issue descriptionChromeSecurityStateModelClient has various tests that console messages are logged as expected. These tests are a bit complicated (and also not that thorough) because to test that a console message is logged, they have to wait for an async notification to come up through WebContentsDelegate. These would be much simplified if we could add a MockRenderProcessHost method to retrieve the FrameMsg_AddMessageToConsole IPCs that have been sent. Then these tests could be unit tests that synchronously retrieve the console message IPCs and check that they are as expected, instead of browser tests that wait for async notifications from Blink that console messages have been added.
,
Oct 26 2016
Another drive-by, because I had to do something similar in crrev.com/1917073002 to listen to console messages :) I see that ConsoleWebContentsDelegate used in the current tests is very similar to ConsoleObserverDelegate from cr/1917073002, so it seems you could use that instead? And perhaps we should rename ConsoleObserverDelegate to ConsoleMessageWaiter or something more searchable. That aside, it seems a bit odd to me to have to keep track of IPCs in unit tests. Wouldn't it be cleaner to delegate logging of the console message to a mock class instead?
,
Oct 26 2016
Oh, cool, yes we should be using ConsoleObserverDelegate instead. > Wouldn't it be cleaner to delegate logging of the console message to a mock class instead? Do you mean that RenderFrameHostImpl::AddMessageToConsole() should send the message to a class that sends the IPC, so that the class can be mocked? Or that ChromeSecurityStateModelClient should use a separate class (that can be mocked) to send the console message instead of calling the RFH directly? To me, the main limitation is that a test should be able to synchronously check that a console message was logged, because otherwise we can't really test that a console message was *not* logged when it shouldn't have been.
,
Oct 26 2016
It's a bit hacky, but we could get around that by logging a final message at the end and checking that only the final message appears, right?
,
Oct 26 2016
> Do you mean that RenderFrameHostImpl::AddMessageToConsole() should send the message to a class that sends the IPC, so that the class can be mocked? Or that ChromeSecurityStateModelClient should use a separate class (that can be mocked) to send the console message instead of calling the RFH directly? The latter. You can wrap |web_contents_->GetMainFrame()->AddMessageToConsole()| call in a ConsoleDelegate class. Test code then uses a MockConsoleDelegate which just keeps track of which messages were logged. That way you should be able to synchronously test for an unexpected message.
,
Oct 26 2016
Ok, yeah, I think either of those approaches would work (waiting for a dummy message at the end, or a MockConsoleDelegate.)
,
Oct 26 2016
Re-titling and -labeling to reflect the various options we can do to simplify these tests: - Use the pre-existing ConsoleObserverDelegate instead of re-inventing the wheel. - Log a dummy message and wait for it to test that a console message isn't added. - Or have ChromeSSMClient log to a ConsoleDelegate that can be mocked for tests.
,
Oct 26 2016
,
Nov 10 2017
,
Feb 18 2018
|
|||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||
Comment 1 by est...@chromium.org
, Oct 26 2016