Index: ui/views/widget/widget_interactive_uitest.cc |
diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc |
index 230a720714384882c112f554ef67121b07f8f3a2..ffb1f63df7431cd1e01a762da9d5219df4e7cb95 100644 |
--- a/ui/views/widget/widget_interactive_uitest.cc |
+++ b/ui/views/widget/widget_interactive_uitest.cc |
@@ -36,8 +36,13 @@ |
#include "ui/views/window/dialog_delegate.h" |
#include "ui/wm/public/activation_client.h" |
-#if defined(OS_WIN) |
+#if defined(USE_AURA) |
#include "ui/aura/window.h" |
+#include "ui/wm/core/base_focus_rules.h" |
+#include "ui/wm/core/focus_controller.h" |
+#endif |
+ |
+#if defined(OS_WIN) |
#include "ui/aura/window_tree_host.h" |
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
#include "ui/views/win/hwnd_util.h" |
@@ -1821,5 +1826,78 @@ TEST_F(WidgetInputMethodInteractiveTest, AcceleratorInTextfield) { |
widget->CloseNow(); |
} |
+#if defined(USE_AURA) |
+class TestFocusRules : public wm::BaseFocusRules { |
+ public: |
+ TestFocusRules() {} |
+ ~TestFocusRules() override {} |
+ |
+ void set_can_activate(bool can_activate) { can_activate_ = can_activate; } |
+ |
+ // wm::BaseFocusRules overrides: |
+ bool SupportsChildActivation(aura::Window* window) const override { |
+ return true; |
+ } |
+ |
+ bool CanActivateWindow(aura::Window* window) const override { |
+ return can_activate_; |
+ } |
+ |
+ private: |
+ bool can_activate_ = true; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
+}; |
+ |
+// (crbug.com/621791) |
+#if defined(OS_WIN) |
+// TODO(warx): Figure out the reason for the test failing on OS_WIN. |
+#define MAYBE_NonActiveWindowRequestImeFocus \ |
+ DISABLED_NonActiveWindowRequestImeFocus |
+#else |
+#define MAYBE_NonActiveWindowRequestImeFocus NonActiveWindowRequestImeFocus |
+#endif |
+TEST_F(WidgetInputMethodInteractiveTest, MAYBE_NonActiveWindowRequestImeFocus) { |
sky
2016/10/19 16:23:32
How come you're grouping this in WidgetInputMethod
Qiang(Joe) Xu
2016/10/20 23:51:51
done
|
+ TestFocusRules* test_focus_rules = new TestFocusRules; |
+ std::unique_ptr<wm::FocusController> focus_controller = |
+ base::MakeUnique<wm::FocusController>(test_focus_rules); |
+ aura::client::SetActivationClient(GetContext(), focus_controller.get()); |
+ |
+ Widget* widget1 = CreateWidget(); |
+ Textfield* textfield1a = new Textfield; |
+ widget1->GetRootView()->AddChildView(textfield1a); |
+ Textfield* textfield1b = new Textfield; |
+ widget1->GetRootView()->AddChildView(textfield1b); |
+ |
+ Widget* widget2 = CreateWidget(); |
+ Textfield* textfield2 = new Textfield; |
+ widget2->GetRootView()->AddChildView(textfield2); |
+ |
+ ShowSync(widget2); |
+ textfield2->RequestFocus(); |
+ EXPECT_TRUE(textfield2->HasFocus()); |
+ EXPECT_FALSE(textfield1a->HasFocus()); |
+ EXPECT_FALSE(textfield1b->HasFocus()); |
+ |
+ // Don't allow window activation at this step. |
+ test_focus_rules->set_can_activate(false); |
+ textfield1a->RequestFocus(); |
+ EXPECT_TRUE(textfield2->HasFocus()); |
+ EXPECT_FALSE(textfield1a->HasFocus()); |
+ EXPECT_FALSE(textfield1b->HasFocus()); |
+ |
+ // Allow window activation and |widget1| gets activated at this step, focus |
+ // should be properly restored. |
+ test_focus_rules->set_can_activate(true); |
+ ShowSync(widget1); |
+ EXPECT_TRUE(textfield1a->HasFocus()); |
+ EXPECT_FALSE(textfield1b->HasFocus()); |
+ EXPECT_FALSE(textfield2->HasFocus()); |
+ |
+ widget1->Close(); |
+ widget2->Close(); |
+} |
+#endif |
+ |
} // namespace test |
} // namespace views |