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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc

Issue 1254963010: [Views] Move modality tests from widget_unittest.cc to desktop_native_widget_aura_unittest.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 4 months 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/test/widget_test.cc ('k') | ui/views/widget/widget_unittest.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/client/aura_constants.h" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/cursor_client.h" 9 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/client/window_tree_client.h" 10 #include "ui/aura/client/window_tree_client.h"
11 #include "ui/aura/test/test_window_delegate.h" 11 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host.h" 13 #include "ui/aura/window_tree_host.h"
14 #include "ui/events/event_processor.h" 14 #include "ui/events/event_processor.h"
15 #include "ui/events/event_utils.h" 15 #include "ui/events/event_utils.h"
16 #include "ui/events/test/event_generator.h" 16 #include "ui/events/test/event_generator.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 #include "ui/views/test/test_views.h" 18 #include "ui/views/test/test_views.h"
19 #include "ui/views/test/test_views_delegate.h" 19 #include "ui/views/test/test_views_delegate.h"
20 #include "ui/views/test/views_test_base.h" 20 #include "ui/views/test/views_test_base.h"
21 #include "ui/views/test/widget_test.h" 21 #include "ui/views/test/widget_test.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 #include "ui/views/window/dialog_delegate.h"
23 #include "ui/wm/public/dispatcher_client.h" 24 #include "ui/wm/public/dispatcher_client.h"
24 25
26 #if defined(OS_WIN)
27 #include "ui/views/win/hwnd_util.h"
28 #endif
29
25 namespace views { 30 namespace views {
26 namespace test { 31 namespace test {
27 32
28 typedef ViewsTestBase DesktopNativeWidgetAuraTest; 33 typedef ViewsTestBase DesktopNativeWidgetAuraTest;
29 34
30 // Verifies creating a Widget with a parent that is not in a RootWindow doesn't 35 // Verifies creating a Widget with a parent that is not in a RootWindow doesn't
31 // crash. 36 // crash.
32 TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) { 37 TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) {
33 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 38 scoped_ptr<aura::Window> window(new aura::Window(NULL));
34 window->Init(ui::LAYER_NOT_DRAWN); 39 window->Init(ui::LAYER_NOT_DRAWN);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // Verifies deleting the widget from a mouse pressed event doesn't crash. 502 // Verifies deleting the widget from a mouse pressed event doesn't crash.
498 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMousePress) { 503 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMousePress) {
499 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_PRESSED); 504 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_PRESSED);
500 } 505 }
501 506
502 // Verifies deleting the widget from a mouse released event doesn't crash. 507 // Verifies deleting the widget from a mouse released event doesn't crash.
503 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMouseReleased) { 508 TEST_F(DesktopAuraWidgetTest, CloseWidgetDuringMouseReleased) {
504 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_RELEASED); 509 RunCloseWidgetDuringDispatchTest(this, ui::ET_MOUSE_RELEASED);
505 } 510 }
506 511
512 // Provides functionality to create a window modal dialog.
513 class ModalDialogDelegate : public DialogDelegateView {
514 public:
515 ModalDialogDelegate() {}
516 ~ModalDialogDelegate() override {}
517
518 // WidgetDelegate overrides.
519 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; }
520
521 private:
522 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate);
523 };
524
525 // This test verifies that whether mouse events when a modal dialog is
526 // displayed are eaten or recieved by the dialog.
527 TEST_F(WidgetTest, WindowMouseModalityTest) {
528 // Create a top level widget.
529 Widget top_level_widget;
530 Widget::InitParams init_params =
531 CreateParams(Widget::InitParams::TYPE_WINDOW);
532 init_params.show_state = ui::SHOW_STATE_NORMAL;
533 gfx::Rect initial_bounds(0, 0, 500, 500);
534 init_params.bounds = initial_bounds;
535 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
536 init_params.native_widget =
537 new PlatformDesktopNativeWidget(&top_level_widget);
538 top_level_widget.Init(init_params);
539 top_level_widget.Show();
540 EXPECT_TRUE(top_level_widget.IsVisible());
541
542 // Create a view and validate that a mouse moves makes it to the view.
543 EventCountView* widget_view = new EventCountView();
544 widget_view->SetBounds(0, 0, 10, 10);
545 top_level_widget.GetRootView()->AddChildView(widget_view);
546
547 gfx::Point cursor_location_main(5, 5);
548 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main,
549 cursor_location_main, ui::EventTimeForNow(),
550 ui::EF_NONE, ui::EF_NONE);
551 ui::EventDispatchDetails details =
552 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main);
553 ASSERT_FALSE(details.dispatcher_destroyed);
554
555 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
556 widget_view->ResetCounts();
557
558 // Create a modal dialog and validate that a mouse down message makes it to
559 // the main view within the dialog.
560
561 // This instance will be destroyed when the dialog is destroyed.
562 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
563
564 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
565 dialog_delegate, NULL, top_level_widget.GetNativeView());
566 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
567 EventCountView* dialog_widget_view = new EventCountView();
568 dialog_widget_view->SetBounds(0, 0, 50, 50);
569 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view);
570 modal_dialog_widget->Show();
571 EXPECT_TRUE(modal_dialog_widget->IsVisible());
572
573 gfx::Point cursor_location_dialog(100, 100);
574 ui::MouseEvent mouse_down_dialog(
575 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog,
576 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
577 details = GetEventProcessor(&top_level_widget)->OnEventFromSource(
578 &mouse_down_dialog);
579 ASSERT_FALSE(details.dispatcher_destroyed);
580 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
581
582 // Send a mouse move message to the main window. It should not be received by
583 // the main window as the modal dialog is still active.
584 gfx::Point cursor_location_main2(6, 6);
585 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2,
586 cursor_location_main2, ui::EventTimeForNow(),
587 ui::EF_NONE, ui::EF_NONE);
588 details = GetEventProcessor(&top_level_widget)->OnEventFromSource(
589 &mouse_down_main);
590 ASSERT_FALSE(details.dispatcher_destroyed);
591 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
592
593 modal_dialog_widget->CloseNow();
594 top_level_widget.CloseNow();
595 }
596
597 #if defined(OS_WIN)
598 // Tests whether we can activate the top level widget when a modal dialog is
599 // active.
600 TEST_F(WidgetTest, WindowModalityActivationTest) {
601 TestDesktopWidgetDelegate widget_delegate;
602 widget_delegate.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW));
603
604 Widget* top_level_widget = widget_delegate.GetWidget();
605 top_level_widget->Show();
606 EXPECT_TRUE(top_level_widget->IsVisible());
607
608 HWND win32_window = views::HWNDForWidget(top_level_widget);
609 EXPECT_TRUE(::IsWindow(win32_window));
610
611 // This instance will be destroyed when the dialog is destroyed.
612 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
613
614 // We should be able to activate the window even if the WidgetDelegate
615 // says no, when a modal dialog is active.
616 widget_delegate.set_can_activate(false);
617
618 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
619 dialog_delegate, NULL, top_level_widget->GetNativeView());
620 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
621 modal_dialog_widget->Show();
622 EXPECT_TRUE(modal_dialog_widget->IsVisible());
623
624 LRESULT activate_result = ::SendMessage(
625 win32_window,
626 WM_MOUSEACTIVATE,
627 reinterpret_cast<WPARAM>(win32_window),
628 MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT));
629 EXPECT_EQ(activate_result, MA_ACTIVATE);
630
631 modal_dialog_widget->CloseNow();
632 }
633 #endif // defined(OS_WIN)
634
507 } // namespace test 635 } // namespace test
508 } // namespace views 636 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/widget_test.cc ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698