| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/views_test_helper_mac.h" | 5 #include "ui/views/test/views_test_helper_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/scoped_nsautorelease_pool.h" | 9 #import "base/mac/scoped_nsautorelease_pool.h" |
| 10 #include "ui/base/test/scoped_fake_nswindow_focus.h" |
| 11 #include "ui/base/test/ui_controls.h" |
| 10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 11 #include "ui/views/test/event_generator_delegate_mac.h" | 13 #include "ui/views/test/event_generator_delegate_mac.h" |
| 12 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 13 | 15 |
| 14 namespace views { | 16 namespace views { |
| 15 | 17 |
| 16 // static | 18 // static |
| 17 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop, | 19 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop, |
| 18 ui::ContextFactory* context_factory) { | 20 ui::ContextFactory* context_factory) { |
| 19 return new ViewsTestHelperMac; | 21 return new ViewsTestHelperMac; |
| 20 } | 22 } |
| 21 | 23 |
| 22 ViewsTestHelperMac::ViewsTestHelperMac() | 24 ViewsTestHelperMac::ViewsTestHelperMac() |
| 23 : zero_duration_mode_(new ui::ScopedAnimationDurationScaleMode( | 25 : zero_duration_mode_(new ui::ScopedAnimationDurationScaleMode( |
| 24 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)) { | 26 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)) { |
| 25 test::InitializeMacEventGeneratorDelegate(); | 27 test::InitializeMacEventGeneratorDelegate(); |
| 26 | 28 |
| 27 // Unbundled applications (those without Info.plist) default to | 29 // Unbundled applications (those without Info.plist) default to |
| 28 // NSApplicationActivationPolicyProhibited, which prohibits the application | 30 // NSApplicationActivationPolicyProhibited, which prohibits the application |
| 29 // obtaining key status or activating windows without user interaction. | 31 // obtaining key status or activating windows without user interaction. |
| 30 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; | 32 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; |
| 31 } | 33 } |
| 32 | 34 |
| 33 ViewsTestHelperMac::~ViewsTestHelperMac() { | 35 ViewsTestHelperMac::~ViewsTestHelperMac() { |
| 34 } | 36 } |
| 35 | 37 |
| 38 void ViewsTestHelperMac::SetUp() { |
| 39 ViewsTestHelper::SetUp(); |
| 40 // Assume that if the methods in the ui_controls.h test header are enabled |
| 41 // then the test runner is in a non-sharded mode, and will use "real" |
| 42 // activations. This allows interactive_ui_tests to test the actual OS window |
| 43 // activation codepaths. |
| 44 if (!ui_controls::IsUIControlsEnabled()) |
| 45 faked_focus_.reset(new ui::test::ScopedFakeNSWindowFocus); |
| 46 } |
| 47 |
| 36 void ViewsTestHelperMac::TearDown() { | 48 void ViewsTestHelperMac::TearDown() { |
| 37 // Ensure all Widgets are closed explicitly in tests. The Widget may be | 49 // Ensure all Widgets are closed explicitly in tests. The Widget may be |
| 38 // hosting a Compositor. If that's torn down after the test ContextFactory | 50 // hosting a Compositor. If that's torn down after the test ContextFactory |
| 39 // then a lot of confusing use-after-free errors result. In browser tests, | 51 // then a lot of confusing use-after-free errors result. In browser tests, |
| 40 // this is handled automatically by views::Widget::CloseAllSecondaryWidgets(). | 52 // this is handled automatically by views::Widget::CloseAllSecondaryWidgets(). |
| 41 // Unit tests on Aura may create Widgets owned by a RootWindow that gets torn | 53 // Unit tests on Aura may create Widgets owned by a RootWindow that gets torn |
| 42 // down, but on Mac we need to be more explicit. | 54 // down, but on Mac we need to be more explicit. |
| 43 base::mac::ScopedNSAutoreleasePool pool; // Ensure the NSArray is released. | 55 base::mac::ScopedNSAutoreleasePool pool; // Ensure the NSArray is released. |
| 44 NSArray* native_windows = [NSApp windows]; | 56 NSArray* native_windows = [NSApp windows]; |
| 45 for (NSWindow* window : native_windows) | 57 for (NSWindow* window : native_windows) |
| 46 DCHECK(!Widget::GetWidgetForNativeWindow(window)) << "Widget not closed."; | 58 DCHECK(!Widget::GetWidgetForNativeWindow(window)) << "Widget not closed."; |
| 47 } | 59 } |
| 48 | 60 |
| 49 } // namespace views | 61 } // namespace views |
| OLD | NEW |