[linux] Introduced the graceful way to shutdown at startup.

The platform may fail to initialise, but currently there is no way to
shutdown gracefully, instead platforms have to CHECK or LOG(FATAL),
which essentially crashes the browser.  This seems unnecessary because
harmless things like launching chrome with a wrong platform cause
crashes that are then reported to Crashpad.

This patch introduces the early failure path for the platforms: they can
do primary checks at the stage of initialising the UI, and return
whether they succedeed.  In case of failure, the process exits with
normal status.

Bug: 1280138
Change-Id: I176be3ba914cbdb2544478de5228476dcb3ccd21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3351790
Reviewed-by: Sergey Ulanov <[email protected]>
Reviewed-by: Bo Liu <[email protected]>
Reviewed-by: Robert Kroeger <[email protected]>
Reviewed-by: David Roger <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Commit-Queue: Alexander Dunaev <[email protected]>
Cr-Commit-Position: refs/heads/main@{#961077}
diff --git a/chrome/browser/ozone_platform_browsertest.cc b/chrome/browser/ozone_platform_browsertest.cc
new file mode 100644
index 0000000..0afdd23a
--- /dev/null
+++ b/chrome/browser/ozone_platform_browsertest.cc
@@ -0,0 +1,32 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/test/browser_test.h"
+#include "ui/ozone/public/ozone_platform.h"
+
+namespace ui {
+
+// Configures the ozone platform so it would return an error early at the stage
+// of initialisation.  In such event, the browser should gracefully exit.
+// See https://crbug.com/1280138.
+class OzonePlatformTest : public InProcessBrowserTest {
+ public:
+  OzonePlatformTest() {
+    OzonePlatform::SetFailInitializeUIForTest(true);
+    set_expected_exit_code(1);
+  }
+
+  ~OzonePlatformTest() override {
+    OzonePlatform::SetFailInitializeUIForTest(false);
+  }
+};
+
+IN_PROC_BROWSER_TEST_F(OzonePlatformTest, ExitsGracefullyOnPlatormInitFailure) {
+  // This should never be hit.  The browser is expected to exit before entering
+  // the test body.
+  ASSERT_TRUE(false);
+}
+
+}  // namespace ui