| 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/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/ui_base_paths.h" | 18 #include "ui/base/ui_base_paths.h" |
| 19 #include "ui/base/ui_base_switches.h" | 19 #include "ui/base/ui_base_switches.h" |
| 20 #include "ui/events/event_processor.h" | 20 #include "ui/events/event_processor.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
| 22 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
| 23 #include "ui/views/controls/textfield/textfield.h" | 23 #include "ui/views/controls/textfield/textfield.h" |
| 24 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 24 #include "ui/views/test/widget_test.h" | 25 #include "ui/views/test/widget_test.h" |
| 25 #include "ui/views/touchui/touch_selection_controller_impl.h" | 26 #include "ui/views/touchui/touch_selection_controller_impl.h" |
| 26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/window/dialog_delegate.h" | 28 #include "ui/views/window/dialog_delegate.h" |
| 28 #include "ui/wm/public/activation_client.h" | 29 #include "ui/wm/public/activation_client.h" |
| 29 | 30 |
| 30 #if !defined(OS_CHROMEOS) | 31 #if !defined(OS_CHROMEOS) |
| 31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 gfx::GLSurface::InitializeOneOffForTests(); | 164 gfx::GLSurface::InitializeOneOffForTests(); |
| 164 base::FilePath pak_dir; | 165 base::FilePath pak_dir; |
| 165 PathService::Get(base::DIR_MODULE, &pak_dir); | 166 PathService::Get(base::DIR_MODULE, &pak_dir); |
| 166 base::FilePath pak_file; | 167 base::FilePath pak_file; |
| 167 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | 168 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); |
| 168 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 169 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
| 169 WidgetTest::SetUp(); | 170 WidgetTest::SetUp(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 protected: | 173 protected: |
| 173 void ShowTouchSelectionQuickMenuImmediately(Textfield* textfield) { | 174 static void ShowQuickMenuImmediately( |
| 174 DCHECK(textfield); | 175 TouchSelectionControllerImpl* controller) { |
| 175 DCHECK(textfield->touch_selection_controller_); | 176 DCHECK(controller); |
| 176 TouchSelectionControllerImpl* controller = | |
| 177 static_cast<TouchSelectionControllerImpl*>( | |
| 178 textfield->touch_selection_controller_.get()); | |
| 179 if (controller->context_menu_timer_.IsRunning()) { | 177 if (controller->context_menu_timer_.IsRunning()) { |
| 180 controller->context_menu_timer_.Stop(); | 178 controller->context_menu_timer_.Stop(); |
| 181 controller->ContextMenuTimerFired(); | 179 controller->ContextMenuTimerFired(); |
| 182 } | 180 } |
| 183 } | 181 } |
| 184 | 182 |
| 185 bool TouchSelectionQuickMenuIsVisible(Textfield* textfield) { | 183 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { |
| 186 DCHECK(textfield); | 184 DCHECK(controller); |
| 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(); | 185 return controller->context_menu_ && controller->context_menu_->visible(); |
| 192 } | 186 } |
| 193 }; | 187 }; |
| 194 | 188 |
| 195 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
| 196 // Tests whether activation and focus change works correctly in Windows. | 190 // Tests whether activation and focus change works correctly in Windows. |
| 197 // We test the following:- | 191 // We test the following:- |
| 198 // 1. If the active aura window is correctly set when a top level widget is | 192 // 1. If the active aura window is correctly set when a top level widget is |
| 199 // created. | 193 // created. |
| 200 // 2. If the active aura window in widget 1 created above, is set to NULL when | 194 // 2. If the active aura window in widget 1 created above, is set to NULL when |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 widget.Init(init_params); | 755 widget.Init(init_params); |
| 762 | 756 |
| 763 Textfield* textfield = new Textfield; | 757 Textfield* textfield = new Textfield; |
| 764 textfield->SetBounds(0, 0, 200, 20); | 758 textfield->SetBounds(0, 0, 200, 20); |
| 765 textfield->SetText(base::ASCIIToUTF16("some text")); | 759 textfield->SetText(base::ASCIIToUTF16("some text")); |
| 766 widget.GetRootView()->AddChildView(textfield); | 760 widget.GetRootView()->AddChildView(textfield); |
| 767 | 761 |
| 768 widget.Show(); | 762 widget.Show(); |
| 769 textfield->RequestFocus(); | 763 textfield->RequestFocus(); |
| 770 textfield->SelectAll(true); | 764 textfield->SelectAll(true); |
| 765 TextfieldTestApi textfield_test_api(textfield); |
| 771 | 766 |
| 772 RunPendingMessages(); | 767 RunPendingMessages(); |
| 773 | 768 |
| 774 aura::test::EventGenerator generator(widget.GetNativeView()->GetRootWindow()); | 769 aura::test::EventGenerator generator(widget.GetNativeView()->GetRootWindow()); |
| 775 generator.GestureTapAt(gfx::Point(10, 10)); | 770 generator.GestureTapAt(gfx::Point(10, 10)); |
| 776 ShowTouchSelectionQuickMenuImmediately(textfield); | 771 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( |
| 772 textfield_test_api.touch_selection_controller())); |
| 777 | 773 |
| 778 EXPECT_TRUE(textfield->HasFocus()); | 774 EXPECT_TRUE(textfield->HasFocus()); |
| 779 EXPECT_TRUE(widget.IsActive()); | 775 EXPECT_TRUE(widget.IsActive()); |
| 780 EXPECT_TRUE(TouchSelectionQuickMenuIsVisible(textfield)); | 776 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( |
| 777 textfield_test_api.touch_selection_controller()))); |
| 781 } | 778 } |
| 782 | 779 |
| 783 namespace { | 780 namespace { |
| 784 | 781 |
| 785 // Used to veirfy OnMouseCaptureLost() has been invoked. | 782 // Used to veirfy OnMouseCaptureLost() has been invoked. |
| 786 class CaptureLostTrackingWidget : public Widget { | 783 class CaptureLostTrackingWidget : public Widget { |
| 787 public: | 784 public: |
| 788 CaptureLostTrackingWidget() : got_capture_lost_(false) {} | 785 CaptureLostTrackingWidget() : got_capture_lost_(false) {} |
| 789 virtual ~CaptureLostTrackingWidget() {} | 786 virtual ~CaptureLostTrackingWidget() {} |
| 790 | 787 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 962 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 966 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 963 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 967 ASSERT_FALSE(details.dispatcher_destroyed); | 964 ASSERT_FALSE(details.dispatcher_destroyed); |
| 968 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 965 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 969 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 966 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 970 } | 967 } |
| 971 #endif | 968 #endif |
| 972 | 969 |
| 973 } // namespace test | 970 } // namespace test |
| 974 } // namespace views | 971 } // namespace views |
| OLD | NEW |