Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Unified Diff: chrome/browser/ui/views/first_run_bubble_unittest.cc

Issue 1443253004: Fix a regression caused by my change to make the first run bubble window display as an inactive win… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/first_run_bubble_unittest.cc
diff --git a/chrome/browser/ui/views/first_run_bubble_unittest.cc b/chrome/browser/ui/views/first_run_bubble_unittest.cc
index 9fe90ebc67b5dbe4f4dbea37e12539e6508e73c6..010a7026016574844fea3d9a33d9b0b24a97e06c 100644
--- a/chrome/browser/ui/views/first_run_bubble_unittest.cc
+++ b/chrome/browser/ui/views/first_run_bubble_unittest.cc
@@ -13,10 +13,44 @@
#include "ui/aura/window_tree_host.h"
#include "ui/events/event.h"
#include "ui/events/event_processor.h"
+#include "ui/events/event_utils.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
+// Provides functionality to observe the widget passed in the constructor for
+// the widget closing event.
+class WidgetClosingObserver : public views::WidgetObserver {
+ public:
+ explicit WidgetClosingObserver(views::Widget* widget)
+ : widget_(widget),
+ widget_destroyed_(false) {
+ widget_->AddObserver(this);
+ }
+
+ ~WidgetClosingObserver() override {
+ if (widget_)
+ widget_->RemoveObserver(this);
+ }
+
+ void OnWidgetClosing(views::Widget* widget) override {
+ DCHECK(widget == widget_);
+ widget_->RemoveObserver(this);
+ widget_destroyed_ = true;
+ widget_ = nullptr;
+ }
+
+ bool widget_destroyed() const {
+ return widget_destroyed_;
+ }
+
+ private:
+ views::Widget* widget_;
+ bool widget_destroyed_;
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetClosingObserver);
+};
+
class FirstRunBubbleTest : public views::ViewsTestBase,
views::WidgetObserver {
public:
@@ -27,6 +61,8 @@ class FirstRunBubbleTest : public views::ViewsTestBase,
void SetUp() override;
void TearDown() override;
+ void CreateAndCloseBubbleOnEventTest(ui::Event* event);
+
protected:
TestingProfile* profile() { return profile_.get(); }
@@ -56,57 +92,35 @@ void FirstRunBubbleTest::TearDown() {
TestingBrowserProcess::DeleteInstance();
}
-// Provides functionality to observe the widget passed in the constructor for
-// the widget closing event.
-class WidgetClosingObserver : public views::WidgetObserver {
- public:
- WidgetClosingObserver(views::Widget* widget)
- : widget_(widget),
- widget_destroyed_(false) {
- widget_->AddObserver(this);
- }
-
- ~WidgetClosingObserver() override {
- if (widget_)
- widget_->RemoveObserver(this);
- }
-
- void OnWidgetClosing(views::Widget* widget) override {
- DCHECK(widget == widget_);
- widget_->RemoveObserver(this);
- widget_destroyed_ = true;
- widget_ = nullptr;
- }
-
- bool widget_destroyed() const {
- return widget_destroyed_;
- }
-
- private:
- views::Widget* widget_;
- bool widget_destroyed_;
-
- DISALLOW_COPY_AND_ASSIGN(WidgetClosingObserver);
-};
-
-TEST_F(FirstRunBubbleTest, CreateAndClose) {
+void FirstRunBubbleTest::CreateAndCloseBubbleOnEventTest(ui::Event* event) {
// Create the anchor and parent widgets.
views::Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
scoped_ptr<views::Widget> anchor_widget(new views::Widget);
anchor_widget->Init(params);
+ anchor_widget->SetBounds(gfx::Rect(10, 10, 500, 500));
anchor_widget->Show();
FirstRunBubble* delegate =
FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView());
EXPECT_TRUE(delegate != NULL);
- delegate->GetWidget()->CloseNow();
+
+ anchor_widget->GetFocusManager()->SetFocusedView(
+ anchor_widget->GetContentsView());
+
+ scoped_ptr<WidgetClosingObserver> widget_observer(
+ new WidgetClosingObserver(delegate->GetWidget()));
+
+ ui::EventDispatchDetails details =
+ anchor_widget->GetNativeWindow()->GetHost()->event_processor()->
+ OnEventFromSource(event);
+ EXPECT_FALSE(details.dispatcher_destroyed);
+
+ EXPECT_TRUE(widget_observer->widget_destroyed());
}
-// Tests that the first run bubble is closed when keyboard events are
-// dispatched to the anchor widget.
-TEST_F(FirstRunBubbleTest, CloseBubbleOnKeyEvent) {
+TEST_F(FirstRunBubbleTest, CreateAndClose) {
// Create the anchor and parent widgets.
views::Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
@@ -118,19 +132,27 @@ TEST_F(FirstRunBubbleTest, CloseBubbleOnKeyEvent) {
FirstRunBubble* delegate =
FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView());
EXPECT_TRUE(delegate != NULL);
+ delegate->GetWidget()->CloseNow();
+}
- anchor_widget->GetFocusManager()->SetFocusedView(
- anchor_widget->GetContentsView());
-
- scoped_ptr<WidgetClosingObserver> widget_observer(
- new WidgetClosingObserver(delegate->GetWidget()));
-
+// Tests that the first run bubble is closed when keyboard events are
+// dispatched to the anchor widget.
+TEST_F(FirstRunBubbleTest, CloseBubbleOnKeyEvent) {
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
+ CreateAndCloseBubbleOnEventTest(&key_event);
+}
- ui::EventDispatchDetails details =
- anchor_widget->GetNativeWindow()->GetHost()->event_processor()->
- OnEventFromSource(&key_event);
- EXPECT_FALSE(details.dispatcher_destroyed);
+TEST_F(FirstRunBubbleTest, CloseBubbleOnMouseDownEvent) {
+ gfx::Point pt(110, 210);
+ ui::MouseEvent mouse_down(
+ ui::ET_MOUSE_PRESSED, pt, pt, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
+ CreateAndCloseBubbleOnEventTest(&mouse_down);
+}
- EXPECT_TRUE(widget_observer->widget_destroyed());
+TEST_F(FirstRunBubbleTest, CloseBubbleOnTouchDownEvent) {
+ ui::TouchEvent touch_down(
+ ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, ui::EventTimeForNow());
+ CreateAndCloseBubbleOnEventTest(&touch_down);
}
+
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698