ios: Enable (and test!) more of util and test

This builds some code in the util and test libraries on iOS that was
previously excluded. It also enables tests for this code, and other
tests that it was possible to enable either previously or as a result of
this change.

Previously, crashpad_util_test ran 178 tests from 46 test suites, and
crashpad_test_test ran 2 tests from 2 test suites. Now,
crashpad_util_test runs 284 tests from 62 test suites, and
crashpad_test_test runs 6 tests from 4 test suites.

The related .gn files also suffered through a slight cleanup.

Bug: crashpad:31
Change-Id: I94b5d2507d746022b2d3d18d11f2cdecdd1c6c22
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2154526
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
GitOrigin-RevId: 122a400d7b585194b557c89d4afb859c25e916de
diff --git a/test/BUILD.gn b/test/BUILD.gn
index bfbdd51..32dc298 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -43,29 +43,6 @@
     "test_paths.h",
   ]
 
-  if (crashpad_is_ios) {
-    sources -= [
-      "errors.cc",
-      "errors.h",
-      "file.cc",
-      "file.h",
-      "filesystem.cc",
-      "filesystem.h",
-      "multiprocess.h",
-      "multiprocess_exec.cc",
-      "multiprocess_exec.h",
-      "process_type.cc",
-      "process_type.h",
-      "scoped_guarded_page.h",
-      "scoped_module_handle.cc",
-      "scoped_module_handle.h",
-      "scoped_temp_dir.cc",
-      "scoped_temp_dir.h",
-      "test_paths.cc",
-      "test_paths.h",
-    ]
-  }
-
   if (crashpad_is_posix || crashpad_is_fuchsia) {
     sources += [
       "scoped_guarded_page_posix.cc",
@@ -93,6 +70,14 @@
     ]
   }
 
+  if (crashpad_is_ios) {
+    sources -= [
+      "multiprocess.h",
+      "multiprocess_exec.cc",
+      "multiprocess_exec.h",
+    ]
+  }
+
   if (crashpad_is_linux || crashpad_is_android) {
     set_sources_assignment_filter([])
     sources += [
@@ -139,13 +124,6 @@
     "../util",
   ]
 
-  if (crashpad_is_ios) {
-    deps -= [
-      "../compat",
-      "../util",
-    ]
-  }
-
   if (crashpad_is_mac) {
     libs = [ "bsm" ]
     deps += [
@@ -154,6 +132,10 @@
     ]
   }
 
+  if (crashpad_is_ios) {
+    deps += [ ":test_bundle_data" ]
+  }
+
   if (crashpad_is_win) {
     libs = [ "shell32.lib" ]
   }
@@ -166,6 +148,17 @@
   }
 }
 
+if (crashpad_is_ios) {
+  bundle_data("test_bundle_data") {
+    testonly = true
+
+    sources = [ "test_paths_test_data_root.txt" ]
+
+    outputs = [ "{{bundle_resources_dir}}/crashpad_test_data/" +
+                "{{source_root_relative_dir}}/{{source_file_part}}" ]
+  }
+}
+
 source_set("test_test") {
   testonly = true
 
@@ -178,15 +171,6 @@
     "test_paths_test.cc",
   ]
 
-  if (crashpad_is_ios) {
-    sources -= [
-      "multiprocess_exec_test.cc",
-      "scoped_guarded_page_test.cc",
-      "scoped_temp_dir_test.cc",
-      "test_paths_test.cc",
-    ]
-  }
-
   # TODO(crbug.com/812974): Remove !crashpad_is_fuchsia when Fuchsia is no
   # longer treated as a posix platform.
   if (crashpad_is_posix && !crashpad_is_fuchsia && !crashpad_is_ios) {
@@ -197,6 +181,13 @@
     sources += [ "mac/mach_multiprocess_test.cc" ]
   }
 
+  if (crashpad_is_ios) {
+    sources -= [
+      "multiprocess_exec_test.cc",
+      "scoped_guarded_page_test.cc",
+    ]
+  }
+
   if (crashpad_is_win) {
     sources += [
       "win/win_child_process_test.cc",
@@ -216,11 +207,6 @@
   data_deps = [ ":crashpad_test_test_multiprocess_exec_test_child" ]
 
   if (crashpad_is_ios) {
-    deps -= [
-      "../compat",
-      "../util",
-    ]
-
     data_deps -= [ ":crashpad_test_test_multiprocess_exec_test_child" ]
   }
 }
diff --git a/test/test_paths.cc b/test/test_paths.cc
index dfe6c96..475e2b0 100644
--- a/test/test_paths.cc
+++ b/test/test_paths.cc
@@ -46,7 +46,7 @@
 #if defined(OS_FUCHSIA)
   base::FilePath asset_path("/pkg/data");
   if (!IsTestDataRoot(asset_path)) {
-    LOG(WARNING) << "Test data root seems invalid, continuing anyway";
+    LOG(WARNING) << "test data root seems invalid, continuing anyway";
   }
   return asset_path;
 #else  // defined(OS_FUCHSIA)
@@ -65,19 +65,23 @@
     return base::FilePath(environment_value);
   }
 
