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

Side by Side Diff: ui/views/bubble/bubble_delegate_unittest.cc

Issue 1455313002: [Reland][Extensions] Don't count bubble focus loss as acknowledgment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master 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 unified diff | Download patch
« no previous file with comments | « ui/views/bubble/bubble_delegate.cc ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/hit_test.h" 5 #include "ui/base/hit_test.h"
6 #include "ui/events/event_utils.h"
6 #include "ui/views/bubble/bubble_delegate.h" 7 #include "ui/views/bubble/bubble_delegate.h"
7 #include "ui/views/bubble/bubble_frame_view.h" 8 #include "ui/views/bubble/bubble_frame_view.h"
9 #include "ui/views/controls/button/label_button.h"
8 #include "ui/views/test/test_widget_observer.h" 10 #include "ui/views/test/test_widget_observer.h"
9 #include "ui/views/test/views_test_base.h" 11 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget.h" 12 #include "ui/views/widget/widget.h"
11 #include "ui/views/widget/widget_observer.h" 13 #include "ui/views/widget/widget_observer.h"
12 14
13 namespace views { 15 namespace views {
14 16
15 namespace { 17 namespace {
16 18
17 class TestBubbleDelegateView : public BubbleDelegateView { 19 class TestBubbleDelegateView : public BubbleDelegateView {
(...skipping 11 matching lines...) Expand all
29 } 31 }
30 32
31 void SetAnchorViewForTest(View* view) { 33 void SetAnchorViewForTest(View* view) {
32 SetAnchorView(view); 34 SetAnchorView(view);
33 } 35 }
34 36
35 // BubbleDelegateView overrides: 37 // BubbleDelegateView overrides:
36 View* GetInitiallyFocusedView() override { return view_; } 38 View* GetInitiallyFocusedView() override { return view_; }
37 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } 39 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
38 40
41 BubbleFrameView* GetBubbleFrameViewForTest() const {
42 return GetBubbleFrameView();
43 }
44
39 private: 45 private:
40 View* view_; 46 View* view_;
41 47
42 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); 48 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView);
43 }; 49 };
44 50
45 class BubbleDelegateTest : public ViewsTestBase { 51 class BubbleDelegateTest : public ViewsTestBase {
46 public: 52 public:
47 BubbleDelegateTest() {} 53 BubbleDelegateTest() {}
48 ~BubbleDelegateTest() override {} 54 ~BubbleDelegateTest() override {}
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 TEST_F(BubbleDelegateTest, NotActivatable) { 260 TEST_F(BubbleDelegateTest, NotActivatable) {
255 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); 261 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
256 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( 262 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
257 anchor_widget->GetContentsView(), BubbleBorder::NONE); 263 anchor_widget->GetContentsView(), BubbleBorder::NONE);
258 bubble_delegate->set_can_activate(false); 264 bubble_delegate->set_can_activate(false);
259 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 265 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
260 bubble_widget->Show(); 266 bubble_widget->Show();
261 EXPECT_FALSE(bubble_widget->CanActivate()); 267 EXPECT_FALSE(bubble_widget->CanActivate());
262 } 268 }
263 269
270 TEST_F(BubbleDelegateTest, CloseReasons) {
271 {
272 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
273 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
274 anchor_widget->GetContentsView(), BubbleBorder::NONE);
275 bubble_delegate->set_close_on_deactivate(true);
276 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
277 bubble_widget->Show();
278 anchor_widget->Activate();
279 EXPECT_TRUE(bubble_widget->IsClosed());
280 EXPECT_EQ(BubbleDelegateView::CloseReason::DEACTIVATION,
281 bubble_delegate->close_reason());
282 }
283
284 {
285 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
286 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
287 anchor_widget->GetContentsView(), BubbleBorder::NONE);
288 bubble_delegate->set_close_on_esc(true);
289 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
290 bubble_widget->Show();
291 // Cast as a test hack to access AcceleratorPressed() (which is protected
292 // in BubbleDelegate).
293 static_cast<View*>(bubble_delegate)
294 ->AcceleratorPressed(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
295 EXPECT_TRUE(bubble_widget->IsClosed());
296 EXPECT_EQ(BubbleDelegateView::CloseReason::ESCAPE,
297 bubble_delegate->close_reason());
298 }
299
300 {
301 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
302 TestBubbleDelegateView* bubble_delegate =
303 new TestBubbleDelegateView(anchor_widget->GetContentsView());
304 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
305 bubble_widget->Show();
306 BubbleFrameView* frame_view = bubble_delegate->GetBubbleFrameViewForTest();
307 LabelButton* close_button = frame_view->close_;
308 ASSERT_TRUE(close_button);
309 frame_view->ButtonPressed(
310 close_button,
311 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0),
312 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
313 EXPECT_TRUE(bubble_widget->IsClosed());
314 EXPECT_EQ(BubbleDelegateView::CloseReason::CLOSE_BUTTON,
315 bubble_delegate->close_reason());
316 }
317 }
318
264 } // namespace views 319 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_delegate.cc ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698