Commit bb38d021 authored by Melissa Zhang's avatar Melissa Zhang Committed by Commit Bot

[Sharesheet] Update browser tests.

This CL updates browser tests to accommodate for motion when
the |sharesheet_bubble_view| appears and disappears.

Bug: 1148692
Change-Id: I5ca2eafc2bc5bc2392657d21c39998e532b1a7f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543529
Auto-Submit: Melissa Zhang <melzhang@chromium.org>
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828094}
parent f9ad6770
...@@ -4,26 +4,28 @@ ...@@ -4,26 +4,28 @@
#include "chrome/browser/ui/views/sharesheet/sharesheet_bubble_view.h" #include "chrome/browser/ui/views/sharesheet/sharesheet_bubble_view.h"
#include <string> #include <algorithm>
#include "ash/shell.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_features.h" #include "chrome/browser/nearby_sharing/common/nearby_share_features.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharesheet/sharesheet_service.h" #include "chrome/browser/sharesheet/sharesheet_service.h"
#include "chrome/browser/sharesheet/sharesheet_service_factory.h" #include "chrome/browser/sharesheet/sharesheet_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h" #include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/intent_test_util.h" #include "components/services/app_service/public/cpp/intent_test_util.h"
#include "components/services/app_service/public/cpp/intent_util.h" #include "components/services/app_service/public/cpp/intent_util.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "ui/aura/window.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
class SharesheetBubbleViewBrowserTest class SharesheetBubbleViewBrowserTest
: public ::testing::WithParamInterface<bool>, : public ::testing::WithParamInterface<bool>,
public DialogBrowserTest { public InProcessBrowserTest {
public: public:
SharesheetBubbleViewBrowserTest() { SharesheetBubbleViewBrowserTest() {
if (GetParam()) { if (GetParam()) {
...@@ -33,21 +35,39 @@ class SharesheetBubbleViewBrowserTest ...@@ -33,21 +35,39 @@ class SharesheetBubbleViewBrowserTest
} }
} }
// DialogBrowserTest: void ShowUi() {
void ShowUi(const std::string& name) override { views::Widget::Widgets old_widgets;
for (aura::Window* root_window : ash::Shell::GetAllRootWindows())
views::Widget::GetAllChildWidgets(root_window, &old_widgets);
sharesheet::SharesheetService* const sharesheet_service = sharesheet::SharesheetService* const sharesheet_service =
sharesheet::SharesheetServiceFactory::GetForProfile( sharesheet::SharesheetServiceFactory::GetForProfile(
browser()->profile()); browser()->profile());
GURL test_url = GURL("https://www.google.com/"); GURL test_url = GURL("https://www.google.com/");
auto intent = apps_util::CreateIntentFromUrl(test_url); auto intent = apps_util::CreateIntentFromUrl(test_url);
intent->action = apps_util::kIntentActionSend; intent->action = apps_util::kIntentActionSend;
sharesheet_service->ShowBubble( sharesheet_service->ShowBubble(
browser()->tab_strip_model()->GetActiveWebContents(), std::move(intent), browser()->tab_strip_model()->GetActiveWebContents(), std::move(intent),
base::DoNothing()); base::DoNothing());
views::Widget::Widgets new_widgets;
for (aura::Window* root_window : ash::Shell::GetAllRootWindows())
views::Widget::GetAllChildWidgets(root_window, &new_widgets);
views::Widget::Widgets added_widgets;
std::set_difference(new_widgets.begin(), new_widgets.end(),
old_widgets.begin(), old_widgets.end(),
std::inserter(added_widgets, added_widgets.begin()));
ASSERT_EQ(added_widgets.size(), 1u);
sharesheet_widget_ = *added_widgets.begin();
} }
bool VerifyUi() { return sharesheet_widget_->IsVisible(); }
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
views::Widget* sharesheet_widget_;
}; };
INSTANTIATE_TEST_SUITE_P(All, INSTANTIATE_TEST_SUITE_P(All,
...@@ -55,5 +75,6 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -55,5 +75,6 @@ INSTANTIATE_TEST_SUITE_P(All,
::testing::Bool()); ::testing::Bool());
IN_PROC_BROWSER_TEST_P(SharesheetBubbleViewBrowserTest, InvokeUi_Default) { IN_PROC_BROWSER_TEST_P(SharesheetBubbleViewBrowserTest, InvokeUi_Default) {
ShowAndVerifyUi(); ShowUi();
ASSERT_TRUE(VerifyUi());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment