New issue
Advanced search Search tips

Issue 658099 link

Starred by 2 users

Issue metadata

Status: Assigned
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug
Team-Security-UX

Blocking:
issue 659801



Sign in to add a comment

Simplify ChromeSecurityStateModelClient console message tests

Project Member Reported by est...@chromium.org, Oct 21 2016

Issue description

ChromeSecurityStateModelClient 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.
 

Comment 1 by est...@chromium.org, Oct 26 2016

Blocking: 659801

Comment 2 by mea...@chromium.org, 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?

Comment 3 by est...@chromium.org, 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.

Comment 4 by dcheng@chromium.org, 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?

Comment 5 by mea...@chromium.org, 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.

Comment 6 by est...@chromium.org, Oct 26 2016

Ok, yeah, I think either of those approaches would work (waiting for a dummy message at the end, or a MockConsoleDelegate.)

Comment 7 by est...@chromium.org, Oct 26 2016

Components: -Content>Core
Summary: Simply ChromeSecurityStateModelClient console message tests (was: Add a MockRenderProcessHost method to spy on the console messages)
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.
Components: -Security>UX Internals>PageSecurityState
Summary: Simplify ChromeSecurityStateModelClient console message tests (was: Simply ChromeSecurityStateModelClient console message tests)

Comment 9 by est...@chromium.org, Nov 10 2017

Labels: Hotlist-EnamelAndFriendsFixIt
Labels: -Hotlist-EnamelAndFriendsFixIt

Sign in to add a comment