Fix flaky HeadlessWebContentsTest focus test.

This test is a bit flaky:
https://test-results.appspot.com/dashboards/flakiness_dashboard.html#testType=headless_browsertests&tests=FocusOfHeadlessWebContents_IsIndependent

Furthermore, I am working on https://crbug.com/831155. It causes the
frame to commit a navigation more quickly. As a result the frame may
stop loading sooner. It causes this test to become even flakier.

Why this test is flaky?
It waits for the main frame to stop loading by calling WaitForLoad().
Then it waits for the main frame to gain focus by calling
WaitForFocus(). In reality, it may gain focus before it stops loading.
Since WaitForFocus() doesn't check whether or not the main frame is
already focused before waiting, it may wait forever.

The CL makes the tests wait for both event to happen, no matter the
order.

Related CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1026993

Bug: 831155
Change-Id: Id9002b3ee2a06ef17d670858688d28959f334e03
Reviewed-on: https://chromium-review.googlesource.com/1053777
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558262}
3 files changed