Commit 444dfe7a authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Add method to get the FeaturePromoControllerViews for a View

Bug: 1133016
Change-Id: Ia40222beff775014959a6b52ce25ef36893d713d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503816Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821502}
parent 20f8763e
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/ui/views/in_product_help/feature_promo_registry.h" #include "chrome/browser/ui/views/in_product_help/feature_promo_registry.h"
#include "components/feature_engagement/public/feature_constants.h" #include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h" #include "components/feature_engagement/public/tracker.h"
#include "ui/views/view.h"
FeaturePromoControllerViews::FeaturePromoControllerViews( FeaturePromoControllerViews::FeaturePromoControllerViews(
BrowserView* browser_view) BrowserView* browser_view)
...@@ -43,6 +44,21 @@ FeaturePromoControllerViews::~FeaturePromoControllerViews() { ...@@ -43,6 +44,21 @@ FeaturePromoControllerViews::~FeaturePromoControllerViews() {
promo_bubble_->GetWidget()->Close(); promo_bubble_->GetWidget()->Close();
} }
// static
FeaturePromoControllerViews* FeaturePromoControllerViews::GetForView(
views::View* view) {
views::Widget* widget = view->GetWidget();
if (!widget)
return nullptr;
BrowserView* browser_view =
BrowserView::GetBrowserViewForNativeWindow(widget->GetNativeWindow());
if (!browser_view)
return nullptr;
return browser_view->feature_promo_controller();
}
bool FeaturePromoControllerViews::MaybeShowPromoWithParams( bool FeaturePromoControllerViews::MaybeShowPromoWithParams(
const base::Feature& iph_feature, const base::Feature& iph_feature,
const FeaturePromoBubbleParams& params) { const FeaturePromoBubbleParams& params) {
......
...@@ -39,6 +39,11 @@ class FeaturePromoControllerViews : public FeaturePromoController, ...@@ -39,6 +39,11 @@ class FeaturePromoControllerViews : public FeaturePromoController,
explicit FeaturePromoControllerViews(BrowserView* browser_view); explicit FeaturePromoControllerViews(BrowserView* browser_view);
~FeaturePromoControllerViews() override; ~FeaturePromoControllerViews() override;
// Get the appropriate instance for |view|. This finds the BrowserView
// that contains |view| and returns its instance. May return nullptr,
// but if |view| is in a BrowserView's hierarchy it shouldn't.
static FeaturePromoControllerViews* GetForView(views::View* view);
// Repositions the bubble (if showing) relative to the anchor view. // Repositions the bubble (if showing) relative to the anchor view.
// This should be called whenever the anchor view is potentially // This should be called whenever the anchor view is potentially
// moved. It is safe to call this if a bubble is not showing. // moved. It is safe to call this if a bubble is not showing.
......
...@@ -99,6 +99,15 @@ class FeaturePromoControllerViewsTest : public TestWithBrowserView { ...@@ -99,6 +99,15 @@ class FeaturePromoControllerViewsTest : public TestWithBrowserView {
} }
}; };
TEST_F(FeaturePromoControllerViewsTest, GetForView) {
EXPECT_EQ(controller_,
FeaturePromoControllerViews::GetForView(GetAnchorView()));
// For a view not in the BrowserView's hierarchy, it should return null.
views::View orphan_view;
EXPECT_EQ(nullptr, FeaturePromoControllerViews::GetForView(&orphan_view));
}
TEST_F(FeaturePromoControllerViewsTest, AsksBackendToShowPromo) { TEST_F(FeaturePromoControllerViewsTest, AsksBackendToShowPromo) {
EXPECT_CALL(*mock_tracker_, ShouldTriggerHelpUI(Ref(kTestIPHFeature))) EXPECT_CALL(*mock_tracker_, ShouldTriggerHelpUI(Ref(kTestIPHFeature)))
.Times(1) .Times(1)
......
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