Sometimes when running EG tests, DCHECK in BrowserStateDataRemover::RemoveBrowserStateData because UIApplication -keyWindow returns nil.
This happens if AuthenticationServiceFactory::CreateAndInitializeForBrowserState invokes its AuthenticationServiceDelegate's ClearBrowsingData which happens synchronously as part of the initialisation under certain circumstances.
In that case the DCHECK fails because makeKeyAndVisible is invoked from MainController -createInitialUI: which happens after the initialisation of AuthenticationServiceFactory.
This was introduced by https://chromium-review.googlesource.com/863666 that moved the initialisation from a background queue to the main thread. As initialisation was asynchronous before, it happened after the registration of the keyWindow. Fix would be to post the call to BrowserDataRemover on a background task.
Comment 1 by huangml@chromium.org
, Feb 22 2018