-  // In a standalone build, the test executable is usually at
-  // out/{Debug,Release} relative to the Crashpad root.
   base::FilePath executable_path;
   if (Paths::Executable(&executable_path)) {
-#if defined(OS_ANDROID)
+#if defined(OS_IOS) || defined(OS_ANDROID)
+    // On Android and iOS, test data is in a crashpad_test_data directory
+    // adjacent to the main executable. On iOS, this refers to the main
+    // executable file inside the .app bundle, so crashpad_test_data is also
+    // inside the bundle.
     base::FilePath candidate = executable_path.DirName()
                                .Append("crashpad_test_data");
-#else
+#else  // OS_IOS || OS_ANDRID
+    // In a standalone build, the test executable is usually at
+    // out/{Debug,Release} relative to the Crashpad root.
     base::FilePath candidate =
         base::FilePath(executable_path.DirName()
                            .Append(base::FilePath::kParentDirectory)
                            .Append(base::FilePath::kParentDirectory));
-#endif
+#endif  // OS_IOS || OS_ANDROID
     if (IsTestDataRoot(candidate)) {
       return candidate;
     }
diff --git a/util/BUILD.gn b/util/BUILD.gn
index 183a0a8..7fe02f2 100644
--- a/util/BUILD.gn
+++ b/util/BUILD.gn
@@ -244,14 +244,13 @@
     }
   }
 
-  if (crashpad_is_ios) {
+  if (crashpad_is_mac || crashpad_is_ios) {
     sources += [
-      "ios/exception_processor.h",
-      "ios/exception_processor.mm",
-      "ios/ios_system_data_collector.h",
-      "ios/ios_system_data_collector.mm",
       "mac/xattr.cc",
       "mac/xattr.h",
+      "misc/clock_mac.cc",
+      "misc/paths_mac.cc",
+      "synchronization/semaphore_mac.cc",
     ]
   }
 
@@ -264,8 +263,6 @@
       "mac/mac_util.h",
       "mac/service_management.cc",
       "mac/service_management.h",
-      "mac/xattr.cc",
-      "mac/xattr.h",
       "mach/child_port_handshake.cc",
       "mach/child_port_handshake.h",
       "mach/child_port_server.cc",
@@ -298,13 +295,19 @@
       "mach/task_for_pid.cc",
       "mach/task_for_pid.h",
       "misc/capture_context_mac.S",
-      "misc/clock_mac.cc",
-      "misc/paths_mac.cc",
       "net/http_transport_mac.mm",
       "posix/process_info_mac.cc",
       "process/process_memory_mac.cc",
       "process/process_memory_mac.h",
-      "synchronization/semaphore_mac.cc",
+    ]
+  }
+
+  if (crashpad_is_ios) {
+    sources += [
+      "ios/exception_processor.h",
+      "ios/exception_processor.mm",
+      "ios/ios_system_data_collector.h",
+      "ios/ios_system_data_collector.mm",
     ]
   }
 
@@ -655,12 +658,15 @@
     sources += [ "posix/scoped_mmap_test.cc" ]
   }
 
+  if (crashpad_is_mac || crashpad_is_ios) {
+    sources += [ "mac/xattr_test.cc" ]
+  }
+
   if (crashpad_is_mac) {
     sources += [
       "mac/launchd_test.mm",
       "mac/mac_util_test.mm",
       "mac/service_management_test.mm",
-      "mac/xattr_test.cc",
       "mach/child_port_handshake_test.cc",
       "mach/child_port_server_test.cc",
       "mach/composite_mach_message_server_test.cc",
@@ -684,20 +690,9 @@
     sources += [ "ios/exception_processor_test.mm" ]
 
     sources -= [
-      "file/directory_reader_test.cc",
-      "file/file_io_test.cc",
-      "file/filesystem_test.cc",
       "misc/capture_context_test.cc",
-      "misc/clock_test.cc",
-      "misc/paths_test.cc",
-      "net/http_body_test.cc",
-      "net/http_multipart_builder_test.cc",
       "process/process_memory_range_test.cc",
       "process/process_memory_test.cc",
-      "stream/file_encoder_test.cc",
-      "synchronization/semaphore_test.cc",
-      "thread/thread_test.cc",
-      "thread/worker_thread_test.cc",
     ]
   }
 
@@ -743,7 +738,12 @@
     }
   }
 
-  data = [ "net/testdata/" ]
+  data = [
+    "net/testdata/ascii_http_body.txt",
+    "net/testdata/binary_http_body.dat",
+    "net/testdata/crashpad_util_test_cert.pem",
+    "net/testdata/crashpad_util_test_key.pem",
+  ]
 
   deps = [
     ":util",
@@ -756,10 +756,6 @@
     "../third_party/zlib",
   ]
 
-  if (crashpad_is_android || crashpad_is_linux) {
-    deps += [ "../third_party/lss" ]
-  }
-
   if (!crashpad_is_android && !crashpad_is_ios) {
     data_deps = [ ":http_transport_test_server" ]
 
@@ -772,6 +768,14 @@
     libs = [ "Foundation.framework" ]
   }
 
+  if (crashpad_is_ios) {
+    deps += [ ":util_test_bundle_data" ]
+  }
+
+  if (crashpad_is_android || crashpad_is_linux) {
+    deps += [ "../third_party/lss" ]
+  }
+
   if (crashpad_is_win) {
     libs = [
       "rpcrt4.lib",
@@ -785,6 +789,20 @@
   }
 }
 
+if (crashpad_is_ios) {
+  bundle_data("util_test_bundle_data") {
+    testonly = true
+
+    sources = [
+      "net/testdata/ascii_http_body.txt",
+      "net/testdata/binary_http_body.dat",
+    ]
+
+    outputs = [ "{{bundle_resources_dir}}/crashpad_test_data/" +
+                "{{source_root_relative_dir}}/{{source_file_part}}" ]
+  }
+}
+
 if (crashpad_is_win) {
   crashpad_executable("crashpad_util_test_process_info_test_child") {
     testonly = true