| 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 "chrome/test/base/interactive_test_utils.h" | 5 #include "chrome/test/base/interactive_test_utils.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/base/cocoa/cocoa_base_utils.h" | 17 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 17 | 18 |
| 18 namespace ui_test_utils { | 19 namespace ui_test_utils { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 void MoveMouseToNSViewCenterAndPress( | 23 void MoveMouseToNSViewCenterAndPress( |
| 23 NSView* view, | 24 NSView* view, |
| 24 ui_controls::MouseButton button, | 25 ui_controls::MouseButton button, |
| 25 int state, | 26 int state, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (delegate == view) | 69 if (delegate == view) |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 return false; | 73 return false; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void ClickOnView(const Browser* browser, ViewID vid) { | 76 void ClickOnView(const Browser* browser, ViewID vid) { |
| 76 NSWindow* window = browser->window()->GetNativeWindow(); | 77 NSWindow* window = browser->window()->GetNativeWindow(); |
| 77 DCHECK(window); | 78 DCHECK(window); |
| 79 // Fail tests that use ClickOnView() on an inactive window. Tests that do will |
| 80 // flake too easily. There seems to be no guarantee that the WindowServer will |
| 81 // send the event to the window, or activate it. It isn't enough just to wait |
| 82 // for NSWindowDidBecomeKeyNotification after this method. |
| 83 EXPECT_TRUE([window isKeyWindow]) |
| 84 << "ClickOnView() in an inactive window is not robust."; |
| 78 NSView* view = view_id_util::GetView(window, vid); | 85 NSView* view = view_id_util::GetView(window, vid); |
| 79 DCHECK(view); | 86 DCHECK(view); |
| 80 MoveMouseToNSViewCenterAndPress( | 87 MoveMouseToNSViewCenterAndPress( |
| 81 view, | 88 view, |
| 82 ui_controls::LEFT, | 89 ui_controls::LEFT, |
| 83 ui_controls::DOWN | ui_controls::UP, | 90 ui_controls::DOWN | ui_controls::UP, |
| 84 base::MessageLoop::QuitWhenIdleClosure()); | 91 base::MessageLoop::QuitWhenIdleClosure()); |
| 85 content::RunMessageLoop(); | 92 content::RunMessageLoop(); |
| 86 } | 93 } |
| 87 | 94 |
| 88 void FocusView(const Browser* browser, ViewID vid) { | 95 void FocusView(const Browser* browser, ViewID vid) { |
| 89 NSWindow* window = browser->window()->GetNativeWindow(); | 96 NSWindow* window = browser->window()->GetNativeWindow(); |
| 90 DCHECK(window); | 97 DCHECK(window); |
| 91 NSView* view = view_id_util::GetView(window, vid); | 98 NSView* view = view_id_util::GetView(window, vid); |
| 92 DCHECK(view); | 99 DCHECK(view); |
| 93 [window makeFirstResponder:view]; | 100 [window makeFirstResponder:view]; |
| 94 } | 101 } |
| 95 | 102 |
| 96 } // namespace ui_test_utils | 103 } // namespace ui_test_utils |
| OLD | NEW |