[autofill] Pin preview font-family to a system font

(Merge to M74)

Bug: 916838
Change-Id: I4e874105262f2e15a11a7a18a7afd204e5827400
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1423109
Reviewed-by: Fabio Tirelo <ftirelo@chromium.org>
Reviewed-by: Koji Ishii <kojii@chromium.org>
Commit-Queue: Roger McFarlane <rogerm@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#640884}(cherry picked from commit 0bd10e13a008389ec14bbe7cc95f17d82ea151c1)
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1544309
Reviewed-by: Roger McFarlane <rogerm@chromium.org>
Cr-Commit-Position: refs/branch-heads/3729@{#512}
Cr-Branched-From: d4a8972e30b604f090aeda5dfff68386ae656267-refs/heads/master@{#638880}
diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc
index d8207cd2..e27de98 100644
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc
@@ -13,6 +13,7 @@
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/test/scoped_feature_list.h"
+#include "build/build_config.h"
 #include "chrome/test/base/chrome_render_view_test.h"
 #include "components/autofill/content/renderer/form_autofill_util.h"
 #include "components/autofill/content/renderer/form_cache.h"
@@ -32,6 +33,10 @@
 #include "third_party/blink/public/web/web_script_source.h"
 #include "third_party/blink/public/web/web_select_element.h"
 
+#if defined(OS_WIN)
+#include "third_party/blink/public/web/win/web_font_rendering.h"
+#endif
+
 using autofill::features::kAutofillEnforceMinRequiredFieldsForHeuristics;
 using autofill::features::kAutofillEnforceMinRequiredFieldsForQuery;
 using autofill::features::kAutofillEnforceMinRequiredFieldsForUpload;
@@ -279,6 +284,17 @@
   }
   ~FormAutofillTest() override {}
 
+#if defined(OS_WIN)
+  void SetUp() override {
+    ChromeRenderViewTest::SetUp();
+
+    // Autofill uses the system font to render suggestion previews. On Windows
+    // an extra step is required to ensure that the system font is configured.
+    blink::WebFontRendering::SetMenuFontMetrics(
+        base::ASCIIToUTF16("Arial").c_str(), 12);
+  }
+#endif
+
   void ExpectLabels(const char* html,
                     const std::vector<base::string16>& id_attributes,
                     const std::vector<base::string16>& name_attributes,
diff --git a/third_party/blink/renderer/core/html/resources/html.css b/third_party/blink/renderer/core/html/resources/html.css
index 96fd1f8..ccf544a 100644
--- a/third_party/blink/renderer/core/html/resources/html.css
+++ b/third_party/blink/renderer/core/html/resources/html.css
@@ -559,10 +559,16 @@
 /* TODO(crbug.com/880258): Use different styles for
   `-internal-autofill-previewed` and `-internal-autofill-selected`. */
 input:-internal-autofill-previewed,
-input:-internal-autofill-selected,
 textarea:-internal-autofill-previewed,
+select:-internal-autofill-previewed {
+  font-family: system-ui !important;
+  background-color: #E8F0FE !important;
+  background-image:none !important;
+  color: #000000 !important;
+}
+
+input:-internal-autofill-selected,
 textarea:-internal-autofill-selected,
-select:-internal-autofill-previewed,
 select:-internal-autofill-selected {
   background-color: #E8F0FE !important;
   background-image:none !important;