Fix components_browsertests for iOS

- Add require bundle data for the component_browsertests.
- Disable one PaintPreviewRecorder test for now.
- Use appropriate defines in tests for IS_IOS
- Do not use the csp_nonce when building the dom_distiller
for blink on iOS (this matches the other platforms that use
content)

Bug: 1427365
Change-Id: Ia6991b644a817c65a225d90d3cd31bf8e52cc9c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4567469
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1149788}
diff --git a/components/BUILD.gn b/components/BUILD.gn
index 9f5f048d..ad4e3b1 100644
--- a/components/BUILD.gn
+++ b/components/BUILD.gn
@@ -47,6 +47,23 @@
     }
     outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
   }
+
+  if (use_blink) {
+    bundle_data("components_tests_distiller_bundle_data") {
+      testonly = true
+      sources = [
+        "//third_party/chaijs/chai.js",
+        "//third_party/dom_distiller_js/dist/test/data/out/domdistillerjstest.js",
+        "//third_party/dom_distiller_js/dist/test/data/war/test.html",
+        "//third_party/mocha/mocha.js",
+        "dom_distiller/core/javascript/dom_distiller_viewer.js",
+        "dom_distiller/core/javascript/domdistiller.js",
+        "dom_distiller/core/javascript/extract_features.js",
+      ]
+      outputs = [ "{{bundle_resources_dir}}/" +
+                  "{{source_root_relative_dir}}/{{source_file_part}}" ]
+    }
+  }
 }
 
 # Omit Lacros because it allows //components to depend on //chrome, which in
@@ -411,6 +428,9 @@
       "//components/translate/ios/browser:unit_tests",
       "//components/ukm/ios:unit_tests",
     ]
+    if (use_blink) {
+      deps += [ ":components_tests_distiller_bundle_data" ]
+    }
   } else {  #!is_ios
     deps += [
       "//components/background_sync:unit_tests",
@@ -906,7 +926,13 @@
     }
 
     if (is_ios) {
-      deps += [ ":components_tests_pak_bundle_data" ]
+      deps += [
+        ":components_tests_distiller_bundle_data",
+        ":components_tests_pak_bundle_data",
+        "test:dom_distiller_test_bundle_data",
+        "test:url_rewrite_test_bundle_data",
+        "//content/test:content_test_bundle_data",
+      ]
     }
 
     if (enable_pdf) {
diff --git a/components/custom_handlers/BUILD.gn b/components/custom_handlers/BUILD.gn
index 475a2be..5da78c2 100644
--- a/components/custom_handlers/BUILD.gn
+++ b/components/custom_handlers/BUILD.gn
@@ -95,4 +95,10 @@
     "//testing/gmock",
     "//testing/gtest",
   ]
+  if (is_ios) {
+    deps += [
+      "//components/test:custom_handlers_test_bundle_data",
+      "//components/test:fenced_frames_test_bundle_data",
+    ]
+  }
 }
diff --git a/components/dom_distiller/content/browser/test/distilled_page_js_browsertest.cc b/components/dom_distiller/content/browser/test/distilled_page_js_browsertest.cc
index ad8a4fd9..1c57a2b 100644
--- a/components/dom_distiller/content/browser/test/distilled_page_js_browsertest.cc
+++ b/components/dom_distiller/content/browser/test/distilled_page_js_browsertest.cc
@@ -58,7 +58,7 @@
 }
 
 // FontSizeSlider is only used on Desktop.
-#if BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
 #define MAYBE_FontSizeSlider DISABLED_FontSizeSlider
 #else
 #define MAYBE_FontSizeSlider FontSizeSlider
diff --git a/components/dom_distiller/content/browser/test/dom_distiller_js_browsertest.cc b/components/dom_distiller/content/browser/test/dom_distiller_js_browsertest.cc
index 312744f..9a7cc17c 100644
--- a/components/dom_distiller/content/browser/test/dom_distiller_js_browsertest.cc
+++ b/components/dom_distiller/content/browser/test/dom_distiller_js_browsertest.cc
@@ -91,7 +91,7 @@
 #if BUILDFLAG(IS_ANDROID)
     CHECK(base::PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir));
     pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks"));
-#elif BUILDFLAG(IS_MAC)
+#elif BUILDFLAG(IS_APPLE)
     base::PathService::Get(base::DIR_MODULE, &pak_dir);
 #else
     base::PathService::Get(base::DIR_ASSETS, &pak_dir);
diff --git a/components/dom_distiller/content/browser/test/test_util.cc b/components/dom_distiller/content/browser/test/test_util.cc
index b6bfa17..de7a8b2f 100644
--- a/components/dom_distiller/content/browser/test/test_util.cc
+++ b/components/dom_distiller/content/browser/test/test_util.cc
@@ -116,7 +116,7 @@
 #if BUILDFLAG(IS_ANDROID)
   CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir));
   pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks"));
