[headless] Let screen properties change to propagate with no NSWindow

https://crrev.com/c/5949433 added screen orientation handling to
headless shell, however, the related tests fail on Macs due to
the check for the enclosing NSWindow to exist preventing screen
properties change to be passed to the upper layers.

This CL removes the excessively aggressive check allowing screen
properties change to be handled normally when running headless
in which case enclosing NSWindow never exists.

Bug: 375425824
Change-Id: I44392e2536a6a7122b5574bac068ebef2b210fc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5967373
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1375988}
diff --git a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
index f7ead5e4..a8658f07 100644
--- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
+++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
@@ -1657,12 +1657,10 @@
 }
 
 - (void)updateScreenProperties {
-  NSWindow* enclosingWindow = [self window];
-  if (!enclosingWindow)
-    return;
-
-  // TODO(ccameron): This will call [enclosingWindow screen], which may return
-  // nil. Do that call here to avoid sending bogus display info to the host.
+  // This does not require enclosing window to exist, and allowing screen
+  // properties change to propagate when it does not ensures that screen infos
+  // are properly updated when running headless.
+  // See // https://crbug.com/375425824.
   auto* screen = display::Screen::GetScreen();
   const display::ScreenInfos newScreenInfos =
       screen->GetScreenInfosNearestDisplay(
@@ -2444,7 +2442,11 @@
   // as they have not been updated while unattached to a window.
   [self sendWindowFrameInScreenToHost];
   [self sendViewBoundsInWindowToHost];
-  [self updateScreenProperties];
+
+  if ([self window]) {
+    [self updateScreenProperties];
+  }
+
   _host->OnWindowIsKeyChanged([[self window] isKeyWindow]);
   _host->OnFirstResponderChanged([[self window] firstResponder] == self);
 
diff --git a/headless/test/headless_protocol_browsertest.cc b/headless/test/headless_protocol_browsertest.cc
index 049a1fc8..a711c99 100644
--- a/headless/test/headless_protocol_browsertest.cc
+++ b/headless/test/headless_protocol_browsertest.cc
@@ -344,13 +344,7 @@
 
 HEADLESS_PROTOCOL_TEST(GrantPermissions, "sanity/grant_permissions.js")
 
-// https://crbug.com/375425824
-#if BUILDFLAG(IS_MAC)
-#define MAYBE_ScreenOrientationLock DISABLED_ScreenOrientationLock
-#else
-#define MAYBE_ScreenOrientationLock ScreenOrientationLock
-#endif
-HEADLESS_PROTOCOL_TEST(MAYBE_ScreenOrientationLock,
+HEADLESS_PROTOCOL_TEST(ScreenOrientationLock,
                        "sanity/screen_orientation_lock.js")
 
 #if !defined(HEADLESS_USE_EMBEDDED_RESOURCES)