content: makes content browsertests subclass test ContentBrowserClient

Some times tests need to replace the ContentBrowserClient. This
is often done by subclassing ContentBrowserClient and replacing
ContentBrowserClient during test execution. This is problematic
as certain things (such as RegisterBrowserInterfaceBindersForFrame)
are provided by ShellContentBrowserClient, and if not present
result in bad behavior (killing the renderer), which leads to flake.

To fix this problem this patch does the following:
. Moves ContentBrowserTestShellContentBrowserClient to its own
  header and renames it to
  ContentBrowserTestContentBrowserClient.
. makes SetBrowserClientForTesting() CHECK in content_browsertests.
. changes all browsertests to use
  ContentBrowserTestContentBrowserClient.
. Changes ShellContentBrowserClient so that it sets the browser
  client when called the second time (effectively what
  SetBrowserClientForTesting() does).

Bug: 1406282

Change-Id: Ieaa7cfa09a53e9618b963d6cc4b931226d2c799e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4222392
Commit-Queue: Scott Violet <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1102490}
diff --git a/content/browser/renderer_host/cookie_browsertest.cc b/content/browser/renderer_host/cookie_browsertest.cc
index c646801..6697faaa 100644
--- a/content/browser/renderer_host/cookie_browsertest.cc
+++ b/content/browser/renderer_host/cookie_browsertest.cc
@@ -24,6 +24,7 @@
 #include "content/public/test/browser_test.h"
 #include "content/public/test/browser_test_utils.h"
 #include "content/public/test/content_browser_test.h"
+#include "content/public/test/content_browser_test_content_browser_client.h"
 #include "content/public/test/content_browser_test_utils.h"
 #include "content/public/test/test_utils.h"
 #include "content/shell/browser/shell.h"
@@ -378,7 +379,8 @@
   mojo::Remote<network::mojom::RestrictedCookieManager> real_rcm_;
 };
 
-class CookieStoreContentBrowserClient : public ContentBrowserClient {
+class CookieStoreContentBrowserClient
+    : public ContentBrowserTestContentBrowserClient {
  public:
   ~CookieStoreContentBrowserClient() override = default;
 
@@ -458,12 +460,8 @@
   // Try to get cross-site cookies from the subframe's process.
   {
     CookieStoreContentBrowserClient browser_client;
-    content::ContentBrowserClient* old_browser_client =
-        content::SetBrowserClientForTesting(&browser_client);
     browser_client.set_override_url("http://127.0.0.1/");
     EXPECT_EQ("", GetCookieFromJS(iframe));
-
-    content::SetBrowserClientForTesting(old_browser_client);
   }
 
   EXPECT_EQ(
@@ -476,15 +474,11 @@
   // Now set a cross-site cookie from the main frame's process.
   {
     CookieStoreContentBrowserClient browser_client;
-    content::ContentBrowserClient* old_browser_client =
-        content::SetBrowserClientForTesting(&browser_client);
 
     browser_client.set_override_url("https://baz.com/");
     SetCookieFromJS(iframe, "pwn=ed");
 
     EXPECT_EQ("B_cookie=child", GetCookiesDirect(tab, GURL("http://baz.com/")));
-
-    content::SetBrowserClientForTesting(old_browser_client);
   }
 
   EXPECT_EQ(