-#elif BUILDFLAG(IS_MAC)
+#elif BUILDFLAG(IS_APPLE)
   PathService::Get(base::DIR_MODULE, &pak_dir);
 #else
   PathService::Get(base::DIR_ASSETS, &pak_dir);
diff --git a/components/dom_distiller/core/BUILD.gn b/components/dom_distiller/core/BUILD.gn
index d94b2ee..7bad8e8 100644
--- a/components/dom_distiller/core/BUILD.gn
+++ b/components/dom_distiller/core/BUILD.gn
@@ -54,6 +54,7 @@
   ]
   deps = [
     "//base",
+    "//build:blink_buildflags",
     "//components/dom_distiller/core/mojom",
     "//components/leveldb_proto",
     "//components/pref_registry",
diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc
index 987e947..33f765e 100644
--- a/components/dom_distiller/core/viewer.cc
+++ b/components/dom_distiller/core/viewer.cc
@@ -14,6 +14,7 @@
 #include "base/strings/strcat.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
+#include "build/blink_buildflags.h"
 #include "build/build_config.h"
 #include "components/dom_distiller/core/distilled_page_prefs.h"
 #include "components/dom_distiller/core/dom_distiller_service.h"
@@ -160,7 +161,7 @@
   std::ostringstream csp;
   std::ostringstream css;
   std::ostringstream svg;
-#if BUILDFLAG(IS_IOS)
+#if BUILDFLAG(IS_IOS) && !BUILDFLAG(USE_BLINK)
   // On iOS the content is inlined as there is no API to detect those requests
   // and return the local data once a page is loaded.
   css << "<style>" << viewer::GetCss() << "</style>";
diff --git a/components/paint_preview/renderer/paint_preview_recorder_browsertest.cc b/components/paint_preview/renderer/paint_preview_recorder_browsertest.cc
index d79d823a..6cc7d28 100644
--- a/components/paint_preview/renderer/paint_preview_recorder_browsertest.cc
+++ b/components/paint_preview/renderer/paint_preview_recorder_browsertest.cc
@@ -114,7 +114,16 @@
   base::test::ScopedFeatureList feature_list_;
 };
 
