Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | |
| 8 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/base/ui_base_paths.h" | |
| 11 #include "ui/gl/test/gl_surface_test_support.h" | |
| 12 #include "ui/views/controls/textfield/textfield.h" | 8 #include "ui/views/controls/textfield/textfield.h" |
| 13 #include "ui/views/test/native_widget_factory.h" | 9 #include "ui/views/test/native_widget_factory.h" |
| 14 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_interactive_ui_test_base.h" |
| 15 #include "ui/views/test/widget_test.h" | 11 #include "ui/views/test/widget_test.h" |
| 16 #include "ui/views/widget/widget_delegate.h" | |
| 17 #include "ui/wm/core/base_focus_rules.h" | 12 #include "ui/wm/core/base_focus_rules.h" |
| 18 #include "ui/wm/core/focus_controller.h" | 13 #include "ui/wm/core/focus_controller.h" |
| 19 | 14 |
| 20 namespace views { | 15 namespace views { |
| 21 namespace test { | 16 namespace test { |
| 22 | 17 |
| 18 namespace { | |
| 19 | |
| 20 NativeWidget* CreateNativeWidget(const Widget::InitParams& params, | |
|
sky
2016/10/24 20:05:03
optional: nuke the function and call CreatePlatfor
| |
| 21 Widget* widget) { | |
| 22 return CreatePlatformNativeWidgetImpl(params, widget, kDefault, nullptr); | |
| 23 } | |
| 24 | |
| 23 class TestFocusRules : public wm::BaseFocusRules { | 25 class TestFocusRules : public wm::BaseFocusRules { |
| 24 public: | 26 public: |
| 25 TestFocusRules() {} | 27 TestFocusRules() {} |
| 26 ~TestFocusRules() override {} | 28 ~TestFocusRules() override {} |
| 27 | 29 |
| 28 void set_can_activate(bool can_activate) { can_activate_ = can_activate; } | 30 void set_can_activate(bool can_activate) { can_activate_ = can_activate; } |
| 29 | 31 |
| 30 // wm::BaseFocusRules overrides: | 32 // wm::BaseFocusRules overrides: |
| 31 bool SupportsChildActivation(aura::Window* window) const override { | 33 bool SupportsChildActivation(aura::Window* window) const override { |
| 32 return true; | 34 return true; |
| 33 } | 35 } |
| 34 | 36 |
| 35 bool CanActivateWindow(aura::Window* window) const override { | 37 bool CanActivateWindow(aura::Window* window) const override { |
| 36 return can_activate_; | 38 return can_activate_; |
| 37 } | 39 } |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 bool can_activate_ = true; | 42 bool can_activate_ = true; |
| 41 | 43 |
| 42 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 44 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 class NativeWidgetAuraTest : public ViewsTestBase { | 47 } // namespace |
| 46 public: | |
| 47 NativeWidgetAuraTest() {} | |
| 48 ~NativeWidgetAuraTest() override {} | |
| 49 | 48 |
| 50 void SetUp() override { | 49 typedef ViewsInteractiveUITestBase NativeWidgetAuraTest; |
|
sky
2016/10/24 20:05:02
using
| |
| 51 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
| 52 ui::RegisterPathProvider(); | |
| 53 base::FilePath ui_test_pak_path; | |
| 54 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | |
| 55 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | |
| 56 | |
| 57 ViewsTestBase::SetUp(); | |
| 58 } | |
| 59 | |
| 60 NativeWidget* CreateNativeWidget(const Widget::InitParams& params, | |
| 61 Widget* widget) { | |
| 62 return CreatePlatformNativeWidgetImpl(params, widget, kDefault, nullptr); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); | |
| 67 }; | |
| 68 | 50 |
| 69 // When requesting view focus from a non-active top level widget, focus is not | 51 // When requesting view focus from a non-active top level widget, focus is not |
| 70 // instantly given. Instead, the view is firstly stored and then it is attempted | 52 // instantly given. Instead, the view is firstly stored and then it is attempted |
| 71 // to activate the widget. If widget is currently not activatable, focus should | 53 // to activate the widget. If widget is currently not activatable, focus should |
| 72 // not be grabbed. And focus will be given/restored the next time the widget is | 54 // not be grabbed. And focus will be given/restored the next time the widget is |
| 73 // made active. (crbug.com/621791) | 55 // made active. (crbug.com/621791) |
| 74 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { | 56 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { |
| 75 TestFocusRules* test_focus_rules = new TestFocusRules; | 57 TestFocusRules* test_focus_rules = new TestFocusRules; |
| 76 std::unique_ptr<wm::FocusController> focus_controller = | 58 std::unique_ptr<wm::FocusController> focus_controller = |
| 77 base::MakeUnique<wm::FocusController>(test_focus_rules); | 59 base::MakeUnique<wm::FocusController>(test_focus_rules); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 EXPECT_TRUE(textfield2a->HasFocus()); | 103 EXPECT_TRUE(textfield2a->HasFocus()); |
| 122 EXPECT_FALSE(textfield2b->HasFocus()); | 104 EXPECT_FALSE(textfield2b->HasFocus()); |
| 123 EXPECT_FALSE(textfield1->HasFocus()); | 105 EXPECT_FALSE(textfield1->HasFocus()); |
| 124 | 106 |
| 125 widget1->CloseNow(); | 107 widget1->CloseNow(); |
| 126 widget2->CloseNow(); | 108 widget2->CloseNow(); |
| 127 } | 109 } |
| 128 | 110 |
| 129 } // namespace test | 111 } // namespace test |
| 130 } // namespace views | 112 } // namespace views |
| OLD | NEW |