Allow changing AppWindowClient for tests

AppWindowClient::Set sets the global AppWindowClient. Unit tests
sometimes call it more than once, e.g. when multiple BrowserProcesses
are created. Currently, each additional call silently returns instead of
changing g_client. Even Set(nullptr) does nothing.

Normally, this is fine: only tests should call it more than once, and
usually it's called with the same value anyway (because BrowserProcess
and TestingBrowserProcess both use the global ChromeAppWindowClient
singleton).

Some tests do create and destroy unique AppWindowClients, like ones in
app_shell_unittest. This CL allows g_client to be changed to nullptr and
then to a new value. Otherwise, since these tests run sequentially in the
same process, g_client may point to freed memory. This will become an
issue as we add more tests here.

Bug: 751242
Change-Id: I1bfa8f12f1fbbd5e086ae3c033e038b93c5a18ce
Reviewed-on: https://chromium-review.googlesource.com/593052
Commit-Queue: Michael Giuffrida <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#491645}
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 3174931..894f6804 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -257,7 +257,6 @@
   device_client_.reset(new ChromeDeviceClient);
 
 #if BUILDFLAG(ENABLE_EXTENSIONS)
-  // Athena sets its own instance during Athena's init process.
   extensions::AppWindowClient::Set(ChromeAppWindowClient::GetInstance());
 
   extension_event_router_forwarder_ = new extensions::EventRouterForwarder;
@@ -284,6 +283,7 @@
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
 #if BUILDFLAG(ENABLE_EXTENSIONS)
   extensions::ExtensionsBrowserClient::Set(nullptr);
+  extensions::AppWindowClient::Set(nullptr);
 #endif
 
 #if !defined(OS_ANDROID)