-TEST_P(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameAndClipping) {
+// TODO(crbug.com/1448918): The color returned on iOS is incorrect.
+#if BUILDFLAG(IS_IOS)
+#define MAYBE_TestCaptureMainFrameAndClipping \
+  DISABLED_TestCaptureMainFrameAndClipping
+#else
+#define MAYBE_TestCaptureMainFrameAndClipping TestCaptureMainFrameAndClipping
+#endif
+
+TEST_P(PaintPreviewRecorderRenderViewTest,
+       MAYBE_TestCaptureMainFrameAndClipping) {
   LoadHTML(
       "<!doctype html>"
       "<body>"
diff --git a/components/performance_manager/BUILD.gn b/components/performance_manager/BUILD.gn
index c3696899..b61fd11 100644
--- a/components/performance_manager/BUILD.gn
+++ b/components/performance_manager/BUILD.gn
@@ -389,4 +389,8 @@
     "//testing/gmock",
     "//testing/gtest",
   ]
+
+  if (is_ios) {
+    deps += [ "//components/test:performance_manager_test_bundle_data" ]
+  }
 }
diff --git a/components/test/BUILD.gn b/components/test/BUILD.gn
index 1d674fb..cbb8136a 100644
--- a/components/test/BUILD.gn
+++ b/components/test/BUILD.gn
@@ -62,6 +62,18 @@
 }
 
 if (is_ios) {
+  bundle_data_from_filelist("custom_handlers_test_bundle_data") {
+    testonly = true
+    filelist_name = "data/custom_handlers/unit_tests_bundle_data.filelist"
+  }
+  bundle_data_from_filelist("dom_distiller_test_bundle_data") {
+    testonly = true
+    filelist_name = "data/dom_distiller/unit_tests_bundle_data.filelist"
+  }
+  bundle_data_from_filelist("fenced_frames_test_bundle_data") {
+    testonly = true
+    filelist_name = "data/fenced_frames/unit_tests_bundle_data.filelist"
+  }
   bundle_data_from_filelist("history_test_bundle_data") {
     testonly = true
     filelist_name = "data/history/unit_tests_bundle_data.filelist"
@@ -70,6 +82,14 @@
     testonly = true
     filelist_name = "data/password_manager/unit_tests_bundle_data.filelist"
   }
+  bundle_data_from_filelist("performance_manager_test_bundle_data") {
+    testonly = true
+    filelist_name = "data/performance_manager/unit_tests_bundle_data.filelist"
+  }
+  bundle_data_from_filelist("url_rewrite_test_bundle_data") {
+    testonly = true
+    filelist_name = "data/url_rewrite/unit_tests_bundle_data.filelist"
+  }
   bundle_data_from_filelist("viz_test_bundle_data") {
     testonly = true
     filelist_name = "data/viz/unit_tests_bundle_data.filelist"
diff --git a/components/test/PRESUBMIT.py b/components/test/PRESUBMIT.py
index 40d45be7..9a35089 100644
--- a/components/test/PRESUBMIT.py
+++ b/components/test/PRESUBMIT.py
@@ -20,12 +20,27 @@
         sys.path.append(input_api.change.RepositoryRoot())
         from build.ios import presubmit_support
         results += presubmit_support.CheckBundleData(
-                input_api, output_api, 'data/history/unit_tests_bundle_data')
+                input_api, output_api,
+                'data/custom_handlers/unit_tests_bundle_data')
+        results += presubmit_support.CheckBundleData(
+                input_api, output_api,
+                'data/dom_distiller/unit_tests_bundle_data')
+        results += presubmit_support.CheckBundleData(
+                input_api, output_api,
+                'data/fenced_frames/unit_tests_bundle_data')
         results += presubmit_support.CheckBundleData(
                 input_api, output_api,
                 'data/password_manager/unit_tests_bundle_data')
         results += presubmit_support.CheckBundleData(
                 input_api, output_api,
+                'data/performance_manager/unit_tests_bundle_data')
+        results += presubmit_support.CheckBundleData(
+                input_api, output_api, 'data/history/unit_tests_bundle_data')
+        results += presubmit_support.CheckBundleData(
+                input_api, output_api,
+                'data/url_rewrite/unit_tests_bundle_data')
+        results += presubmit_support.CheckBundleData(
+                input_api, output_api,
                 'data/viz/unit_tests_bundle_data')
         results += presubmit_support.CheckBundleData(
                 input_api, output_api,
diff --git a/components/test/data/custom_handlers/unit_tests_bundle_data.filelist b/components/test/data/custom_handlers/unit_tests_bundle_data.filelist
new file mode 100644
index 0000000..2aee103
--- /dev/null
+++ b/components/test/data/custom_handlers/unit_tests_bundle_data.filelist
@@ -0,0 +1,8 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# NOTE: this file is generated by build/ios/update_bundle_filelist.py
+#       If it requires updating, you should get a presubmit error with
+#       instructions on how to regenerate. Otherwise, do not edit.
+//components/test/data/custom_handlers/custom_handler.html
+//components/test/data/custom_handlers/title1.html
diff --git a/components/test/data/custom_handlers/unit_tests_bundle_data.globlist b/components/test/data/custom_handlers/unit_tests_bundle_data.globlist
new file mode 100644
index 0000000..f2c74f7
--- /dev/null
+++ b/components/test/data/custom_handlers/unit_tests_bundle_data.globlist
@@ -0,0 +1,10 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# See build/ios/update_bundle_filelist.py for details on how .globlist
+# files are used to update their .filelist counterparts.
+
+//components/test/data/custom_handlers/**
+-//components/test/data/custom_handlers/*.globlist
+-//components/test/data/custom_handlers/*.filelist
diff --git a/components/test/data/dom_distiller/unit_tests_bundle_data.filelist b/components/test/data/dom_distiller/unit_tests_bundle_data.filelist
new file mode 100644
index 0000000..2293264
--- /dev/null
+++ b/components/test/data/dom_distiller/unit_tests_bundle_data.filelist
@@ -0,0 +1,19 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# NOTE: this file is generated by build/ios/update_bundle_filelist.py
+#       If it requires updating, you should get a presubmit error with
+#       instructions on how to regenerate. Otherwise, do not edit.
+//components/test/data/dom_distiller/core_features.json
+//components/test/data/dom_distiller/derived_features.json
+//components/test/data/dom_distiller/font_size_slider_tester.js
+//components/test/data/dom_distiller/invisible_style.html
+//components/test/data/dom_distiller/markup_article.html
+//components/test/data/dom_distiller/non_og_article.html
+//components/test/data/dom_distiller/og_article.html
+//components/test/data/dom_distiller/pinch_tester.js
+//components/test/data/dom_distiller/settings_dialog_tester.js
+//components/test/data/dom_distiller/simple_article.html
+//components/test/data/dom_distiller/test_util.js
+//components/test/data/dom_distiller/video_article.html
+//components/test/data/dom_distiller/visible_style.html
diff --git a/components/test/data/dom_distiller/unit_tests_bundle_data.globlist b/components/test/data/dom_distiller/unit_tests_bundle_data.globlist
new file mode 100644
index 0000000..232300f
--- /dev/null
+++ b/components/test/data/dom_distiller/unit_tests_bundle_data.globlist
@@ -0,0 +1,14 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# See build/ios/update_bundle_filelist.py for details on how .globlist
+# files are used to update their .filelist counterparts.
+
+//components/test/data/dom_distiller/**
+-//components/test/data/dom_distiller/*.globlist
+-//components/test/data/dom_distiller/*.filelist
+-//components/test/data/dom_distiller/**DIR_METADATA
+-//components/test/data/dom_distiller/**OWNERS
+-//components/test/data/dom_distiller/**README.md
+-//components/test/data/dom_distiller/**/README
diff --git a/components/test/data/fenced_frames/unit_tests_bundle_data.filelist b/components/test/data/fenced_frames/unit_tests_bundle_data.filelist
new file mode 100644
index 0000000..aa9ff27f
--- /dev/null
+++ b/components/test/data/fenced_frames/unit_tests_bundle_data.filelist
@@ -0,0 +1,8 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# NOTE: this file is generated by build/ios/update_bundle_filelist.py
+#       If it requires updating, you should get a presubmit error with
+#       instructions on how to regenerate. Otherwise, do not edit.
+//components/test/data/fenced_frames/title1.html
+//components/test/data/fenced_frames/title1.html.mock-http-headers
diff --git a/components/test/data/fenced_frames/unit_tests_bundle_data.globlist b/components/test/data/fenced_frames/unit_tests_bundle_data.globlist
new file mode 100644
index 0000000..22e96b5
--- /dev/null
+++ b/components/test/data/fenced_frames/unit_tests_bundle_data.globlist
@@ -0,0 +1,10 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# See build/ios/update_bundle_filelist.py for details on how .globlist
+# files are used to update their .filelist counterparts.
+
+//components/test/data/fenced_frames/**
+-//components/test/data/fenced_frames/*.globlist
+-//components/test/data/fenced_frames/*.filelist
diff --git a/components/test/data/performance_manager/unit_tests_bundle_data.filelist b/components/test/data/performance_manager/unit_tests_bundle_data.filelist
new file mode 100644
index 0000000..f0850bf
--- /dev/null
+++ b/components/test/data/performance_manager/unit_tests_bundle_data.filelist
@@ -0,0 +1,11 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# NOTE: this file is generated by build/ios/update_bundle_filelist.py
+#       If it requires updating, you should get a presubmit error with
+#       instructions on how to regenerate. Otherwise, do not edit.
+//components/test/data/performance_manager/a_embeds_a.html
+//components/test/data/performance_manager/a_embeds_b.html
+//components/test/data/performance_manager/a_popup_a.html
+//components/test/data/performance_manager/a.html
+//components/test/data/performance_manager/b.html
diff --git a/components/test/data/performance_manager/unit_tests_bundle_data.globlist b/components/test/data/performance_manager/unit_tests_bundle_data.globlist
new file mode 100644
index 0000000..375bd47
--- /dev/null
+++ b/components/test/data/performance_manager/unit_tests_bundle_data.globlist
@@ -0,0 +1,12 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# See build/ios/update_bundle_filelist.py for details on how .globlist
+# files are used to update their .filelist counterparts.
+
+//components/test/data/performance_manager/**
+-//components/test/data/performance_manager/*.globlist
+-//components/test/data/performance_manager/*.filelist
+-//components/test/data/performance_manager/**OWNERS
+-//components/test/data/performance_manager/DIR_METADATA
diff --git a/components/test/data/url_rewrite/unit_tests_bundle_data.filelist b/components/test/data/url_rewrite/unit_tests_bundle_data.filelist
new file mode 100644
index 0000000..f0058fc9
--- /dev/null
+++ b/components/test/data/url_rewrite/unit_tests_bundle_data.filelist
@@ -0,0 +1,8 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# NOTE: this file is generated by build/ios/update_bundle_filelist.py
+#       If it requires updating, you should get a presubmit error with
+#       instructions on how to regenerate. Otherwise, do not edit.
+//components/test/data/url_rewrite/multiple_web_contents.html
+//components/test/data/url_rewrite/single_web_contents.html
diff --git a/components/test/data/url_rewrite/unit_tests_bundle_data.globlist b/components/test/data/url_rewrite/unit_tests_bundle_data.globlist
new file mode 100644
index 0000000..c3e12c22
--- /dev/null
+++ b/components/test/data/url_rewrite/unit_tests_bundle_data.globlist
@@ -0,0 +1,8 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# See build/ios/update_bundle_filelist.py for details on how .globlist
+# files are used to update their .filelist counterparts.
+
+//components/test/data/url_rewrite/*.html