Commit 1f298265 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Allow FeaturePromoBubbleView to be constructed directly

This will allow wider use of this class without creating trivial
subclasses.

Bug: 887991
Change-Id: I885dd5e0319b1ad3aea22b0d04c4a377f65ba358
Reviewed-on: https://chromium-review.googlesource.com/c/1294408
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602159}
parent c33179fa
...@@ -82,6 +82,16 @@ FeaturePromoBubbleView::FeaturePromoBubbleView( ...@@ -82,6 +82,16 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
FeaturePromoBubbleView::~FeaturePromoBubbleView() = default; FeaturePromoBubbleView::~FeaturePromoBubbleView() = default;
// static
FeaturePromoBubbleView* FeaturePromoBubbleView::CreateOwned(
views::View* anchor_view,
views::BubbleBorder::Arrow arrow,
int string_specifier,
ActivationAction activation_action) {
return new FeaturePromoBubbleView(anchor_view, arrow, string_specifier,
activation_action);
}
void FeaturePromoBubbleView::CloseBubble() { void FeaturePromoBubbleView::CloseBubble() {
GetWidget()->Close(); GetWidget()->Close();
} }
......
...@@ -30,6 +30,18 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView { ...@@ -30,6 +30,18 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView {
~FeaturePromoBubbleView() override; ~FeaturePromoBubbleView() override;
// Creates a promo bubble. The returned pointer is only valid until the widget
// is closed. It must not be manually deleted by the caller. |anchor_view| is
// the View this bubble is anchored to. |arrow| specifies where on the border
// the bubble's arrow is located. |string_specifier| is a string ID that can
// be passed to |l10n_util::GetStringUTF16()|. |activation_action| specifies
// whether the bubble's widget will be activated.
static FeaturePromoBubbleView* CreateOwned(
views::View* anchor_view,
views::BubbleBorder::Arrow arrow,
int string_specifier,
ActivationAction activation_action);
// Closes the promo bubble. // Closes the promo bubble.
void CloseBubble(); void CloseBubble();
......
// Copyright 2018 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/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/feature_promos/feature_promo_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/grit/generated_resources.h"
class FeaturePromoDialogTest : public DialogBrowserTest {
public:
FeaturePromoDialogTest() = default;
~FeaturePromoDialogTest() override = default;
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
auto* app_menu_button = BrowserView::GetBrowserViewForBrowser(browser())
->toolbar()
->app_menu_button();
// We use one of the strings for the new tab feature promo since there is
// currently no infrastructure for test-only string resources.
int placeholder_string = IDS_NEWTAB_PROMO_0;
FeaturePromoBubbleView::CreateOwned(
app_menu_button, views::BubbleBorder::TOP_RIGHT, placeholder_string,
FeaturePromoBubbleView::ActivationAction::ACTIVATE);
}
};
IN_PROC_BROWSER_TEST_F(FeaturePromoDialogTest, InvokeUi_FeaturePromo) {
ShowAndVerifyUi();
}
...@@ -1204,6 +1204,7 @@ test("browser_tests") { ...@@ -1204,6 +1204,7 @@ test("browser_tests") {
if (enable_desktop_in_product_help) { if (enable_desktop_in_product_help) {
sources += [ sources += [
"../browser/ui/views/feature_promos/bookmark_promo_dialog_browsertest.cc", "../browser/ui/views/feature_promos/bookmark_promo_dialog_browsertest.cc",
"../browser/ui/views/feature_promos/feature_promo_dialog_browsertest.cc",
"../browser/ui/views/feature_promos/incognito_window_promo_dialog_browsertest.cc", "../browser/ui/views/feature_promos/incognito_window_promo_dialog_browsertest.cc",
"../browser/ui/views/feature_promos/new_tab_promo_dialog_browsertest.cc", "../browser/ui/views/feature_promos/new_tab_promo_dialog_browsertest.cc",
] ]
......
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