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

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

Issue 1456213002: Revert of [Extensions] Don't count bubble dismissal from focus loss as acknowledgment (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 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"
7 #include "ui/views/bubble/bubble_delegate.h" 6 #include "ui/views/bubble/bubble_delegate.h"
8 #include "ui/views/bubble/bubble_frame_view.h" 7 #include "ui/views/bubble/bubble_frame_view.h"
9 #include "ui/views/controls/button/label_button.h"
10 #include "ui/views/test/test_widget_observer.h" 8 #include "ui/views/test/test_widget_observer.h"
11 #include "ui/views/test/views_test_base.h" 9 #include "ui/views/test/views_test_base.h"
12 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_observer.h" 11 #include "ui/views/widget/widget_observer.h"
14 12
15 namespace views { 13 namespace views {
16 14
17 namespace { 15 namespace {
18 16
19 class TestBubbleDelegateView : public BubbleDelegateView { 17 class TestBubbleDelegateView : public BubbleDelegateView {
(...skipping 11 matching lines...) Expand all
31 } 29 }
32 30
33 void SetAnchorViewForTest(View* view) { 31 void SetAnchorViewForTest(View* view) {
34 SetAnchorView(view); 32 SetAnchorView(view);
35 } 33 }
36 34
37 // BubbleDelegateView overrides: 35 // BubbleDelegateView overrides:
38 View* GetInitiallyFocusedView() override { return view_; } 36 View* GetInitiallyFocusedView() override { return view_; }
39 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } 37 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
40 38
41 BubbleFrameView* GetBubbleFrameViewForTest() const {
42 return GetBubbleFrameView();
43 }
44
45 private: 39 private:
46 View* view_; 40 View* view_;
47 41
48 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); 42 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView);
49 }; 43 };
50 44
51 class BubbleDelegateTest : public ViewsTestBase { 45 class BubbleDelegateTest : public ViewsTestBase {
52 public: 46 public:
53 BubbleDelegateTest() {} 47 BubbleDelegateTest() {}
54 ~BubbleDelegateTest() override {} 48 ~BubbleDelegateTest() override {}
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 TEST_F(BubbleDelegateTest, NotActivatable) { 254 TEST_F(BubbleDelegateTest, NotActivatable) {
261 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); 255 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
262 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( 256 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
263 anchor_widget->GetContentsView(), BubbleBorder::NONE); 257 anchor_widget->GetContentsView(), BubbleBorder::NONE);
264 bubble_delegate->set_can_activate(false); 258 bubble_delegate->set_can_activate(false);
265 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 259 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
266 bubble_widget->Show(); 260 bubble_widget->Show();
267 EXPECT_FALSE(bubble_widget->CanActivate()); 261 EXPECT_FALSE(bubble_widget->CanActivate());
268 } 262 }
269 263
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
319 } // namespace views 264 } // 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