From 4f45215b14dafd14f1b6f9f4a8ecf85fc66b3fec Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Mon, 19 Dec 2022 09:26:33 +0000 Subject: [PATCH] CrOSSharingHub: Run Lacros browser test with Ash The Lacros test SharingHubBubbleControllerChromeOsBrowserTest now runs as part of lacros_chrome_browsertests_run_in_series. The test waits for the bubble to be shown and closed. Previously, the tests were being skipped as Ash was not running. Bug: 1300325 Change-Id: I095f415c14d0bed46dbd72cb8a92e9726eaa3727 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4111483 Reviewed-by: Travis Skare Commit-Queue: Eric Willigers Cr-Commit-Position: refs/heads/main@{#1084874} --- ..._controller_chromeos_lacros_browsertest.cc | 40 ++++++++++++++----- chrome/test/BUILD.gn | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/chrome/browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc b/chrome/browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc index 9878a2f86b221..08c0d5a40f0c3 100644 --- a/chrome/browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc +++ b/chrome/browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include +#include + +#include "base/one_shot_event.h" +#include "base/run_loop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/lacros/window_utility.h" #include "chrome/browser/ui/page_action/page_action_icon_type.h" @@ -26,28 +31,45 @@ class FakeSharesheet : public crosapi::mojom::Sharesheet { FakeSharesheet& operator=(const FakeSharesheet&) = delete; ~FakeSharesheet() override = default; + void AwaitShow() { + base::RunLoop run_loop; + show_bubble_called_.Post(FROM_HERE, run_loop.QuitClosure()); + run_loop.Run(); + } + + void AwaitClose() { + base::RunLoop run_loop; + close_bubble_called_.Post(FROM_HERE, run_loop.QuitClosure()); + run_loop.Run(); + } + private: // crosapi::mojom::Sharesheet: void ShowBubble( const std::string& window_id, sharesheet::LaunchSource source, crosapi::mojom::IntentPtr intent, - crosapi::mojom::Sharesheet::ShowBubbleCallback callback) override {} + crosapi::mojom::Sharesheet::ShowBubbleCallback callback) override { + NOTREACHED(); + } void ShowBubbleWithOnClosed( const std::string& window_id, sharesheet::LaunchSource source, crosapi::mojom::IntentPtr intent, crosapi::mojom::Sharesheet::ShowBubbleWithOnClosedCallback callback) override { - show_bubble_called = true; + show_bubble_called_.Signal(); + callback_ = std::move(callback); } void CloseBubble(const std::string& window_id) override { - close_bubble_called = true; + close_bubble_called_.Signal(); + std::move(callback_).Run(); } public: - bool show_bubble_called = false; - bool close_bubble_called = false; + base::OneShotEvent show_bubble_called_; + base::OneShotEvent close_bubble_called_; + crosapi::mojom::Sharesheet::ShowBubbleWithOnClosedCallback callback_; }; class SharingHubBubbleControllerChromeOsBrowserTest @@ -96,16 +118,16 @@ IN_PROC_BROWSER_TEST_F(SharingHubBubbleControllerChromeOsBrowserTest, CreateOrGetFromWebContents(web_contents) ->ShowBubble(share::ShareAttempt(web_contents)); - // Verify that the sharesheet was opened. - EXPECT_TRUE(service_.show_bubble_called); + // Verify that the sharesheet is opened. + service_.AwaitShow(); // Close the sharesheet using the sharing hub controller. sharing_hub::SharingHubBubbleControllerChromeOsImpl:: CreateOrGetFromWebContents(web_contents) ->HideBubble(); - // Verify that the sharesheet was closed. - EXPECT_TRUE(service_.close_bubble_called); + // Verify that the sharesheet is closed. + service_.AwaitClose(); } } // namespace diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index 6692434b0cfa9..3c0676a299cf6 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -2759,7 +2759,6 @@ if (!is_android) { "../browser/lacros/lacros_extension_apps_controller_browsertest.cc", "../browser/lacros/lacros_extension_apps_publisher_browsertest.cc", "../browser/policy/restricted_mgs_policy_provider_lacros_browsertest.cc", - "../browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc", "../browser/web_applications/app_service/lacros_web_apps_controller_browsertest.cc", ] deps += [ @@ -4921,6 +4920,7 @@ if (is_chromeos_lacros) { "../browser/ui/browser_navigator_browsertest.cc", "../browser/ui/browser_navigator_browsertest.h", "../browser/ui/browser_navigator_browsertest_chromeos.cc", + "../browser/ui/sharing_hub/sharing_hub_bubble_controller_chromeos_lacros_browsertest.cc", "../browser/ui/startup/first_run_service_browsertest.cc", "../browser/ui/views/intent_picker_bubble_view_browsertest.cc", "../browser/ui/views/location_bar/intent_chip_button_browsertest.cc",