OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" |
7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
11 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/test/event_generator.h" |
12 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
13 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
14 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/base/ui_base_paths.h" | 18 #include "ui/base/ui_base_paths.h" |
| 19 #include "ui/base/ui_base_switches.h" |
16 #include "ui/events/event_processor.h" | 20 #include "ui/events/event_processor.h" |
17 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
18 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
| 23 #include "ui/views/controls/textfield/textfield.h" |
19 #include "ui/views/test/widget_test.h" | 24 #include "ui/views/test/widget_test.h" |
| 25 #include "ui/views/touchui/touch_selection_controller_impl.h" |
20 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
21 #include "ui/views/window/dialog_delegate.h" | 27 #include "ui/views/window/dialog_delegate.h" |
22 #include "ui/wm/public/activation_client.h" | 28 #include "ui/wm/public/activation_client.h" |
23 | 29 |
24 #if !defined(OS_CHROMEOS) | 30 #if !defined(OS_CHROMEOS) |
25 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
26 #endif | 32 #endif |
27 | 33 |
28 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
29 #include "ui/views/win/hwnd_util.h" | 35 #include "ui/views/win/hwnd_util.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 161 |
156 virtual void SetUp() OVERRIDE { | 162 virtual void SetUp() OVERRIDE { |
157 gfx::GLSurface::InitializeOneOffForTests(); | 163 gfx::GLSurface::InitializeOneOffForTests(); |
158 base::FilePath pak_dir; | 164 base::FilePath pak_dir; |
159 PathService::Get(base::DIR_MODULE, &pak_dir); | 165 PathService::Get(base::DIR_MODULE, &pak_dir); |
160 base::FilePath pak_file; | 166 base::FilePath pak_file; |
161 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | 167 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); |
162 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 168 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
163 WidgetTest::SetUp(); | 169 WidgetTest::SetUp(); |
164 } | 170 } |
| 171 |
| 172 protected: |
| 173 void ShowTouchSelectionQuickMenuImmediately(Textfield* textfield) { |
| 174 DCHECK(textfield); |
| 175 DCHECK(textfield->touch_selection_controller_); |
| 176 TouchSelectionControllerImpl* controller = |
| 177 static_cast<TouchSelectionControllerImpl*>( |
| 178 textfield->touch_selection_controller_.get()); |
| 179 if (controller->context_menu_timer_.IsRunning()) { |
| 180 controller->context_menu_timer_.Stop(); |
| 181 controller->ContextMenuTimerFired(); |
| 182 } |
| 183 } |
| 184 |
| 185 bool TouchSelectionQuickMenuIsVisible(Textfield* textfield) { |
| 186 DCHECK(textfield); |
| 187 DCHECK(textfield->touch_selection_controller_); |
| 188 TouchSelectionControllerImpl* controller = |
| 189 static_cast<TouchSelectionControllerImpl*>( |
| 190 textfield->touch_selection_controller_.get()); |
| 191 return controller->context_menu_ && controller->context_menu_->visible(); |
| 192 } |
165 }; | 193 }; |
166 | 194 |
167 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
168 // Tests whether activation and focus change works correctly in Windows. | 196 // Tests whether activation and focus change works correctly in Windows. |
169 // We test the following:- | 197 // We test the following:- |
170 // 1. If the active aura window is correctly set when a top level widget is | 198 // 1. If the active aura window is correctly set when a top level widget is |
171 // created. | 199 // created. |
172 // 2. If the active aura window in widget 1 created above, is set to NULL when | 200 // 2. If the active aura window in widget 1 created above, is set to NULL when |
173 // another top level widget is created and focused. | 201 // another top level widget is created and focused. |
174 // 3. On focusing the native platform window for widget 1, the active aura | 202 // 3. On focusing the native platform window for widget 1, the active aura |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 modal_dialog_widget->Show(); | 723 modal_dialog_widget->Show(); |
696 | 724 |
697 EXPECT_FALSE(top_level_window->HasCapture()); | 725 EXPECT_FALSE(top_level_window->HasCapture()); |
698 | 726 |
699 modal_dialog_widget->CloseNow(); | 727 modal_dialog_widget->CloseNow(); |
700 top_level_widget.CloseNow(); | 728 top_level_widget.CloseNow(); |
701 } | 729 } |
702 | 730 |
703 #endif | 731 #endif |
704 | 732 |
| 733 TEST_F(WidgetTestInteractive, CanActivateFlagIsHonored) { |
| 734 Widget widget; |
| 735 Widget::InitParams init_params = |
| 736 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 737 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 738 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 739 init_params.activatable = Widget::InitParams::ACTIVATABLE_NO; |
| 740 #if !defined(OS_CHROMEOS) |
| 741 init_params.native_widget = new DesktopNativeWidgetAura(&widget); |
| 742 #endif // !defined(OS_CHROMEOS) |
| 743 widget.Init(init_params); |
| 744 |
| 745 widget.Show(); |
| 746 EXPECT_FALSE(widget.IsActive()); |
| 747 } |
| 748 |
| 749 // Test that touch selection quick menu is not activated when opened. |
| 750 TEST_F(WidgetTestInteractive, TouchSelectionQuickMenuIsNotActivated) { |
| 751 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 752 #if defined(OS_WIN) |
| 753 views_delegate().set_use_desktop_native_widgets(true); |
| 754 #endif // !defined(OS_WIN) |
| 755 |
| 756 Widget widget; |
| 757 Widget::InitParams init_params = |
| 758 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 759 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 760 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 761 widget.Init(init_params); |
| 762 |
| 763 Textfield* textfield = new Textfield; |
| 764 textfield->SetBounds(0, 0, 200, 20); |
| 765 textfield->SetText(base::ASCIIToUTF16("some text")); |
| 766 widget.GetRootView()->AddChildView(textfield); |
| 767 |
| 768 widget.Show(); |
| 769 textfield->RequestFocus(); |
| 770 textfield->SelectAll(true); |
| 771 |
| 772 RunPendingMessages(); |
| 773 |
| 774 aura::test::EventGenerator generator(widget.GetNativeView()->GetRootWindow()); |
| 775 generator.GestureTapAt(gfx::Point(10, 10)); |
| 776 ShowTouchSelectionQuickMenuImmediately(textfield); |
| 777 |
| 778 EXPECT_TRUE(textfield->HasFocus()); |
| 779 EXPECT_TRUE(widget.IsActive()); |
| 780 EXPECT_TRUE(TouchSelectionQuickMenuIsVisible(textfield)); |
| 781 } |
| 782 |
705 namespace { | 783 namespace { |
706 | 784 |
707 // Used to veirfy OnMouseCaptureLost() has been invoked. | 785 // Used to veirfy OnMouseCaptureLost() has been invoked. |
708 class CaptureLostTrackingWidget : public Widget { | 786 class CaptureLostTrackingWidget : public Widget { |
709 public: | 787 public: |
710 CaptureLostTrackingWidget() : got_capture_lost_(false) {} | 788 CaptureLostTrackingWidget() : got_capture_lost_(false) {} |
711 virtual ~CaptureLostTrackingWidget() {} | 789 virtual ~CaptureLostTrackingWidget() {} |
712 | 790 |
713 bool GetAndClearGotCaptureLost() { | 791 bool GetAndClearGotCaptureLost() { |
714 bool value = got_capture_lost_; | 792 bool value = got_capture_lost_; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 965 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
888 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 966 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
889 ASSERT_FALSE(details.dispatcher_destroyed); | 967 ASSERT_FALSE(details.dispatcher_destroyed); |
890 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 968 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
891 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 969 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
892 } | 970 } |
893 #endif | 971 #endif |
894 | 972 |
895 } // namespace test | 973 } // namespace test |
896 } // namespace views | 974 } // namespace views |
OLD | NEW |